Pydantic AI and Bifrost: what each layer does
When I call large language models from code, I rely on two tools, Pydantic AI and Bifrost. Pydantic AI runs the agent inside the application: it calls the tools, sends validation errors back to the model and keeps the signed reasoning in the history. Bifrost is one service in front of the providers that holds the keys, budgets, routing and cost log for every application. If you use both to power your agents, two settings in the application decide whether the model keeps its reasoning between tool calls and runs at the effort you asked for: Pydantic AI’s native model class and a profile for the real model.
In my tests with Pydantic AI v2.75.0 and Claude Opus 5.5 through Bifrost v2.6.0, an agent with only an effort setting lost its reasoning between tool calls, because of a Bifrost bug that v2.7.0 fixed on 27 November. An agent set to high effort ran at low effort because of its model name, and still does on v2.7.0. Neither raised an error.
This post explains what each layer does with an LLM call and how the model class and name decide what Bifrost and the model receive. It builds on the previous post, which showed that a call now contains signed reasoning and hosted tools that only each provider’s native API supports.
What each layer does #
Pydantic AI and Bifrost overlap in more places than it first seems, but they run at different points of the call and see different things:
What each layer does
Pydantic AI runs inside the application, Bifrost as a separate service in front of the providers.
anthropic/claude-opus-5-5 matches no profile.temperature on Opus 5.5, with a warning only in Bifrost's own log.Without Pydantic AI, the application runs the tool loop and validation itself. Without Bifrost, each service holds its own provider keys and limits.
The middle band is where the two layers can disagree without an error. Both adapt the request to the model, Pydantic AI by the model name and Bifrost by its own configuration, and both retry and fall back.
Pydantic AI is a library in the application. It builds each request in the format of the chosen model class and picks a profile by the model name in the code. The profile decides, for example, whether Opus 5.5 gets adaptive thinking and which version of the web search tool it receives. When the gateway picks the model instead, the name in the code doesn’t say which model will answer. Pydantic AI then uses its defaults, and only the gateway adapts the request to the model.
Bifrost is a separate service between any number of applications and the providers. It hands out virtual keys with budgets and rate limits and routes requests across keys, regions and deployments. On every route except passthrough, it parses each request into its own schema and writes a new one for the provider. My Bifrost introduction covers the gateway side in more detail.
Model class and name #
Pydantic AI connects to Bifrost through the /pydanticai route, which
accepts each provider SDK’s own format. Two arguments in the code decide what
the model receives:
- The model class sets the format Bifrost receives, such as Messages
from
AnthropicModelor Chat Completions fromOpenAIChatModel. When it’s the provider’s own format, Bifrost forwards the thinking block as it is. Otherwise, Bifrost converts the request, and the conversion decides what is kept. - The model name picks the provider. A prefix such as
anthropic/orbedrock/picks it in the code, and without a prefix, Bifrost’s configuration picks it. Pydantic AI uses the same name to pick its profile, so a gateway name such asanthropic/claude-opus-5-5also changes what the model receives, unless you pass the profile yourself.
I ran one agent with four ways to create the model. It asks for high effort,
and with AnthropicModel it also sets a temperature, which Opus 5.5
doesn’t accept. Each tab highlights what changes:
provider = AnthropicProvider(
base_url="http://localhost:8080/pydanticai",
api_key=VIRTUAL_KEY, # Bifrost virtual key
)
model = AnthropicModel(
"claude-opus-5-5",
provider=provider,
)
agent = Agent(
model,
tools=[get_weather],
model_settings={
"thinking": "high",
"temperature": 0.2,
},
)
agent.run_sync("What's the weather in Berlin, and any news?")provider = OpenAIProvider(
base_url="http://localhost:8080/pydanticai/v1",
api_key=VIRTUAL_KEY, # Bifrost virtual key
)
model = OpenAIChatModel(
"claude-opus-5-5",
provider=provider,
)
agent = Agent(
model,
tools=[get_weather],
model_settings={
"thinking": "high",
"openai_reasoning_effort": "high",
},
)
agent.run_sync("What's the weather in Berlin, and any news?")provider = AnthropicProvider(
base_url="http://localhost:8080/pydanticai",
api_key=VIRTUAL_KEY, # Bifrost virtual key
)
model = AnthropicModel(
"anthropic/claude-opus-5-5",
provider=provider,
)
agent = Agent(
model,
tools=[get_weather],
model_settings={
"thinking": "high",
"temperature": 0.2,
},
)
agent.run_sync("What's the weather in Berlin, and any news?")provider = AnthropicProvider(
base_url="http://localhost:8080/pydanticai",
api_key=VIRTUAL_KEY, # Bifrost virtual key
)
model = AnthropicModel(
"anthropic/claude-opus-5-5",
provider=provider,
profile=provider.model_profile("claude-opus-5-5"),
)
agent = Agent(
model,
tools=[get_weather],
model_settings={
"thinking": "high",
"temperature": 0.2,
},
)
agent.run_sync("What's the weather in Berlin, and any news?")The chart shows what the model received in each case:
One agent, four ways to create the model
AnthropicModel("claude-opus-5-5", provider=provider) OpenAIChatModel("claude-opus-5-5", provider=provider) reasoning_details field, which OpenAIChatModel doesn't send back.AnthropicModel("anthropic/claude-opus-5-5", provider=provider) temperature 0.2Pydantic AI's defaults for older Claude models. Anthropic's API rejects a thinking budget on Opus 5.5.temperature, with a warning only in its own log.AnthropicModel("anthropic/claude-opus-5-5", provider=provider, profile=provider.model_profile("claude-opus-5-5")) profile=adaptive thinking, effort highPydantic AI v2.75.0 and Bifrost v2.6.0 at Anthropic's API, thinking: "high", three runs per row. Input tokens of the request with the tool result, 455 in every run without reasoning. Each row had the same outcome on Bifrost v2.7.0.
A · Native class #
With AnthropicModel and the model’s own name, claude-opus-5-5, Pydantic AI
uses the Opus 5.5 profile. It sends adaptive thinking with high effort and
removes the temperature, with a warning. Bifrost receives Anthropic’s own
format and forwards the thinking block unchanged.
Since Bifrost accepts the model’s own name, that’s the simplest setup, but the provider then depends on Bifrost’s configuration. Bifrost resolves a name without a provider prefix through its routing rules, the virtual key’s provider weights or its model catalog, so several providers and regions don’t need different names in the code. In my setup, Anthropic is the only configured provider, and Bifrost’s log names the model catalog as what picked it. A change in that configuration can move the model to a host with other features, such as Claude on Amazon Bedrock, which comes without the hosted web search tool.
A gateway that rewrites requests can drop what it doesn’t expect. Bifrost
v2.6.0 and earlier delete thinking blocks with empty text, and Claude 5 models
return the thinking text empty by default, because the reasoning is in the
signature. With only an effort setting, the model reasoned, but in three runs
the request with the tool result had 455 input tokens, as without reasoning. I
reported this on issue #7064,
and the fix was released in
v2.7.0 on 27 November. In three runs on v2.7.0, the same request had 482 to
493 input tokens, so the block was kept. On older versions, set thinking
explicitly, such as model_settings={"thinking": "high"}. Bifrost then
asks Anthropic for summarized thinking, so the block has text and is kept, with
the full reasoning still in the signature. The passthrough route
/anthropic_passthrough keeps the block as well, but skips Bifrost’s
fallbacks, routing rules and retries on HTTP errors.
B · Chat Completions class #
With OpenAIChatModel, thinking alone sends no effort, so tab B also sets
openai_reasoning_effort. Bifrost converts the request to Anthropic’s format
and returns the signature only in its own reasoning_details field, which the
class doesn’t send back. The next request has no thinking block, and there’s
no error. The
previous post explains
why Chat Completions has no standard field for it.
C · Gateway name #
With the gateway name anthropic/claude-opus-5-5, Pydantic AI doesn’t
recognize Opus 5.5 and uses its defaults for older Claude models: a thinking
budget of 16,384 tokens, the temperature and an older version of the web search
tool. Sent directly, Anthropic’s API rejects the budget with a 400. Bifrost
instead converted it to adaptive thinking at effort low and removed the
temperature, with a warning only in its own log. The request succeeded, but
the agent that asked for high effort ran at low effort, and in three runs the
model didn’t reason at all. From v2.76.0, Pydantic AI removes the temperature
itself, with a warning, but still sends the same thinking budget, so Bifrost
gets the same input for its conversion.
D · Gateway name + profile #
This is the setup I’d use. A gateway name with a provider prefix fixes the
provider in the code, so a change in Bifrost’s configuration can’t move the
model to a host with other features. A gateway name is also needed when the
gateway uses aliases or deployment names instead of the model’s ID. Then the
profile argument in tab D keeps the model’s settings correct: the provider
builds the profile for the real model.
With the profile set, Pydantic AI sent adaptive thinking with high effort, as with the model’s own name. In one of three runs, the model didn’t reason, although Bifrost sent effort high every time.
The same applies to a placeholder name when a routing rule in the gateway picks the model, for example from a header. In my test, Pydantic AI again sent the defaults for older Claude models, including an output limit of 20,480 tokens instead of 128,000. This time Bifrost converted the thinking budget to effort high, because it compares the budget with the output limit it assumes for the name, and an unknown name gets a lower one. The effort matched the agent’s setting only by coincidence. A profile fixes this as well, as long as it fits every model the rule can pick.
Who owns retries and fallbacks #
Retries: Pydantic AI sends validation errors for tool calls and output
back to the model, which only the application can do. Below that, two layers
can retry a failed request. The provider SDK retries twice by default, in both
the Anthropic and the OpenAI client. Bifrost can retry with backoff, but
doesn’t by default. When both retry, the retries multiply. With Bifrost set to
three retries, each of the SDK’s three attempts becomes up to four at the
provider, so one failing request can be sent twelve times. If you let Bifrost
retry, set max_retries to 0 in Pydantic AI’s model settings.
Fallbacks: Bifrost is the place to fall back to the same model through another key, region or deployment. The request keeps its format, and the application doesn’t need to know. For some Claude models, such as Sonnet 5.5 and Haiku 5.5, this works only within one account, because their thinking blocks work only in the account that produced them. After a fallback to another organization or to Bedrock, the API drops the blocks without an error.
A fallback to another provider needs a request in that provider’s format.
Bifrost sends a copy of the original request with only the provider and model
changed, and its conversion decides what is kept. Pydantic AI’s
ModelFallback capability builds a new request in the next model’s format
from the agent’s history, so it’s the better place for these fallbacks. The
next model still continues without the previous model’s reasoning, because
only the provider that signed it can read it. By default, ModelFallback
switches on API errors, content filter errors and exceeded output token
limits.
Leave retries and fallbacks within a model to Bifrost, because it holds the provider keys and can switch to another key or region. Leave validation and fallbacks across models to Pydantic AI, because it knows the agent and each model’s format.
Alternatives #
The same questions apply to the alternatives: which format the provider receives, and whether the layer knows which model it’s talking to.
- LiteLLM works as a library and as a gateway. I moved from it to Bifrost because of routing and governance limits, described in my Bifrost introduction.
- OpenRouter is a hosted gateway with an OpenAI-compatible API. It returns
signed reasoning in the
reasoning_detailsformat, and Pydantic AI’sOpenRouterModelsends it back. - Pydantic AI Gateway is Pydantic’s hosted gateway. Pydantic AI’s
gateway/prefixes send each provider’s native format to it and keep the model’s own name.
What I’d do #
For agents on Pydantic AI behind Bifrost:
- Use each provider’s native class, such as
AnthropicModelfor Claude, not one Chat Completions class for every provider. - Give Pydantic AI a gateway name with the provider, such as
anthropic/claude-opus-5-5, and pass the real model as the profile. Without a prefix, Bifrost’s configuration picks the provider. - Run Bifrost v2.7.0 or later. On older versions, set
thinkingexplicitly, not only an effort setting. - If you use Bifrost for retries, set
max_retriesto 0 in Pydantic AI, so the retries of the two layers don’t multiply.
How to check: run one tool loop per kind of model through the gateway.
When Pydantic AI’s usage shows output_reasoning_tokens for the first
response, the second request should have more input tokens than in a run
without reasoning. If it has the same number, the thinking was dropped. With
store_raw_request_response turned on for a provider, Bifrost’s log shows the
request it actually sent, including the thinking settings, the thinking blocks
and the parameters it dropped, and its attempt trail shows retries the client
never saw.
Conclusion #
Both problems I found between Pydantic AI and Bifrost happened without an error: reasoning dropped between tool calls and an effort lower than requested. The native class and the real model’s profile close that gap. My tests ran against Anthropic’s own API, so check every route an agent uses, even when its calls succeed.