Package org.mockserver.llm
Class LlmErrorBody
java.lang.Object
org.mockserver.llm.LlmErrorBody
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 529overloaded_error; rate-limit: HTTP 429rate_limit_error; server error: HTTP 500api_error. (source: Anthropic "Errors" docs.) - OPENAI / OPENAI_RESPONSES / AZURE_OPENAI —
{"error":{"message":...,"type":...,"param":null,"code":...}}. Rate-limit: HTTP 429 typerate_limit_exceeded; overload/server: HTTP 503 typeserver_error. (source: OpenAI "Error codes" docs.) - GEMINI — Google API envelope
{"error":{"code":N,"message":...,"status":...}}. Rate-limit: HTTP 429 statusRESOURCE_EXHAUSTED; overload: HTTP 503 statusUNAVAILABLE. - BEDROCK — AWS JSON error
{"__type":...,"message":...}. Rate-limit: HTTP 429ThrottlingException; overload: HTTP 503ServiceUnavailableException. - OLLAMA — local engine; simple
{"error":...}. No real rate-limit/overload concept, so all kinds map to HTTP 500 with a generic message.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutable (status, jsonBody) pair returned bybodyFor(org.mockserver.model.Provider, org.mockserver.llm.LlmErrorBody.Kind).static enumThe kind of provider error to synthesise. -
Method Summary
Modifier and TypeMethodDescriptionstatic LlmErrorBody.ErrorShapebodyFor(Provider provider, LlmErrorBody.Kind kind) Returns the provider-specific error shape for the givenproviderandkind, ornullwhen the provider is unknown/null so the caller can fall back to its generic body.
-
Method Details
-
bodyFor
Returns the provider-specific error shape for the givenproviderandkind, ornullwhen 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 expliciterrorStatusorquotaErrorStatuson the chaos profile) while keeping the provider-correct body.- Parameters:
provider- the active LLM provider (may benull)kind- the error kind (nevernull)- Returns:
- the provider error shape, or
nullfor an unknown provider
-