Retries, timeouts, and rate limits for model calls
Retries, timeouts, and rate limits for model calls
A model call is an HTTP request with unusual failure habits. It can take thirty seconds and then succeed. It can return 429 because you sent too many tokens this minute, with a header saying when to try again. It can return an overloaded error for a few minutes across the whole provider. And a streaming call can die after half the answer has already reached the browser. The three defences are the same as for any remote call, timeouts, retries, and concurrency limits, but the numbers and the rules for what is safe to retry are different.
Both SDKs take a timeout and a max_retries at construction, and both use httpx underneath, so the timeout is an httpx.Timeout. Set them once, in lifespan, so every route in Relay inherits the same policy.
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.