Class LlmErrorBody

java.lang.Object
org.mockserver.llm.LlmErrorBody

public final class LlmErrorBody extends Object
Pure, deterministic helper that produces the provider-specific overload / rate-limit / server-error response bodies (and the matching default HTTP status) that real LLM providers return. Client SDKs parse these distinct error shapes to decide whether (and how) to retry/back off, so emitting them faithfully lets a mock exercise that retry/backoff logic realistically — a generic body would be silently ignored by an SDK that only retries on, say, an overloaded_error type.

This is the body/status counterpart to LlmRateLimitHeaders (which owns the rate-limit headers): the handler picks the body+status here and stamps the headers there. All methods are static and pure (no clocks, no randomness, no shared state).

Provider error-shape reference

  • ANTHROPIC — top-level {"type":"error","error":{"type":...,"message":...}}. Overload: HTTP 529 overloaded_error; rate-limit: HTTP 429 rate_limit_error; server error: HTTP 500 api_error. (source: Anthropic "Errors" docs.)
  • OPENAI / OPENAI_RESPONSES / AZURE_OPENAI{"error":{"message":...,"type":...,"param":null,"code":...}}. Rate-limit: HTTP 429 type rate_limit_exceeded; overload/server: HTTP 503 type server_error. (source: OpenAI "Error codes" docs.)
  • GEMINI — Google API envelope {"error":{"code":N,"message":...,"status":...}}. Rate-limit: HTTP 429 status RESOURCE_EXHAUSTED; overload: HTTP 503 status UNAVAILABLE.
  • BEDROCK — AWS JSON error {"__type":...,"message":...}. Rate-limit: HTTP 429 ThrottlingException; overload: HTTP 503 ServiceUnavailableException.
  • OLLAMA — local engine; simple {"error":...}. No real rate-limit/overload concept, so all kinds map to HTTP 500 with a generic message.
  • Method Details

    • bodyFor

      public static LlmErrorBody.ErrorShape bodyFor(Provider provider, LlmErrorBody.Kind kind)
      Returns the provider-specific error shape for the given provider and kind, or null when the provider is unknown/null so the caller can fall back to its generic body. The returned status is the provider's natural status for that kind; the caller may override it (e.g. an explicit errorStatus or quotaErrorStatus on the chaos profile) while keeping the provider-correct body.
      Parameters:
      provider - the active LLM provider (may be null)
      kind - the error kind (never null)
      Returns:
      the provider error shape, or null for an unknown provider