@@ -180,7 +180,7 @@ contains all the exceptions encountered during the `run` execution.
180180=== "Python >=3.11"
181181
182182 ```python {title="fallback_model_failure.py" py="3.11"}
183- from pydantic_ai import Agent, ModelHTTPError
183+ from pydantic_ai import Agent, ModelAPIError
184184 from pydantic_ai.models.anthropic import AnthropicModel
185185 from pydantic_ai.models.fallback import FallbackModel
186186 from pydantic_ai.models.openai import OpenAIChatModel
@@ -192,7 +192,7 @@ contains all the exceptions encountered during the `run` execution.
192192 agent = Agent(fallback_model)
193193 try:
194194 response = agent.run_sync('What is the capital of France?')
195- except* ModelHTTPError as exc_group:
195+ except* ModelAPIError as exc_group:
196196 for exc in exc_group.exceptions:
197197 print(exc)
198198 ```
@@ -206,7 +206,7 @@ contains all the exceptions encountered during the `run` execution.
206206 ```python {title="fallback_model_failure.py" noqa="F821" test="skip"}
207207 from exceptiongroup import catch
208208
209- from pydantic_ai import Agent, ModelHTTPError
209+ from pydantic_ai import Agent, ModelAPIError
210210 from pydantic_ai.models.anthropic import AnthropicModel
211211 from pydantic_ai.models.fallback import FallbackModel
212212 from pydantic_ai.models.openai import OpenAIChatModel
@@ -222,10 +222,11 @@ contains all the exceptions encountered during the `run` execution.
222222 fallback_model = FallbackModel(openai_model, anthropic_model)
223223
224224 agent = Agent(fallback_model)
225- with catch({ModelHTTPError : model_status_error_handler}):
225+ with catch({ModelAPIError : model_status_error_handler}):
226226 response = agent.run_sync('What is the capital of France?')
227227 ```
228228
229229By default, the ` FallbackModel ` only moves on to the next model if the current model raises a
230+ [ ` ModelAPIError ` ] [ pydantic_ai.exceptions.ModelAPIError ] , which includes
230231[ ` ModelHTTPError ` ] [ pydantic_ai.exceptions.ModelHTTPError ] . You can customize this behavior by
231232passing a custom ` fallback_on ` argument to the ` FallbackModel ` constructor.
0 commit comments