Pydantic AI
Pydantic AI builds agents whose outputs are
validated Pydantic models. It reaches Hyphen through OpenAIChatModel with a
custom OpenAIProvider.
Code
Setup guide: this config comes from Pydantic AI's official documentation and has not been run end to end against the gateway. Corrections to support@hyphen-solution.com.
The model
Code
Two naming traps
OpenAIModel was renamed to OpenAIChatModel. Older tutorials import
OpenAIModel from pydantic_ai.models.openai. That name is gone in current v1
releases, along with OpenAIModelSettings (now OpenAIChatModelSettings).
Do not use the bare "openai:..." string form. It now resolves to
OpenAIResponsesModel, which targets the Responses API. Build the
OpenAIChatModel explicitly as above, or use the "openai-chat:" prefix.
A typed agent
Code
Keep the default output mode
output_type works here because Pydantic AI's default strategy is a tool
call under the hood. That is exactly what MiniMax supports.
Do not switch to NativeOutput. It asks the provider for a strict JSON schema
via response_format, which the M-series ignore. If you want an alternative,
PromptedOutput is the safe one, since it asks in the prompt and validates the
result.
Code
Streaming
Code
Model settings
max_tokens belongs in model_settings, and it needs to be generous:
Code
Set it too low and the reasoning tokens consume the whole budget, the output tool never gets called, and Pydantic AI raises a validation error that looks like a model failure. See Choosing a model.
Gotchas
OpenAIChatModel, notOpenAIModel.- Never the bare
"openai:minimax-m3"string. It picks the Responses API path and drops your base URL. max_tokensof 4000 for anything with tools oroutput_type.- Docs moved from
ai.pydantic.devtopydantic.dev/docs/ai. 429means the monthly budget is spent. See Handling the 429 cap.
Related
- Pydantic AI OpenAI models
- Instructor: a lighter option if you only want structured output.
- Structured JSON output: the raw pattern underneath.