Class LlmErrorBodies

java.lang.Object
org.mockserver.llm.LlmErrorBodies

public final class LlmErrorBodies extends Object
Pure, deterministic helper that produces the provider-specific JSON error body real LLM providers return for overload / rate-limit / server errors. Client SDKs (the OpenAI Python SDK, Anthropic SDK, Google GenAI SDK, …) parse the error.type / error.code fields in these bodies to drive their retry/backoff logic, so emitting the correct shape lets MockServer exercise that logic faithfully against a mock.

Used by HttpLlmResponseActionHandler when injecting a chaos error (probabilistic error or a stateful quota breach) on the LLM response path. When the provider is null or unknown, callers fall back to the generic {"error":{"type":..,"message":..}} body.

Error kinds

The mapping is keyed by a coarse LlmErrorBodies.Kind derived from the HTTP status and the caller's intent:

Provider body reference

  • ANTHROPIC / BEDROCK (Anthropic Messages API errors) — {"type":"error","error":{"type":"overloaded_error"|"rate_limit_error"|"api_error","message":..}}. Bedrock delivers the Anthropic body unchanged.
  • OPENAI / OPENAI_RESPONSES / AZURE_OPENAI (OpenAI error envelope) — {"error":{"message":..,"type":"server_error"|"rate_limit_exceeded","code":..,"param":null}}.
  • GEMINI (Google API error envelope) — {"error":{"code":..,"message":..,"status":"UNAVAILABLE"|"RESOURCE_EXHAUSTED"|"INTERNAL"}}.
  • OLLAMA{"error":".."} (a plain message string).

All output is a JSON string; the helper is static, deterministic, and performs no I/O. Messages are short, fixed, benign test fixtures.