Skip to Content
LoremLLM

Error injection

Rate limits, overloads, timeouts, malformed chunks and cut-off streams, on demand.

Real providers fail in ways that are hard to reproduce. A mock fails exactly when you ask it to. There are three kinds of failure.

HTTP errors

error(status, options?) returns a non-2xx response in the endpoint's real error shape, so SDKs raise their usual classes, like OpenAI.RateLimitError, Anthropic.RateLimitError and the AI SDK's APICallError.

{ when: { header: { "x-mock-fail": "rate" } }, reply: error(429, { retryAfter: 2 }) }
CallWhat the client sees
error(429, { retryAfter })Rate limit with a retry-after header
error(400, { message })Invalid request
error(401), error(403), error(404)Auth and not-found errors
error(500), error(503)Server errors
error(529)Anthropic overloaded_error. Other endpoints get a 503
EndpointError body
OpenAI{ "error": { "message", "type", "param", "code" } }
Anthropic{ "type": "error", "error": { "type", "message" } }
AI SDK, eve{ "error": "message" }

Stream faults

fault(kind, options?) breaks the connection itself.

CallWhat happens
fault("abort", { afterChunks })The stream starts, then the connection closes without a finish event
fault("timeout", { afterMs })The connection stays open and sends nothing until it closes
fault("malformed", { afterChunks })A chunk that isn't valid JSON

afterChunks lets the stream start normally and fail partway, which is where retry and resume logic usually breaks:

reply: [text("Here is a long answer that will never finish"), fault("abort", { afterChunks: 3 })];

Finish reasons

Some failures are successful responses that end badly. finish(reason) sets the reason using the AI SDK's names, translated for each endpoint:

CallOpenAIAnthropicAI SDK
finish("length")lengthmax_tokenslength
finish("content-filter")content_filterrefusalcontent-filter
reply: [text("The answer is cut off right"), finish("length")];

Flaky on purpose

oneOf fails a share of requests, seeded so it fails the same requests on every run:

reply: oneOf([
  { weight: 9, reply: text("OK") },
  { weight: 1, reply: error(503) },
]);

On this page