Quancisuancis

Platform

Errors

Status codes, error codes, and which errors to retry.

Error shape

Errors return an HTTP status and a JSON body with an error object. Use code to decide what to do; the message is for people.

402 response
{
  "error": {
    "message": "Insufficient balance ($0.00). Add funds to continue.",
    "type": "insufficient_balance",
    "code": "insufficient_balance"
  }
}

This shape is used on every route. The one exception is an unknown model on the Messages route, which answers in Anthropic's shape: type: "error" with a nested error object.

Status and error codes

StatusCodeMeaningWhat to do
400invalid_jsonThe body is not a valid JSON object.Fix the request body.
400model_not_foundThe model name is not recognized.Use kael-beta.
400param: reasoning_effortThe thinking level is not off, low, high, max, z-low, or z-high.See Thinking levels.
400invalid_requestThe request was rejected as invalid.Check your messages, tools and parameters.
400context_length_exceededThe request is too long for the context window.Shorten the messages, tools or attachments.
401missing_api_keyNo API key was sent.Send a key in a supported header.
401invalid_api_keyThe key is unknown or revoked.Create a new key.
402insufficient_balanceYour balance is $0 or below.Add credit, then retry.
413request_too_largeThe request is too large.Send less data.
429rate_limit_exceededToo many requests in a minute, or Kael is briefly busy.Back off, then retry.
429concurrency_limit_exceededToo many requests running at once.Wait for one to finish.
500billing_unavailableYour balance could not be checked.Retry shortly.
502upstream_unreachableKael could not complete the request.Retry.
502upstream_errorKael could not complete the request.Retry.
503upstream_unavailableKael is temporarily unavailable.Retry shortly, with backoff.
504upstream_timeoutThe request took too long.Retry, or lower the thinking level or split the task.

What to retry

  • Retry 429, 500, 502, 503 and 504, with exponential backoff and a little random jitter.
  • Do not retry 400, 401, 402 or 413 until you have fixed the cause. The same request will fail the same way.
  • A retry is a new request, billed like any other if it succeeds.
Python
import random
import time

RETRY = {429, 500, 502, 503, 504}

def with_retries(send, attempts=5):
    for attempt in range(attempts):
        response = send()
        if response.status_code not in RETRY:
            return response
        time.sleep(min(30, 2 ** attempt) + random.random())  # backoff with jitter
    return response

Errors in a stream

An error before streaming starts uses a normal status code. An error after it starts arrives as an event inside the stream, because the status is already 200. See Streaming.