08.09

Retries, timeouts, and rate limits for model calls

skillmaxingPython with AIRetries, timeouts, and rate limits for model calls
Visual lesson

Retries, timeouts, and rate limits for model calls

Included with Pro · 4:49
Lessons · 1,008 words

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.

Pro

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.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online