#192Toto video a jeho text jsou v angličtině.
Error triage: which AI errors deserve a retry and which never do
Retrying every failed AI request can turn a 4-millisecond answer into six seconds of waiting. Learn to read the error code first and respond the right way.
Podrobně
What error triage is
When your app asks an AI service for something and it goes wrong, the service replies with a status code: a three-digit number that names the kind of problem. Triage means reading that number before deciding what to do, the same way a hospital sorts patients by how urgent their case is before treating anyone.
The common mistake is one reaction for every failure, usually "try again". But the five codes you meet most often are not five flavours of "it failed". They are five different instructions, and some of them point in opposite directions.
What the video shows
The video splits errors into two kinds. Some mean "busy, try later". Others mean "your request or your key is wrong". Retrying the second kind only adds waiting: in the course's test, six seconds of it, ending with exactly the same error.
The five codes
| Code | What it means | What to do | |---|---|---| | 400 | Your request is badly built, for example a field the service does not recognise, or too much text | Fix your code; never retry | | 401 | Your key is wrong, missing or cancelled | Fix your setup; never retry | | 429 | Too many requests, or too much text, per minute (a rate limit) | Wait as long as the reply tells you, then retry with growing pauses | | 500 | Something broke at the provider | Retry with growing pauses | | 503 | The provider is running but full | Retry with growing pauses, and send less |
"Growing pauses" means waiting longer after each failure, a technique with its own name, exponential backoff. The key dividing line runs between 400 and 401 on one side and the rest on the other. A 400 or 401 comes back the same no matter how often you send it, because nothing changes between attempts. Waiting cannot fix a typo or a wrong password.
An everyday example
Imagine phoning a shop. If you hear the busy tone, calling back in a few minutes makes sense. If a recording says the number does not exist, redialling a hundred times will not help: you need the right number. A 429 or 503 is the busy tone. A 400 or 401 is the wrong number.
What getting it wrong costs
The course measured two apps hitting a bad key. One retried everything: six attempts with growing pauses, giving up after 6,325 milliseconds, still with a 401. The other read the code first: one attempt, 4 milliseconds, the same 401. Identical outcome, about six seconds apart.
Real products make it worse, because retries are often stacked: a network tool that retries, inside a background job system that retries, inside a queue that redelivers failed jobs. Stack them and those six seconds can grow into minutes, and a permanently broken setup starts to look like a merely slow one.
How to do it
The sorting fits in one small function that returns one of three verdicts: retry, retry after the wait the provider asks for, or stop. Two extra cases are worth adding:
- 402: some providers send it to say "you are out of credit". The right response is a screen with a way to buy more, not a retry.
- 529 or similar provider-specific codes, which mean "overloaded". Treat them like a 503.
Why it matters
Good error handling is not about trying harder. It is about knowing when another try can possibly help. Reading the code first makes broken setups fail fast and visibly, and saves retries for the problems that time can actually fix.
Learn it step by step in Chapter 14 of our free course AI From Scratch: Your First Production LLM Call: Streaming, Retries, Timeouts.
Také na
Další z této kapitoly
#192
#193Streaming: why AI answers arrive word by word, and what it really buys
#194Finish reason: telling a finished AI answer from a cut-off one
#196Exponential backoff: why a retry should wait twice as long each time
#197Thundering herd: when retrying apps move in lockstep and jam a server
#198Concurrency gate: letting fewer requests in made everything faster
Text napsaný s pomocí AI podle kapitoly 14 našeho bezplatného kurzu.