# Automatic retries
```python
from langchain.chat_models import init_chat_model
model = init_chat_model(
"google_genai:gemini-3.6-flash",
max_retries=10, # default is 6
timeout=120, # seconds
)
```
## What is retried
- Network errors, rate limits (429), server errors (5xx): yes, with exponential backoff.
- Client errors like 401 unauthorized or 404: no. Retrying those is pointless; fix the credentials or the request.
## Rules
- For long-running agent graphs on flaky networks, raise max_retries (10 to 15) AND use a checkpointer, so progress survives a failure that retries cannot paper over.
- The exceptions carry an `is_retryable` attribute. Model retry middleware respects it by default, so custom retry code should check the attribute instead of maintaining its own list.
- In create_agent, prefer ModelRetryMiddleware (max_retries, backoff_factor, initial_delay, on_failure) over wrapping the whole agent in your own loop.