Cognitivers docs
Resources

Errors

What each status code means, what the body carries, and what to do about it.

Every error is a JSON body with a machine-readable type, the status_code, and a message written for a human:

{
  "type": "virtual_key_required",
  "status_code": 401,
  "error": { "message": "virtual key is required. Provide a virtual key via the x-bf-vk header." }
}

Branch on type rather than on the message text, which is wording and can change.

Status codes

StatustypeMeaningWhat to do
400invalid_requestThe body is malformed or a parameter is not validFix the request; retrying will not help
401virtual_key_requiredNo credential was sentAdd the Authorization header
401access_not_foundThe key does not exist or was revokedCheck the key, then rotate if it should be valid
403model_not_allowedThe key is not scoped to that modelUse an allowed model or widen the key's scope
404model_not_foundUnknown model idCheck the id against Models and prices
413context_length_exceededInput over the ceiling for that model on your planShorten the input, raise the plan, or send it to the streaming host
429rate_limit_exceededConcurrency ceiling reachedBack off with jitter and cap attempts
429budget_exceededThe key's monthly budget is spentRaise the budget or use another key
500internal_errorSomething failed on our sideRetry with backoff; if it persists, contact us with the request id
503unavailableTemporarily unable to serveRetry with backoff

Retrying

Two categories, and treating them the same is how a small incident becomes a large one:

  • Retryable: 429, 500, 503, and network failures. Back off exponentially with jitter, cap the attempts, and surface the failure if the cap is reached.
  • Not retryable: 400, 401, 403, 404, 413. The request is wrong in a way that will still be wrong on attempt five.

Streaming failures

A stream can fail after it has started. finish_reason tells you whether it ended properly:

finish_reasonMeaning
stopThe model finished
lengthIt hit the output ceiling; the answer is incomplete
absent, with a connection errorThe stream died mid-answer

length is not an error the API returns, it is a signal you asked for too few tokens. And a stream that died mid-answer must be retried as a whole request rather than resumed, because a new generation is not a continuation of the old one.

Reporting a problem

Include the type, the status code, the timestamp, and the model id. Do not include the key. If the request is reproducible, a curl with the key replaced by a placeholder is the fastest thing you can send us.

On this page