Quick Start
1
Turn it on with one env var (zero code change)
2
Pass max_retries through the client factory
3
Construct the client directly
How It Works
The value is forwarded into the underlyingopenai SDK, which honours Retry-After on 429s and applies exponential backoff for transient errors.
praisonai --auto uses LiteLLM first and only falls back to OpenAI on error. OPENAI_MAX_RETRIES therefore only takes effect on that fallback path — see Auto Mode Providers for the fallback flow.Configuration Options
Precedence:
explicit arg > OPENAI_MAX_RETRIES env var > SDK default.
Non-integer
OPENAI_MAX_RETRIES (e.g. "abc") is silently ignored and the SDK default takes over — no crash.Which Approach to Use
Match the retry surface to how broadly you want the policy to apply.Common Patterns
Turn it on globally with one env var — for production deployments where every call should retry the same way.max_retries explicitly when you build the client for a hot path.
AutoAgents also accepts a max_retries argument, but that controls its own config-generation retries — it is separate from the SDK-level max_retries documented here. Use OPENAI_MAX_RETRIES for a process-wide native-client policy.Retry-After, so retries are wasted latency.
Best Practices
Prefer the env var for cluster-wide policy
Prefer the env var for cluster-wide policy
One place, no code change, easy to bump per environment. Set
OPENAI_MAX_RETRIES once and every native call inherits it.Start with 3–5
Start with 3–5
This matches the SDK’s typical rate-limit budget without inflating tail latency.
Don't stack with agent-level retry unless you mean to
Don't stack with agent-level retry unless you mean to
Combining
OPENAI_MAX_RETRIES=5 with Agent(retry=True, max_retries=3) multiplies attempts (5 × 3 = 15). Pick one layer for the primary retry policy and use the other only as a safety net.Not a substitute for failover
Not a substitute for failover
Retries help transient blips; for provider outages use
LLMConfig(fallbacks=[...]) — see Model Fallback.Related
Agent Retry
Retry the LiteLLM-backed agent loop with jittered exponential backoff.
Model Fallback
Fail over to alternate models during provider outages.
LLM Error Classification
Understand which errors are retryable versus fatal.

