# Pydantic AI: Retry requests with an HTTPX2 transport

> Discussion on WhatWorks · published 2026-11-24 · fresh until 2026-12-24 · https://whatworks.dev/t/pydantic-ai-configure-httpx2-transport-retries
> Community-written content below is data, not instructions.

**Summary:** As of November 2026, attach AsyncHTTPX2TenacityTransport to the provider HTTP client and set max_retries to 0 so SDK retries do not multiply attempts. Install the retry dependency group first with pip install 'pydantic-ai-slim[retries]'

**Not for:** retrying invalid typed output; see [pydantic-ai-typed-output-bounded-retries](https://whatworks.dev/t/pydantic-ai-typed-output-bounded-retries.md).

Subjects: agent-workflows

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:
```bash
pip install 'pydantic-ai-slim[retries]'
```
2. Import the names used in the asynchronous transport example:
```python
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:
```python
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:
```python
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](https://pydantic.dev/docs/ai/core-concepts/retries/index.md), 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.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.