Stage 2 · Lesson 7 of 9
Timeouts, retries and backoff
Treat a model API like any unreliable service across the network. Calls can hang. They can hit ( 429).
They can fail with server errors or overload responses, the codes in the 5xx range. Set a on every call, long enough for your longest expected reply. Retry only errors that might succeed a second time: 429 and 5xx.
Never retry a 400, which means your request itself was wrong. Wait longer before each new attempt (exponential backoff), add a little random so many clients do not retry at the same instant, and honour any retry-after header. Cap the attempts, usually at three or four, then fail clearly or fall back.
Most official already retry some errors by default. Learn what yours does before adding your own retries on top, or you multiply the load.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Prompt Engineering for Software Engineers
Design Gurus · Beginner · Subscription
Prompting patterns for engineers building features, not for chatting
- GitHub repoFreeAnthropic Courses
Anthropic · Beginner
Free notebooks: API fundamentals, then the interactive prompt engineering tutorial
Practise
Keep handy
Also worth your time
Few-shot, chain of thought, JSON enforcement and parsing failures in one place