LatentKit

Error Handling

Structured JSON errors, streaming error events, and support correlation IDs.

Request correlation

Every response should include X-LK-Request-ID. Log it with failures when opening support tickets or tracing logs.

Typed JSON errors

Gateway failures return a structured JSON envelope with stable machine-readable codes:

{
  "error": {
    "code": "INSUFFICIENT_CREDITS",
    "category": "billing",
    "message": "Insufficient credits for Platform Access. Please top up your balance.",
    "request_id": "req_abc123",
    "retryable": false
  }
}
FieldDescription
error.codeStable programmatic code
error.categoryBroad handling category such as upstream, model_output, auth, or billing
error.messageHuman-readable detail
error.request_idCorrelation ID for request logs and support
error.retryableWhether retrying the same request can reasonably succeed

Top-level code, message, and request_id remain for older SDKs. New integrations should use error.code and error.category.

Common codes

HTTPCodeMeaning
401INVALID_API_KEYFix Authorization header
400 / 422VALIDATION_ERRORFix request body
403POLICY_REJECTEDPolicy guardrail or route eligibility rejected input
402INSUFFICIENT_CREDITSCredits or plan limit
429RATE_LIMITEDRetry with backoff
503NO_HEALTHY_PROVIDERNo eligible healthy route for capability/profile
200 / 503TOOL_CALL_NOT_PRODUCEDA tool call was required, but the model returned text

Streaming errors

After SSE starts, terminal failures use:

event: error
data: {"error":{"code":"UPSTREAM_ERROR","category":"upstream","message":"...","request_id":"req_abc123","retryable":true},"code":"UPSTREAM_ERROR"}

Client guidance

  1. Read error.category for generic handling and error.code for precise handling
  2. Retry idempotent requests on transient 5xx with backoff
  3. Do not retry 401, 400, or budget errors without changing inputs or billing state

Upgrade-oriented errors

Some plan-limit responses include fields like upgrade_required and upgrade_to for console-native upgrade flows.

See Error reference for the complete taxonomy and retry guidance.

On this page