A nightly batch of 20,000 documents on DeepSeek stopped at document 12,000 with HTTP 402.
In the morning nobody knows which documents were processed.
- ARetry the 402 with exponential backoff, exactly as you do with 429
- BSplit the batch into many smaller requests so each one costs less
- CSwitch the whole batch to the fast model so it spends fewer tokens
- DCheck the estimate against the balance first; mark done documents
Answer: D
Check the estimate against the balance first; mark done documents
Why
402 means the prepaid balance ran out - no retry, model or request size fixes money. Estimate before the run and stop if balance minus a reserve does not cover it; record progress per document so a stopped run resumes where it ended instead of starting over.
- Errors & recoveryA tool call fails with an error.
- Errors & recoveryA streamed generation fails mid-way.
- Errors & recoveryA tool call returns HTTP 400 “invalid parameter: date must be ISO-8601”.
- Errors & recoveryYour fleet of agents all hit a 429 rate-limit at once and every one immediately retries on a fixed 1-second timer.
More on Way of the Agent
- Course programThe first three modules are free: start in the browser or the app, no card needed.
- Library: guides, skills and promptsReady prompt templates, grouped into collections.
- AI ChroniclesSourced stories from the history of AI.
- ConceptsPlain-language explainers of agent engineering.
- Learn AI agentsApps and courses for learning AI agents, compared honestly.
Real situations from building agents - with the answer and why.
Solve a new one every day on the Path