Your LLM app works in the demo. What happens when the API returns 529?
Most LLM apps have code for when the API fails: retries, a fallback model, a friendly 429 message, a UI that keeps the partial text when a stream drops. In most projects I’ve seen, that’s the least tested code in the repo.
The usual fix is hand-written mocks, and I think they mostly give false confidence:
- They drift from reality. Each SDK builds its exception from the exact error body. A mock returning { error: "overloaded" } won’t make the Anthropic SDK throw the overloaded_error it throws in prod.
- They skip the SDK. If you mock the client, the SDK’s own retry logic, timeout handling and streaming parser never run, and those are exactly the parts that matter when things break.
So I built an open-source library for this, llm-crashtest. It applies the VCR approach to LLM APIs: you record a real exchange once, replay it offline (no key, no cost, deterministic), then inject failures on purpose: a 529 on one specific model, a 429 with retry-after, a timeout, a stream cut after N chunks, or a malformed event. Because it works at the fetch level, the real SDK code runs and throws its real errors. Cassettes are scanned for API keys before anything is written to disk.
I’d really like to hear how others handle this in production:
On 529/overload: do you switch models, switch providers, or just retry with backoff? Has a fallback model ever degraded quality enough for users to notice?
On a broken stream: do you keep the partial answer, or discard it and retry?
Testing: recorded fixtures, hand-written mocks, chaos in staging… or not at all (be honest)?
Cassettes: for people who already use VCR-style recordings, how do you keep them from going stale as prompts change?







Comments1
Agreed that the failure path is the least tested code. A real one from my own setup: an unattended agent run failed on a 429 usage-limit error, and the only thing that saved it was that the job reported the failure in its daily email instead of retrying silently. Since then I treat "tell a human, then stop" as a valid fallback, and I test that path the same way as the happy one. Using the real SDK against a fake server, as you describe, is the right way to exercise it.
1 comment
Agreed that the failure path is the least tested code. A real one from my own setup: an unattended agent run failed on a 429 usage-limit error, and the only thing that saved it was that the job reported the failure in its daily email instead of retrying silently. Since then I treat "tell a human, then stop" as a valid fallback, and I test that path the same way as the happy one. Using the real SDK against a fake server, as you describe, is the right way to exercise it.