Connect Pydantic AI to Anoman AI
Pydantic AI routes through Anoman by giving its OpenAI provider a custom base URL — typed agents, guardrails included.
Prerequisites
- An Anoman API key — create one in the dashboard (format anm-sk-…).
- Pydantic AI installed and up to date.
- A model ID from the Anoman catalog, e.g. gpt-4o, gpt-4o-mini, or claude-sonnet-4-6.
Enable streaming for long agent runs
Set stream: true on requests. Autonomous, multi-step, and long-thinking tasks can exceed the 100-second edge timeout and fail with a 524 error; streaming returns tokens as they are generated and keeps the connection alive, so the request completes. Most tools stream by default — confirm it is on for agentic use.
More detail in the streaming guide.
Point the model at Anoman
Build an OpenAIChatModel with an OpenAIProvider that carries Anoman's base URL and key.
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
model = OpenAIChatModel(
"gpt-4o",
provider=OpenAIProvider(
base_url="https://api.anoman.io/v1",
api_key="anm-sk-your-key-here",
),
)
agent = Agent(model)
print(agent.run_sync("What is prompt injection?").output)Prefer Anthropic?
Pass a custom AsyncAnthropic client (pointed at Anoman) to AnthropicProvider.
from anthropic import AsyncAnthropic
from pydantic_ai.models.anthropic import AnthropicModel
from pydantic_ai.providers.anthropic import AnthropicProvider
client = AsyncAnthropic(
base_url="https://api.anoman.io/anthropic",
api_key="anm-sk-your-key-here",
)
model = AnthropicModel("claude-sonnet-4-6", provider=AnthropicProvider(anthropic_client=client))Verify the guardrails are active
Every Anoman response carries guardrail result headers. Inspect them in your dashboard traces to confirm the pipeline is running on Pydantic AI requests — prompt-injection detection, PII masking, and content moderation all apply automatically.
X-Anoman-Guardrail-Injection: pass score=0.03
X-Anoman-Guardrail-Pii: pass
X-Anoman-Guardrail-Content: pass
X-Anoman-Cache: noneNeed help with your integration?
Join the Founding 50 for early access and direct support from the Anoman team.
Join Founding 50