Errors

Merki returns JSON errors with a stable shape. Handle them by code, not by message text.

Quick path

  1. Read the HTTP status and the error.code.
  2. Retry 429 and 5xx with exponential backoff; do not retry 4xx except 429.
  3. On 401, rotate the key instead of retrying.

Details

StatusCodeMeaningRetry
400invalid_requestValidation failed: unknown model, bad field, over context.No — fix the request.
401invalid_keyMissing, revoked, or unknown key.No — rotate. See API keys.
402insufficient_creditsBalance too low for the request.No — top up. See Credits.
403forbiddenTier or verification does not cover this request.No — check Access tiers.
404not_foundUnknown endpoint or model name.No — check Endpoints.
409refusedRequest refused under content policy.No — see Content safety.
429rate_limitedOver the rate limit. Retry-After is set.Yes — back off. See Rate limits.
5xxupstream_error / internal_errorMerki or a BYOK provider failed.Yes — back off with jitter.

Error body:

{"error": {"code": "rate_limited", "message": "Slow down.", "retry_after": 12}}

Mid-stream failure

On streaming requests, a failure after the first chunk ends the stream. Only tokens actually delivered are billed. Re-issue the request; there is no resume. See Streaming and Usage.

Checklist

  • [ ] 401 triggers rotation, not retry.
  • [ ] 429 honors Retry-After.
  • [ ] Refusals are surfaced to the operator, not silently retried.

Next step

Tune request volume: Rate limits.