Skip to content

Commit dc99ae7

Browse files
cjermainDouweM
andauthored
Docs: AWS Bedrock retry behavior (#3379)
Co-authored-by: Douwe Maan <[email protected]>
1 parent 3256386 commit dc99ae7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

docs/models/bedrock.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,47 @@ model = BedrockConverseModel(
114114
agent = Agent(model)
115115
...
116116
```
117+
118+
## Configuring Retries
119+
120+
Bedrock uses boto3's built-in retry mechanisms. You can configure retry behavior by passing a custom boto3 client with retry settings:
121+
122+
```python
123+
import boto3
124+
from botocore.config import Config
125+
126+
from pydantic_ai import Agent
127+
from pydantic_ai.models.bedrock import BedrockConverseModel
128+
from pydantic_ai.providers.bedrock import BedrockProvider
129+
130+
# Configure retry settings
131+
config = Config(
132+
retries={
133+
'max_attempts': 5,
134+
'mode': 'adaptive' # Recommended for rate limiting
135+
}
136+
)
137+
138+
bedrock_client = boto3.client(
139+
'bedrock-runtime',
140+
region_name='us-east-1',
141+
config=config
142+
)
143+
144+
model = BedrockConverseModel(
145+
'us.amazon.nova-micro-v1:0',
146+
provider=BedrockProvider(bedrock_client=bedrock_client),
147+
)
148+
agent = Agent(model)
149+
```
150+
151+
### Retry Modes
152+
153+
- `'legacy'` (default): 5 attempts, basic retry behavior
154+
- `'standard'`: 3 attempts, more comprehensive error coverage
155+
- `'adaptive'`: 3 attempts with client-side rate limiting (recommended for handling `ThrottlingException`)
156+
157+
For more details on boto3 retry configuration, see the [AWS boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html).
158+
159+
!!! note
160+
Unlike other providers that use httpx for HTTP requests, Bedrock uses boto3's native retry mechanisms. The retry strategies described in [HTTP Request Retries](../retries.md) do not apply to Bedrock.

docs/retries.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,17 @@ agent = Agent(model)
339339
- Use async transports for better concurrency when handling multiple requests
340340

341341
For more advanced retry configurations, refer to the [tenacity documentation](https://tenacity.readthedocs.io/).
342+
343+
## Provider-Specific Retry Behavior
344+
345+
### AWS Bedrock
346+
347+
The AWS Bedrock provider uses boto3's built-in retry mechanisms instead of httpx. To configure retries for Bedrock, use boto3's `Config`:
348+
349+
```python
350+
from botocore.config import Config
351+
352+
config = Config(retries={'max_attempts': 5, 'mode': 'adaptive'})
353+
```
354+
355+
See [Bedrock: Configuring Retries](models/bedrock.md#configuring-retries) for complete examples.

0 commit comments

Comments
 (0)