You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/models/overview.md
+18-12Lines changed: 18 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,8 +47,8 @@ Pydantic AI uses a few key terms to describe how it interacts with different LLM
47
47
vendor-SDK-agnostic API, ensuring a single Pydantic AI agent is portable to different LLM vendors without
48
48
any other code changes just by swapping out the Model it uses. Model classes are named
49
49
roughly in the format `<VendorSdk>Model`, for example, we have `OpenAIChatModel`, `AnthropicModel`, `GoogleModel`,
50
-
etc. When using a Model class, you specify the actual LLM model name (e.g., `gpt-5`,
51
-
`claude-sonnet-4-5`, `gemini-2.5-flash`) as a parameter.
50
+
etc. When using a Model class, you specify the actual LLM model name (e.g., `gpt-4o`,
51
+
`claude-3-5-sonnet-latest`, `gemini-1.5-flash`) as a parameter.
52
52
-**Provider**: This refers to provider-specific classes which handle the authentication and connections
53
53
to an LLM vendor. Passing a non-default _Provider_ as a parameter to a Model is how you can ensure
54
54
that your agent will make requests to a specific endpoint, or make use of a specific approach to
@@ -61,7 +61,7 @@ Pydantic AI uses a few key terms to describe how it interacts with different LLM
61
61
and the same schema transformer needs to be used for Gemini models whether you're using `GoogleModel`
62
62
with model name `gemini-2.5-pro-preview`, or `OpenAIChatModel` with `OpenRouterProvider` and model name `google/gemini-2.5-pro-preview`.
63
63
64
-
When you instantiate an [`Agent`][pydantic_ai.Agent] with just a name formatted as `<provider>:<model>`, e.g. `openai:gpt-5` or `openrouter:google/gemini-2.5-pro-preview`,
64
+
When you instantiate an [`Agent`][pydantic_ai.Agent] with just a name formatted as `<provider>:<model>`, e.g. `openai:gpt-4o` or `openrouter:google/gemini-2.5-pro-preview`,
65
65
Pydantic AI will automatically select the appropriate model class, provider, and profile.
66
66
If you want to use a different provider or profile, you can instantiate a model class directly and pass in `provider` and/or `profile` arguments.
67
67
@@ -86,6 +86,12 @@ You can use [`FallbackModel`][pydantic_ai.models.fallback.FallbackModel] to atte
86
86
in sequence until one successfully returns a result. Under the hood, Pydantic AI automatically switches
87
87
from one model to the next if the current model returns a 4xx or 5xx status code.
88
88
89
+
!!! note
90
+
91
+
The provider SDKs on which Models are based (like OpenAI, Anthropic, etc.) often have built-in retry logic that can delay the `FallbackModel` from activating.
92
+
93
+
When using `FallbackModel`, it's recommended to disable provider SDK retries to ensure immediate fallback, for example by setting `max_retries=0` on a [custom OpenAI client](openai.md#custom-openai-client).
94
+
89
95
In the following example, the agent first makes a request to the OpenAI model (which fails due to an invalid API key),
90
96
and then falls back to the Anthropic model.
91
97
@@ -97,8 +103,8 @@ from pydantic_ai.models.anthropic import AnthropicModel
97
103
from pydantic_ai.models.fallback import FallbackModel
98
104
from pydantic_ai.models.openai import OpenAIChatModel
0 commit comments