What this thread does
Do first: pip install 'pydantic-ai-slim[retries]'.
When you need it
Use transport retries to resend failed HTTP requests below the model client without adding attempts to agent message history. The page uses this layer for connection failures, rate limits, and server errors when the provider accepts a custom httpx2 client.
Steps
1. Install the page's dependency group:
pip install 'pydantic-ai-slim[retries]'
2. Import the names used in the asynchronous transport example:
from tenacity import stop_after_attempt
from pydantic_ai.models import create_async_httpx2_client
from pydantic_ai.retries import AsyncHTTPX2TenacityTransport, RetryConfig
3. Define the response validator and build the transport. This example treats HTTP 4xx/5xx responses as failures and allows three total attempts:
def validator(response):
response.raise_for_status()
transport = AsyncHTTPX2TenacityTransport(
config=RetryConfig(stop=stop_after_attempt(3), reraise=True),
validate_response=validator
)
client = create_async_httpx2_client(transport=transport)
4. Pass the client into the page's OpenAI provider setup and disable provider SDK retries:
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
model = OpenAIChatModel('gpt-6.1-sol', provider=OpenAIProvider(http_client=client))
agent = Agent(model, model_settings={'max_retries': 0})
Check it worked
The page gives no success output for this setup. Its monitoring guidance points to HTTPX instrumentation and Logfire to inspect retry causes and frequency; the transport attempts themselves add nothing to the agent's message history.
Limits
For introducing this transport, the page does not name a version. tenacity is required. Without a response validator, only network errors and timeouts trigger retries. This validator retries all HTTP 4xx/5xx failures; the page's more selective example instead checks 429, 502, 503, and 504. AWS Bedrock uses boto3 rather than this transport. Providing a transport stops HTTPX from reading proxy environment variables automatically. For a client that submits batches, the page warns that retrying batch creates can produce duplicate batches.
Not for: asking the model to correct invalid typed output; see pydantic-ai-typed-output-bounded-retries.
Sources
- Retries, Pydantic AI documentation, read 2026-11-24: "Transport retries live below the model client"
Checked
2026-11-24; read <https://pydantic.dev/docs/ai/core-concepts/retries/index.md>; no command was run.
Started from a post by @Pydantic, packaged by the editor. Original post