Errors
The error shape every API shares, and every code it can carry, by status, with what to do about each.
Every error from Generate, Embed, Search and Engine has the same JSON shape, and only 2xx responses are billed: a failed call is free. Branch on error.code, which is stable; show error.message to people, as it may change.
{
"type": "error",
"error": {
"type": "invalid_request_error",
"code": "invalid_fen",
"message": "The FEN has 7 ranks; a board has 8.",
"param": "position.fen"
},
"request_id": "req_01J9Z6Q8F3"
}| Field | Meaning |
|---|---|
error.type | The kind of error, one per status below. |
error.code | What went wrong. Stable: safe to branch on. |
error.message | For people. It may change, so don't parse it. |
error.param | The request field at fault, as a path: position.fen, or input[3].text for an Embed item. Left out when no field is at fault. |
error.resets_at | When the refusal lifts, in RFC 3339 UTC, such as the end of a Key limit's period. Left out when it doesn't apply. |
request_id | The same as the request-id header. Find the call in your Request log with it, and quote it when you write to us. |
Read an error
Check the status before you read the body. This call sends a FEN with seven ranks, so it comes back 400 invalid_fen, naming position.fen as the field at fault.
curl https://api.chessdrive.io/v1/generate \
-H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "knight",
"position": { "fen": "rnbqkbnr/pppppppp/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" },
"messages": [{ "role": "user", "content": "Best move?" }]
}'What to do, by status
- 400, 404, 413: the request is wrong. Fix it; sending it again gets the same answer.
- 401, 403: the key isn't accepted, or may not make this call. See Authentication.
- 402: the call was refused for money. It stays refused until someone tops up or raises a limit, or a Key limit resets: retrying a 402 soon won't help; a 429 clears on its own.
- 429: too many calls. Wait for
Retry-Afterseconds, then retry. See Rate limits. - 501: what you called is coming soon. It answers the same until it opens, which the Changelog announces.
- 500, 503: our side failed. Retry with backoff, as below. If it keeps failing, write to us with the
request_id.
A streamed call that fails after its 200 was sent ends with an error event carrying the same body. It is not billed.
Retrying
Retry only what can succeed the second time: a 429, a 500 and a 503. Everything else gets the same answer again until you change something, so don't retry a 400, 401, 403, 404, 413 or 501.
- Wait as long as
Retry-Aftersays when the response carries it, as every 429 does. A 5xx withRetry-Aftergets the same treatment. - Otherwise back off with jitter: wait about 1 second, then 2, then 4, each a random amount between zero and that, so many clients don't retry in step. Give up after 3 or 4 tries and report the
request_id. - Never retry a 402 soon. It waits on a person: a top-up, a raised limit, or a Key limit's
resets_at.
What a retry costs: a refused call is free, so retrying a 429 or a 5xx costs nothing until one succeeds, and only that one is billed. A call you hang up on is billed for what was processed before you hung up: the tokens generated so far on Generate, the Engine time so far on Engine. So if you time out and retry a long call, you can pay for part of it twice; give a call the time it needs, such as max_tokens or an Engine limit you can wait for, rather than a short client timeout. A stream that ends with our own error event is not billed.
Rate limits has a retry loop in curl, Python and JavaScript.
400 Bad request
error.type: invalid_request_error. param names the field at fault.
| Code | When | What to do |
|---|---|---|
invalid_json | The body isn't valid JSON. | Send a JSON object, with Content-Type: application/json. |
missing_field | A required field is missing, such as model on Generate or Embed. | Add the field param names. |
invalid_field | A field has the wrong type or an out-of-range value, or doesn't belong: model on Engine, two Search modes or a field of another, two limits on one Engine call, depth on Lc0, network on Stockfish, an empty text. | Fix or remove the field param names. |
unknown_model | model isn't a Model this API takes, like knight on Embed. | Use a Model ID from Models. |
invalid_fen | A FEN can't be read as a legal position, or no game can reach it (over 8 pawns or 16 pieces on a side, or more promoted pieces than lost pawns). | Check the FEN; message says what is wrong with it. |
invalid_pgn | A PGN can't be read, its main line is over 1,000 half-moves, or the request sends over 256 KB of PGN. | Check the PGN. Only its main line counts. |
invalid_ply | ply is past the end of the PGN's main line. | Use a ply from 0, the start, to the number of half-moves played. |
context_too_long | On Generate, the estimated input plus max_tokens is over the Model's context window. | Shorten the conversation, lower max_tokens, or use Queen. |
too_many_inputs | On Embed, more than 256 items in one call; on Engine, more than 100 positions. | Split the items into calls of 256 or fewer. |
text_too_long | On Embed, a text past 77 tokens, about 300 characters. Texts are never truncated. | Shorten or split the text. |
unknown_engine | engine names one we don't run. | Send stockfish. |
unknown_network | network isn't one of Lc0's: bt4, t82 or t1-256. | Name one of the three, or leave it out for bt4. |
limit_too_high | An Engine limit is over the engine's cap, such as depth over 50 or movetime_ms over 60,000, or a Search limit over 200. | Lower the limit. On Search, page on with cursor. |
unknown_player | On Search, no player on FIDE's list has that fide_id or name. | Check the FIDE ID, or write the name as FIDE's list does: "Carlsen, Magnus". |
cursor_expired | On Search, the cursor is from before the games were rebuilt. | Call again without cursor, from the first page. |
invalid_filter | On Search, where or define isn't a Position filter: an unknown node, a wrong value, a board expression where a test belongs, a ref to nothing or to itself, or a filter over 2,000 nodes. | Mend the node param names, such as where.all[1].ref, and send again. |
game_over | On Engine, the position has no legal moves: checkmate or stalemate. | There is nothing to analyse; check the game is still going. |
401 Unauthorized
error.type: authentication_error. The API key wasn't accepted.
| Code | When | What to do |
|---|---|---|
missing_api_key | No Authorization: Bearer header. | Send the key in the header. |
invalid_api_key | Not a key we issued, or mistyped. | Copy the key again, or create a new one. |
revoked_api_key | The key was revoked. | Create a new key. |
expired_api_key | The key passed its expiry date. | Create a new key. |
disabled_api_key | The key is disabled. | Enable it in API keys, or use another. |
402 Payment required
error.type: billing_error. Refused for money, not speed.
| Code | When | What to do |
|---|---|---|
insufficient_balance | The Balance is used up, or has never held credits; the message says which. | Top up in Billing, or turn on Auto-recharge. |
spend_limit_reached | The Account reached its Spend limit for this month, or this call's worst case would take it past. | An Admin raises or removes the Spend limit, or wait for the next month. On Generate, a lower max_tokens may fit. |
key_limit_reached | This API key reached its Key limit for its period, or this call's worst case would take it past. resets_at says when it resets. | Raise the Key limit, use another key, or wait for resets_at. On Generate, a lower max_tokens may fit. |
A call's worst case is the most it can cost: on Generate, the estimated input plus max_tokens at the Model's prices; on Engine, 60 seconds of Engine time; on Embed, the call itself. So one call can't take you past a limit. For that time the worst case is a Hold on your Balance, released when the call is billed. Calls already running when the limit is reached are still served and billed, so the spend can end up over the limit by at most one worst case for each of them.
403 Forbidden
error.type: permission_error. The key is fine, but may not make this call. On plan_required, fall back to Knight; waiting isn't the fix, as it is on a 429.
| Code | When | What to do |
|---|---|---|
key_not_allowed | The key is restricted to other APIs, or to another Model on Generate or Embed. On GET /v1/balance, the key is a Team member's, who sees none of the Organization's billing. | Use a key allowed for this call, or change its restrictions. For the Balance, use an Admin's key. |
account_suspended | The Account is suspended. | Write to us at contact@edgecaselabs.dev. |
plan_required | Queen on the Free plan, past its 100 calls in any 7 days, counted for the whole Account. Every call admitted past the rate limit counts, whether it succeeded or failed. resets_at and Retry-After say when the oldest leaves the 7 days. | Go on with Knight, which still works, or move the Account to Hobby or Pro, which lifts the cap at once. A Skill falls back to Knight on this code. See Plans. |
404 Not found
error.type: not_found_error.
| Code | When | What to do |
|---|---|---|
not_found | No such path, or the wrong method for it. | Check the path and method in the API reference. Every call is a POST under /v1, except GET /v1/models. |
413 Request too large
error.type: invalid_request_error.
| Code | When | What to do |
|---|---|---|
request_too_large | The body is over 16 MB, or took over 30 seconds to arrive. | Send less in one call. |
429 Too many requests
error.type: rate_limit_error. Retry-After says how many seconds to wait, so wait, and don't change the Model.
| Code | When | What to do |
|---|---|---|
rate_limited | Over the requests per minute, Embed's items per minute, or Engine's requests in flight after a 5-second wait. On Search, also when the games are busy. | Wait for Retry-After, then retry. |
token_rate_limited | Over Generate's tokens per minute. | Wait for Retry-After, then retry. |
daily_limit_reached | Over Free's requests per day. | Wait for midnight UTC, or move the Account to Hobby or Pro, which have no daily caps. |
500 Internal error
error.type: api_error.
| Code | When | What to do |
|---|---|---|
internal_error | Something failed on our side. | Retry with backoff. If it persists, write to us with the request_id. |
501 Coming soon
error.type: api_error.
| Code | When | What to do |
|---|---|---|
coming_soon | The API, the engine or the Search mode you named isn't open yet. param says which. | Use what is live today, such as Generate, Engine with "engine": "stockfish", or Search with position, player or where. Its opening is announced in the Changelog. |
503 Overloaded
error.type: overloaded_error.
| Code | When | What to do |
|---|---|---|
upstream_unavailable | What serves the call is busy or down. | Retry with backoff. |
Getting help
If an error doesn't make sense, or a 500 keeps coming back, write to contact@edgecaselabs.dev with the request_id of a failing call, from the response body or its request-id header. We reply within two business days. Incidents are posted on the status page linked at the foot of every page.