Docs/API

Errors, and what each one charged

What does each status mean, and did it cost me anything?

Checked against the code on

Errors use standard HTTP status codes and the OpenAI error envelope. The column that matters most is the last one: some failures happen after the model has already run, and those are charged.

Envelope
{ "error": { "message": "Not enough credits. This request needs about 12. Add credits at https://heyaskr.ai/wallet", "type": "insufficient_quota", "param": null, "code": null } }

Before the model runs

None of these charge anything. The reservation, if one was made, is released.

StatusTypeMessageWhat to do
400invalid_request_errormessages is required and must be a non-empty array.Send a messages array.
400invalid_request_errorUnsupported message role: XUse system, user or assistant.
400invalid_request_errorNo usable messages were provided.Send at least one message with string content.
400invalid_request_errorThe conversation is too long.Trim below 120,000 characters.
400invalid_request_errorThat model has no published rate and cannot be billed.Pick a model from the catalog.
401authentication_errorMissing or invalid API key.Check the header; make a new key if in doubt.
402insufficient_quotaNot enough credits. This request needs about N. ...Add credits. N is the worst case for this request, so a smaller max_tokens can get it through.
404invalid_request_errorThe model 'x' does not exist.Ids are exact. Copy from the catalog.
429rate_limit_errorThis key's daily cap of N credits would be exceeded. ...Raise the cap in the wallet or wait for the window to roll.
429(plain body){"statusCode":429,"error":"Too Many Requests","message":"Rate limit exceeded, retry in 1 minute"}120 per minute per IP. This one is not in the OpenAI envelope. Back off and retry.
503api_errorModel access is temporarily unavailable. Nothing was charged.Retry shortly.
502api_errorThe model gateway is unavailable.Retry with backoff.

After the model has run

StatusTypeMessageCharged?What to do
429rate_limit_errorThe upstream gateway is busy. Retry shortly.NoRetry after a short delay.
502 or 400api_errorThe model gateway rejected the request.No502 when the provider failed, 400 when it refused the request. Check the prompt and the model.
502api_errorThe model returned no content. Nothing was charged.NoA request that returns nothing is an error, not an empty answer. Retry or change the prompt.
502api_errorThe gateway sent an unreadable response. It was billed upstream, so the reserved credits were charged.Yes, the reservationDo not retry blindly. Check your activity first.
504api_errorThe model took longer than the gateway deadline. It was generated and billed upstream, so the reserved credits were charged.Yes, the reservationLower max_tokens or pick a faster model. Do not retry blindly.

A retry loop that treats every 5xx as free will double-spend on the two charged cases. Retry 503, 502 with unavailable or rejected, and 429. Log 504 and the unreadable 502 and look before retrying.

Backoff that behaves

Python
import time, requests

RETRY = {429, 503}

def call(payload, tries=4):
    for attempt in range(tries):
        r = requests.post("https://heyaskr.ai/v1/chat/completions", json=payload,
                          headers={"Authorization": "Bearer askr_live_..."}, timeout=130)
        if r.status_code == 200:
            return r.json()
        body = r.json().get("error", {})
        charged = "reserved credits were charged" in body.get("message", "")
        if r.status_code in RETRY or (r.status_code == 502 and not charged):
            time.sleep(2 ** attempt)
            continue
        raise RuntimeError(f"{r.status_code}: {body.get('message')}")