# API reference Four chess APIs: Generate (Knight, Queen), Embed (the Embedding model), Engine (Stockfish, with Lc0 coming soon) and Search (the Games database, with similar moments coming soon), and the Usage API to see what they cost you. The whole contract, which this page is built from, is an OpenAPI 3.1 file at [/openapi.yaml](/openapi.yaml). ## Authentication `Authorization: Bearer ck_…`. Keys are `ck_` + 43 base62 characters + a 6-character base62 CRC32 checksum. Shown once at creation. Server-side use only. ## Errors Every error answers with the same JSON envelope, and only 2xx responses are billed. Each endpoint lists its statuses and their codes. | Field | Type | | Description | |---|---|---|---| | `type` | string | required | One of `error`. | | `error` | object | required | | | `error.type` | string | required | One of `invalid_request_error`, `authentication_error`, `billing_error`, `permission_error`, `not_found_error`, `rate_limit_error`, `api_error`, `overloaded_error`. | | `error.code` | string | required | A stable machine-readable code; see each response for the list. | | `error.message` | string | required | For humans; may change. Never contains provider text. | | `error.param` | string | optional | The request field at fault, as a path: `position.fen`, `input[3].text`. | | `error.resets_at` | string | optional | When the refusal lifts, RFC 3339 in UTC, such as the end of a Key limit's period on `key_limit_reached`, or when the next Queen call frees up on `plan_required`. | | `request_id` | string | required | Same value as the `request-id` header. | ## Generate `POST /v1/generate` Ask Knight or Queen, optionally about a position, and get prose with its named moves checked. Stateless: send the whole conversation each time. The reply is markdown. Every move it names comes back as a Line, which the prose links as `[text](line:L1)`; a Line is cut at its first illegal move, so every move in `lines` is legal. Without a `position`, `lines` is empty. Coaching, explaining and picking a move are Recipes in the Docs, not APIs. With `stream: true` the response is Server-Sent Events (see `GenerateStreamEvent`). ### Request body | Field | Type | | Description | |---|---|---|---| | `model` | string | required | Knight or Queen: a versioned Model ID (`knight-1`, `queen-1`) or an alias for the latest version (`knight`, `queen`). The Embedding model is `invalid_field`. | | `system` | string | optional | Instructions for the Model, ahead of the conversation. | | `messages` | array of objects | required | The whole conversation, alternating `user` and `assistant`, ending with `user`. | | `messages[].role` | string | required | One of `user`, `assistant`. | | `messages[].content` | string | required | Markdown. Assistant turns are sent back as received, `line:` links included. | | `position` | object | optional | The position the conversation is about. Without one, `lines` is always empty. | | `position.fen` | string | optional | A position in Forsyth–Edwards Notation. | | `position.pgn` | string | optional | A game in PGN. Only its main line counts; variations and comments are ignored. The main line holds at most 1,000 half-moves, and one request sends at most 256 KB of PGN, each distinct PGN counted once. | | `position.ply` | integer | optional | Half-moves into the PGN's main line; 0 is the start position. | | `max_tokens` | integer | optional | The most output tokens to generate, up to the Model's output cap: 3,072 on Knight, 4,096 on Queen. Left out, it is 1,024 on Knight and 4,096 on Queen, whose reasoning can't be turned off. Over the cap is `invalid_field`. Estimated input plus `max_tokens` over the Model's context window is `context_too_long`, never silently clamped. Reasoning counts toward it, so a low `max_tokens` can cut the reply short or leave no room for it. A reply with no text is `upstream_unavailable`, unbilled. | | `temperature` | number | optional | Default `1`. | | `stream` | boolean | optional | Default `false`. | ### Response | Field | Type | | Description | |---|---|---|---| | `id` | string | required | Same value as the `request-id` header. | | `model` | string | required | The versioned Model ID that served the request. | | `content` | string | required | Markdown; Lines are referenced as `[text](line:L1)`. A `line:` link with no matching Line is plain text. | | `lines` | array of objects | required | | | `lines[].id` | string | required | Referenced from the prose as `[text](line:)`. | | `lines[].from_fen` | string | required | A position in Forsyth–Edwards Notation. | | `lines[].moves` | array of objects | required | | | `finish_reason` | string | required | `end` when the Model finished, `max_tokens` when it was cut off there. One of `end`, `max_tokens`. | | `usage` | object | required | Generate is priced in tokens: every token the Model processes is billed, including the grounding we add and its reasoning. `cached_tokens` and `grounding_tokens` are part of `input_tokens`, and `reasoning_tokens` is part of `output_tokens`; each is 0 when there is none. | | `usage.input_tokens` | integer | required | Every input token, cached and grounding included. | | `usage.output_tokens` | integer | required | Every output token, reasoning included. | | `usage.cached_tokens` | integer | required | Input tokens read from cache (the conversation history a client resends), billed at the cached-input price. | | `usage.grounding_tokens` | integer | required | Input tokens we added to ground the Model in the position, billed as input. | | `usage.reasoning_tokens` | integer | required | Output tokens the Model spent reasoning before it answered, billed as output. | | `cost_usd` | string | required | What this call drew from the Balance, as a decimal string in dollars. | ### Errors - **400**: `invalid_request_error`. Codes: `invalid_json`, `missing_field`, `invalid_field`, `unknown_model`, `invalid_fen`, `invalid_pgn`, `invalid_ply`, `context_too_long` (Generate), `too_many_inputs` and `text_too_long` (Embed), `unknown_engine`, `unknown_network`, `limit_too_high` and `game_over` (Engine). - **401**: `authentication_error`. Codes: `missing_api_key`, `invalid_api_key`, `revoked_api_key`, `expired_api_key`, `disabled_api_key`. - **402**: `billing_error`: the call was refused for money, not speed. Codes: `insufficient_balance` (the Balance is used up, or has never held credits), `spend_limit_reached` (the Account's Spend limit for this month), `key_limit_reached` (this API key's Key limit for its period, with `resets_at`). - **403**: `permission_error`. Codes: `account_suspended`, `key_not_allowed` (the API key is restricted to other APIs, or to another Model on an API that takes `model`; on `GET /v1/balance`, the key is a Team member's; a Study key anywhere but Engine and Generate), and `plan_required` (Queen on the Free plan past its 100 calls in any 7 days, counted per Account; Knight still works). A `plan_required` refusal carries the rate-limit headers, `Retry-After`, and `resets_at`, when the oldest of those calls leaves the 7 days. A Skill falls back to Knight on it; Hobby or Pro lifts it at once. - **413**: `invalid_request_error`. Code: `request_too_large` (the body is over 16 MB, or took over 30 seconds to arrive). - **429**: `rate_limit_error`: slow down; `Retry-After` says how long. The code names the limit: `rate_limited` (requests per minute, Embed items per minute, or requests in flight on Engine and Embed), `daily_limit_reached` (Free's requests per day), `token_rate_limited` (tokens per minute, Generate). - **500**: `api_error`. Code: `internal_error`. - **503**: `overloaded_error`. Code: `upstream_unavailable`. Retry with backoff. ### Samples ```bash curl curl https://api.chessdrive.io/v1/generate \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "knight", "system": "You are a patient chess coach for a 1400-rated player.", "position": {"pgn": "1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 a6", "ply": 10}, "messages": [{"role": "user", "content": "What is the idea behind 5...a6?"}] }' ``` ```python Python import os import requests r = requests.post( "https://api.chessdrive.io/v1/generate", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={ "model": "knight", "system": "You are a patient chess coach for a 1400-rated player.", "position": {"pgn": "1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 a6", "ply": 10}, "messages": [{"role": "user", "content": "What is the idea behind 5...a6?"}], }, ) print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/generate", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: "knight", system: "You are a patient chess coach for a 1400-rated player.", position: { pgn: "1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 a6", ply: 10 }, messages: [{ role: "user", content: "What is the idea behind 5...a6?" }], }), }); console.log(await res.json()); ``` ```json Response { "id": "req_01J9Z6Q8F3", "model": "knight-1", "content": "5...a6 prepares [...b5](line:L1), gaining space on the queenside, and keeps White's knights off b5.", "lines": [ { "id": "L1", "from_fen": "rnbqkb1r/1p2pppp/p2p1n2/8/3NP3/2N5/PPP2PPP/R1BQKB1R w KQkq - 0 6", "moves": [ { "san": "Be2", "uci": "f1e2", "fen": "rnbqkb1r/1p2pppp/p2p1n2/8/3NP3/2N5/PPP1BPPP/R1BQK2R b KQkq - 1 6" }, { "san": "b5", "uci": "b7b5", "fen": "rnbqkb1r/4pppp/p2p1n2/1p6/3NP3/2N5/PPP1BPPP/R1BQK2R w KQkq - 0 7" } ] } ], "finish_reason": "end", "usage": { "input_tokens": 1840, "output_tokens": 96, "cached_tokens": 1152, "grounding_tokens": 1530, "reasoning_tokens": 0 }, "cost_usd": "0.000963" } ``` ## Embed `POST /v1/embed` Turn positions and texts into vectors in one space. Up to 256 items per call, positions and texts mixed in any order, each typed. Vectors compare only within one Embedding model version, so `model` takes a versioned ID and never an alias. One bad item rejects the whole call, with `param` naming it (`input[3].fen`). ### Request body | Field | Type | | Description | |---|---|---|---| | `model` | string | required | A versioned Embedding model ID. There is no alias: vectors compare only within one version. Any other name, Knight and Queen included, is `unknown_model`. | | `input` | array of objects | required | 1 to 256 items, positions and texts mixed in any order. Over 256 is `too_many_inputs`. | | `input[].type` | string | optional | One of `text`. | | `input[].fen` | string | optional | A position in Forsyth–Edwards Notation. | | `input[].pgn` | string | optional | A game in PGN. Only its main line counts; variations and comments are ignored. The main line holds at most 1,000 half-moves, and one request sends at most 256 KB of PGN, each distinct PGN counted once. | | `input[].ply` | integer | optional | Half-moves into the PGN's main line; 0 is the start position. | | `input[].text` | string | optional | On Embed, at most 77 tokens, about 300 characters. On Search, at most 1,000 characters. Never truncated (`text_too_long` on Embed, `query_too_long` on Search). Empty or whitespace-only text is `invalid_field`. | | `encoding_format` | string | optional | `base64` gives each vector's bytes in base64: little-endian float32 numbers, one signed byte per number under `precision` `int8`, or the packed bits under `binary`. One of `float`, `base64`. Default `"float"`. | | `dimensions` | integer | optional | How long each vector is. A shorter vector is the first numbers of the full one, at unit length again: `chessdrive-embed-1` puts the most useful dimensions first, so it costs a little recall for a much smaller file. The price is the same. One of `64`, `128`, `256`, `512`. Default `512`. | | `precision` | string | optional | How each number is stored. `int8` is an integer from -127 to 127, one byte each. `binary` is each number's sign, 1 for zero or above, packed 8 to a byte with the first dimension in the high bit: `dimensions` / 8 integers from 0 to 255. Compare int8 vectors by cosine and binary ones by Hamming distance. The price is the same. One of `float32`, `int8`, `binary`. Default `"float32"`. | ### Response | Field | Type | | Description | |---|---|---|---| | `id` | string | required | Same value as the `request-id` header. | | `model` | string | required | | | `dimensions` | integer | required | Each vector's length in dimensions: the request's `dimensions`, or 512 for `chessdrive-embed-1`. A binary vector holds `dimensions` / 8 bytes. | | `data` | array of objects | required | One vector per item, in request order. A float32 vector is L2-normalised. | | `data[].index` | integer | required | The item's place in `input`. | | `data[].embedding` | array of numbers or string | required | A list of numbers, integers under `precision` `int8` or `binary`, or a base64 string under `encoding_format` `base64`. | | `usage` | object | required | Items by kind, each with its own price; both are always present. | | `usage.positions` | integer | required | | | `usage.texts` | integer | required | | | `cost_usd` | string | required | What this call drew from the Balance, as a decimal string in dollars. | ### Errors - **400**: `invalid_request_error`. Codes: `invalid_json`, `missing_field`, `invalid_field`, `unknown_model`, `invalid_fen`, `invalid_pgn`, `invalid_ply`, `context_too_long` (Generate), `too_many_inputs` and `text_too_long` (Embed), `unknown_engine`, `unknown_network`, `limit_too_high` and `game_over` (Engine). - **401**: `authentication_error`. Codes: `missing_api_key`, `invalid_api_key`, `revoked_api_key`, `expired_api_key`, `disabled_api_key`. - **402**: `billing_error`: the call was refused for money, not speed. Codes: `insufficient_balance` (the Balance is used up, or has never held credits), `spend_limit_reached` (the Account's Spend limit for this month), `key_limit_reached` (this API key's Key limit for its period, with `resets_at`). - **403**: `permission_error`. Codes: `account_suspended`, `key_not_allowed` (the API key is restricted to other APIs, or to another Model on an API that takes `model`; on `GET /v1/balance`, the key is a Team member's; a Study key anywhere but Engine and Generate), and `plan_required` (Queen on the Free plan past its 100 calls in any 7 days, counted per Account; Knight still works). A `plan_required` refusal carries the rate-limit headers, `Retry-After`, and `resets_at`, when the oldest of those calls leaves the 7 days. A Skill falls back to Knight on it; Hobby or Pro lifts it at once. - **413**: `invalid_request_error`. Code: `request_too_large` (the body is over 16 MB, or took over 30 seconds to arrive). - **429**: `rate_limit_error`: slow down; `Retry-After` says how long. The code names the limit: `rate_limited` (requests per minute, Embed items per minute, or requests in flight on Engine and Embed), `daily_limit_reached` (Free's requests per day), `token_rate_limited` (tokens per minute, Generate). - **500**: `api_error`. Code: `internal_error`. - **501**: `api_error`. Code: `coming_soon`: the API, or the `engine` you named (with `param: engine`), is listed but isn't open yet. Refused straight after the key check, so it is never billed and counts toward no rate limit. Its opening is announced in the Changelog. - **503**: `overloaded_error`. Code: `upstream_unavailable`. Retry with backoff. ### Samples ```bash curl curl https://api.chessdrive.io/v1/embed \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "chessdrive-embed-1", "input": [{"type": "position", "fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"}, {"type": "text", "text": "an isolated queen'\''s pawn"}] }' ``` ```python Python import os import requests r = requests.post( "https://api.chessdrive.io/v1/embed", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={ "model": "chessdrive-embed-1", "input": [{"type": "position", "fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"}, {"type": "text", "text": "an isolated queen's pawn"}], }, ) print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/embed", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: "chessdrive-embed-1", input: [{ type: "position", fen: "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1" }, { type: "text", text: "an isolated queen's pawn" }], }), }); console.log(await res.json()); ``` ## Search `POST /v1/search` Every move played from a position, one player's games, or the positions a filter holds for. Search answers from real games, in one of three modes, exactly one a call. `position` gives every move played from it, most played first, with how those games ended: one query, $5 per 1,000. `player` gives that player's games, newest first: $5 per 1,000 games returned, at least one a call, and nothing for a name that could be several players, which answers their `candidates`. `where` takes a Position filter and gives the Positions it holds for, each with how often games reached it, whether it is quiet, and the highest-rated game that reaches it: $5 per 1,000 Positions returned, at least one a call. A filter that is wrong is 400 `invalid_filter`, unbilled, with `param` naming the node at fault; one that runs too long is 503 `upstream_unavailable`, unbilled: narrow it. No answer names where a game came from. Search by similar moments, with `query`, is coming soon: it answers 501 `coming_soon`, unbilled. ### Request body | Field | Type | | Description | |---|---|---|---| | `position` | object | optional | Every move played from this Position in the Games database, most played first. | | `position.fen` | string | optional | A position in Forsyth–Edwards Notation. | | `position.pgn` | string | optional | A game in PGN. Only its main line counts; variations and comments are ignored. The main line holds at most 1,000 half-moves, and one request sends at most 256 KB of PGN, each distinct PGN counted once. | | `position.ply` | integer | optional | Half-moves into the PGN's main line; 0 is the start position. | | `player` | object | optional | The player whose games to find. | | `player.fide_id` | integer | optional | A player on FIDE's list. | | `player.name` | string | optional | A name as FIDE's list writes it, "Carlsen, Magnus", case ignored. A name that could be several players answers their `candidates`. | | `where` | object | optional | A Position filter: a test, true or false for each Position, whose Positions the answer holds. Board expressions give a set of squares: `{"piece": "wN"}` (`w` or `b`, then `P N B R Q K`), `{"attacks": "wB"}` or `{"attacks": "white"}` (own pieces count as attacked), `{"occupied": "white" \| "black" \| "any"}`, `{"squares": ["g8", "h7"]}`, `{"rank": 7}`, `{"file": "a"}`, `and`, `or` and `not`, `{"shift": [X, "N"]}` (one step: N S E W NE NW SE SW), `{"fill": [X, "N"]}` (1 to 7 steps), and `{"flip": X}` (colours swapped, ranks mirrored). Tests: `{"any": X}`, `{"none": X}`, `{"count": X, "gte" \| "lte" \| "eq": n}`, `{"to_move": "white" \| "black"}`, `{"castling": "K" \| "Q" \| "k" \| "q"}`, `{"en_passant": true}` or `{"en_passant": X}`, `all`, `some`, `not` and `flip`, and `{"ref": name}` for a part named in `define`. Each node is one key. A wrong filter is `invalid_filter`, with `param` at the node; past 2,000 nodes or 64 levels once refs are replaced, it is too big. | | `define` | object | optional | With `where`: named parts of the filter, each a board expression or a test, used as `{"ref": name}`. A part may use others, never itself. | | `limit` | integer | optional | With `player`, how many games at most (default 50); with `where`, how many Positions (default 20). `limit_too_high` past 200. | | `cursor` | string | optional | With `player` or `where`: the last answer's `next_cursor`, for the next page, sent with the same `player` and `filters`, or the same `where` and `define`. Opaque. A cursor from before the games were rebuilt is `cursor_expired`. | | `pgn` | boolean | optional | With `player`: each game carries its PGN. Default `false`. | | `filters` | object | optional | All optional, combined with AND. `date`, `eco` and `result` mean the same in both modes. `rating`, `speed` and `player` are for a query (coming soon, and not promised), and `color` and `opponent` for a player's games; sent in the other mode, or with `position`, they are `invalid_field`. | | `filters.date` | object | optional | When the game was played, by month, both ends included. | | `filters.eco` | array of strings | optional | ECO codes or prefixes (`B90`, `C4`, `E`). | | `filters.result` | array of strings | optional | The game's result, from White's side as PGN writes it. | | `filters.color` | string | optional | The side the player had. One of `white`, `black`. | | `filters.opponent` | object | optional | The other side, by FIDE ID. | ### Response | Field | Type | | Description | |---|---|---|---| | `id` | string | optional | Same value as the `request-id` header. | | `fen` | string | optional | A position in Forsyth–Edwards Notation. | | `moves` | array of objects | optional | Empty when no stored game reaches the Position. | | `moves[].uci` | string | required | | | `moves[].san` | string | required | | | `moves[].count` | integer | required | How many games played it. | | `moves[].white_wins` | integer | required | | | `moves[].draws` | integer | required | | | `moves[].black_wins` | integer | required | | | `usage` | object | optional | | | `usage.queries` | integer | optional | Always 1. | | `usage.games` | integer | optional | The true count. The bill counts at least one game, except on an ambiguous name, which is free. | | `usage.positions` | integer | optional | The true count. The bill counts at least one Position. | | `cost_usd` | string | optional | What this call drew from the Balance, as a decimal string in dollars. | | `match` | string | optional | `fide`: one player on FIDE's list, with their games. `ambiguous`: a name that could be several, in `candidates`, with no games and nothing billed. One of `fide`, `ambiguous`. | | `player` | object or null | optional | Null on an ambiguous name. | | `player.fide_id` | integer | optional | | | `player.name` | string | optional | | | `player.federation` | string or null | optional | | | `player.title` | string or null | optional | | | `player.ratings` | object | optional | The player's ratings on FIDE's list, null when they have none. | | `player.birth_year` | integer or null | optional | | | `candidates` | array of objects | optional | On an ambiguous name, the players it could be. Call again with one's `fide_id`. Empty otherwise. | | `candidates[].fide_id` | integer | required | | | `candidates[].name` | string | required | | | `candidates[].federation` | string or null | required | | | `candidates[].title` | string or null | required | | | `candidates[].ratings` | object | required | The player's ratings on FIDE's list, null when they have none. | | `games` | array of objects | optional | Newest first. | | `games[].color` | string | required | The side the player had. One of `white`, `black`. | | `games[].game` | object | required | One game, the same in a Moment and among a player's games. | | `next_cursor` | string or null | optional | Send as `cursor`, with the same `where` and `define`, for the next page. Null on the last page. It expires when the games are rebuilt. | | `positions` | array of objects | optional | Empty when the filter holds for no stored Position. | | `positions[].fen` | string | required | A position in Forsyth–Edwards Notation. | | `positions[].occurrences` | integer | required | How many times the games reach it. | | `positions[].quiet` | boolean | required | The side to move is out of check and has no capture or promotion that wins material. | | `positions[].examples` | array of objects | required | The highest-rated game that reaches it, without its moves. | ### Errors - **400**: `invalid_request_error`. Codes: `invalid_json`, `missing_field`, `invalid_field`, `unknown_model`, `invalid_fen`, `invalid_pgn`, `invalid_ply`, `context_too_long` (Generate), `too_many_inputs` and `text_too_long` (Embed), `unknown_engine`, `unknown_network`, `limit_too_high` and `game_over` (Engine). - **401**: `authentication_error`. Codes: `missing_api_key`, `invalid_api_key`, `revoked_api_key`, `expired_api_key`, `disabled_api_key`. - **402**: `billing_error`: the call was refused for money, not speed. Codes: `insufficient_balance` (the Balance is used up, or has never held credits), `spend_limit_reached` (the Account's Spend limit for this month), `key_limit_reached` (this API key's Key limit for its period, with `resets_at`). - **403**: `permission_error`. Codes: `account_suspended`, `key_not_allowed` (the API key is restricted to other APIs, or to another Model on an API that takes `model`; on `GET /v1/balance`, the key is a Team member's; a Study key anywhere but Engine and Generate), and `plan_required` (Queen on the Free plan past its 100 calls in any 7 days, counted per Account; Knight still works). A `plan_required` refusal carries the rate-limit headers, `Retry-After`, and `resets_at`, when the oldest of those calls leaves the 7 days. A Skill falls back to Knight on it; Hobby or Pro lifts it at once. - **413**: `invalid_request_error`. Code: `request_too_large` (the body is over 16 MB, or took over 30 seconds to arrive). - **429**: `rate_limit_error`: slow down; `Retry-After` says how long. The code names the limit: `rate_limited` (requests per minute, Embed items per minute, or requests in flight on Engine and Embed), `daily_limit_reached` (Free's requests per day), `token_rate_limited` (tokens per minute, Generate). - **500**: `api_error`. Code: `internal_error`. - **501**: `api_error`. Code: `coming_soon`: the API, or the `engine` you named (with `param: engine`), is listed but isn't open yet. Refused straight after the key check, so it is never billed and counts toward no rate limit. Its opening is announced in the Changelog. - **503**: `overloaded_error`. Code: `upstream_unavailable`. Retry with backoff. ### Samples ```bash curl curl https://api.chessdrive.io/v1/search \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "position": {"fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"} }' ``` ```python Python import os import requests r = requests.post( "https://api.chessdrive.io/v1/search", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={ "position": {"fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"}, }, ) print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/search", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ position: { fen: "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1" }, }), }); console.log(await res.json()); ``` ## Engine `POST /v1/engine` Analyse a position, a list of positions or a whole game, with Stockfish. At most one limit (`depth`, `nodes` or `movetime_ms`) under the engine's cap, or the engine's default. Every call also stops at a 60 s wall-clock cap and returns the deepest completed result. Scores are from White's point of view. Engine takes no `model`; billing is by Engine time, at least 100 ms a call. With `stream: true` the response is Server-Sent Events, one per completed depth (see `EngineStreamEvent`). **A whole game:** a `position` that is a `pgn` with no `ply` runs Engine on every position of the PGN's main line and answers with an `EngineGameResponse`, one entry per move. The limit applies to each position, and the default is `depth` 14 rather than 20. The whole game shares the one 60 s budget: a `movetime_ms` that can't fit is refused up front, and a game that runs past it fails with `limit_too_high` and is not billed. It is billed by the Engine time of all its positions together, at least 100 ms. A whole game takes no `lines` (each move gets Engine's best Line) and no `stream`. **A list of positions:** `positions`, instead of `position`, takes up to 100 and answers with an `EngineBatchResponse`, one result per position in order. It counts as one request and one in flight. The limit and `lines` apply to each position, the default is `depth` 14 rather than 20, and each Line is cut to its first 8 half-moves. The positions run one after another inside the one 60 s budget. A position Engine can't take refuses the whole call, naming it, and nothing is billed. A finished game comes back as `game_over` and doesn't stop the others. At the budget, or when the engine fails part way, the call still answers 200: what finished is billed, and the rest comes back as `not_run`, unbilled, to send again. If nothing finished, it is the usual error, unbilled. Billing is the Engine time of all its positions together, at least 100 ms. A list takes no `stream`. **A burst:** a call over the Plan's requests in flight waits up to 5 s for one to finish before it answers `429 rate_limited`. ### Request body | Field | Type | | Description | |---|---|---|---| | `engine` | string | required | Any other name is `unknown_engine`. One of `stockfish`, `lc0`. | | `position` | object | optional | A position, as the other APIs take it (a FEN, or a PGN plus `ply`), or a whole game: a PGN with no `ply` runs Engine on every position of its main line. | | `position.fen` | string | optional | A position in Forsyth–Edwards Notation. | | `position.pgn` | string | optional | A game in PGN. Only its main line counts; variations and comments are ignored. The main line holds at most 1,000 half-moves, and one request sends at most 256 KB of PGN, each distinct PGN counted once. | | `position.ply` | integer | optional | Half-moves into the PGN's main line; 0 is the start position. | | `positions` | array of objects | optional | 1 to 100 positions to analyse in one call, instead of `position`. Over 100 is `too_many_inputs`. | | `positions[].fen` | string | optional | A position in Forsyth–Edwards Notation. | | `positions[].pgn` | string | optional | A game in PGN. Only its main line counts; variations and comments are ignored. The main line holds at most 1,000 half-moves, and one request sends at most 256 KB of PGN, each distinct PGN counted once. | | `positions[].ply` | integer | optional | Half-moves into the PGN's main line; 0 is the start position. | | `depth` | integer | optional | Stockfish only (`invalid_field` on Lc0). Stockfish's default is `depth` 20 on a position and 14 on each position of a whole game or a list. On a whole game leave it out: at `depth` 20 a game of 25 moves or more passes the 60 s a call has and fails as `limit_too_high`. | | `nodes` | integer | optional | At most 1,000,000,000 on Stockfish and 2,000,000 visits on Lc0, whose default is `nodes` 10,000. | | `movetime_ms` | integer | optional | | | `lines` | integer | optional | How many ranked Lines to return. A whole game takes only 1. Default `1`. | | `network` | string | optional | Lc0's network: `bt4` (the default), `t82` or `t1-256`. Only Lc0 takes one; on Stockfish it is `invalid_field`. One of `bt4`, `t82`, `t1-256`. | | `stream` | boolean | optional | Not on a whole game or a list of positions. Default `false`. | ### Response | Field | Type | | Description | |---|---|---|---| | `id` | string | optional | Same value as the `request-id` header. | | `engine` | string | optional | Stockfish, or Lc0, which is coming soon; a call naming `lc0` returns 501 `coming_soon`. One of `stockfish`, `lc0`. | | `version` | string | optional | | | `network` | string or null | optional | The Network Lc0 ran; null on Stockfish. | | `fen` | string | optional | A position in Forsyth–Edwards Notation. | | `depth` | integer | optional | | | `seldepth` | integer | optional | | | `nodes` | integer | optional | | | `time_ms` | integer | optional | | | `best_move` | object | optional | | | `best_move.san` | string | required | | | `best_move.uci` | string | required | | | `lines` | array of objects | optional | | | `lines[].rank` | integer | required | | | `lines[].depth` | integer | required | | | `lines[].cp` | integer or null | required | Centipawns. | | `lines[].mate` | integer or null | required | Moves to mate; positive means White mates. | | `lines[].wdl` | object | required | Win, draw and loss chances for White, per mille. | | `lines[].moves` | array of objects | required | | | `stop_reason` | string | optional | `limit` when the requested limit was reached, `time_cap` when the time cap stopped it. One of `limit`, `time_cap`. | | `usage` | object | optional | Engine time, the engine's own search time on every `ok` position together. The bill counts at least 100 ms. | | `usage.engine_ms` | integer | optional | | | `cost_usd` | string | optional | What this call drew from the Balance, as a decimal string in dollars. | | `moves` | array of objects | optional | | | `moves[].ply` | integer | required | The position the move was played from, as `{pgn, ply}` names it: 0 for White's first move. Send it as the `position` of a Generate call to talk about this move. | | `moves[].move_number` | integer | required | The move's number, as a PGN writes it. | | `moves[].color` | string | required | One of `white`, `black`. | | `moves[].move` | object | required | | | `moves[].fen` | string | required | A position in Forsyth–Edwards Notation. | | `moves[].eval_before` | object | required | A position's evaluation from White's point of view. Exactly one of `cp` and `mate` is set; `mate` 0 is a checkmate on the board, and `wdl` says who won. | | `moves[].eval_after` | object | required | A position's evaluation from White's point of view. Exactly one of `cp` and `mate` is set; `mate` 0 is a checkmate on the board, and `wdl` says who won. | | `moves[].win_chance_lost` | number | required | The win chance the move lost for the side that played it, on Lichess's scale from -1 to +1: `2 / (1 + exp(-0.00368208 × cp)) - 1`, and ±1 for a mate. 0 when it lost none. | | `moves[].verdict` | string | required | How good the move was, by the win chance it lost for the side that played it, the way Lichess judges: `best` is Engine's own best move; otherwise 0.3 or more lost is a `blunder`, 0.2 a `mistake`, 0.1 an `inaccuracy`, and less is `good`. One of `best`, `good`, `inaccuracy`, `mistake`, `blunder`. | | `moves[].best_line` | array of objects | required | Engine's best Line from `fen`, its first 8 half-moves at most; `eval_before` is its score. For the whole Line or more Lines, call Engine on `{pgn, ply}`. | | `results` | array of objects | optional | | | `results[].status` | string | required | One of `ok`, `game_over`, `not_run`. | | `results[].fen` | string | required | A position in Forsyth–Edwards Notation. | | `results[].depth` | integer | optional | | | `results[].seldepth` | integer | optional | | | `results[].nodes` | integer | optional | | | `results[].time_ms` | integer | optional | | | `results[].stop_reason` | string | optional | `limit` when the requested limit was reached, `time_cap` when the time cap stopped it. One of `limit`, `time_cap`. | | `results[].best_move` | object | optional | | | `results[].lines` | array of objects | optional | The ranked Lines, each its first 8 half-moves at most. | ### Errors - **400**: `invalid_request_error`. Codes: `invalid_json`, `missing_field`, `invalid_field`, `unknown_model`, `invalid_fen`, `invalid_pgn`, `invalid_ply`, `context_too_long` (Generate), `too_many_inputs` and `text_too_long` (Embed), `unknown_engine`, `unknown_network`, `limit_too_high` and `game_over` (Engine). - **401**: `authentication_error`. Codes: `missing_api_key`, `invalid_api_key`, `revoked_api_key`, `expired_api_key`, `disabled_api_key`. - **402**: `billing_error`: the call was refused for money, not speed. Codes: `insufficient_balance` (the Balance is used up, or has never held credits), `spend_limit_reached` (the Account's Spend limit for this month), `key_limit_reached` (this API key's Key limit for its period, with `resets_at`). - **403**: `permission_error`. Codes: `account_suspended`, `key_not_allowed` (the API key is restricted to other APIs, or to another Model on an API that takes `model`; on `GET /v1/balance`, the key is a Team member's; a Study key anywhere but Engine and Generate), and `plan_required` (Queen on the Free plan past its 100 calls in any 7 days, counted per Account; Knight still works). A `plan_required` refusal carries the rate-limit headers, `Retry-After`, and `resets_at`, when the oldest of those calls leaves the 7 days. A Skill falls back to Knight on it; Hobby or Pro lifts it at once. - **413**: `invalid_request_error`. Code: `request_too_large` (the body is over 16 MB, or took over 30 seconds to arrive). - **429**: `rate_limit_error`: slow down; `Retry-After` says how long. The code names the limit: `rate_limited` (requests per minute, Embed items per minute, or requests in flight on Engine and Embed), `daily_limit_reached` (Free's requests per day), `token_rate_limited` (tokens per minute, Generate). - **500**: `api_error`. Code: `internal_error`. - **501**: `api_error`. Code: `coming_soon`: the API, or the `engine` you named (with `param: engine`), is listed but isn't open yet. Refused straight after the key check, so it is never billed and counts toward no rate limit. Its opening is announced in the Changelog. - **503**: `overloaded_error`. Code: `upstream_unavailable`. Retry with backoff. ### Samples ```bash curl curl https://api.chessdrive.io/v1/engine \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "engine": "stockfish", "position": {"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"}, "depth": 30, "lines": 2 }' ``` ```python Python import os import requests r = requests.post( "https://api.chessdrive.io/v1/engine", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={ "engine": "stockfish", "position": {"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"}, "depth": 30, "lines": 2, }, ) print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/engine", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ engine: "stockfish", position: { fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" }, depth: 30, lines: 2, }), }); console.log(await res.json()); ``` ```json Response { "id": "req_01J9Z6Q8F3", "engine": "stockfish", "version": "Stockfish 19", "network": null, "fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "depth": 30, "seldepth": 41, "nodes": 18200000, "time_ms": 7400, "stop_reason": "limit", "best_move": { "san": "e4", "uci": "e2e4" }, "lines": [ { "rank": 1, "depth": 30, "cp": 34, "mate": null, "wdl": { "win": 312, "draw": 620, "loss": 68 }, "moves": [ { "san": "e4", "uci": "e2e4" }, { "san": "e5", "uci": "e7e5" } ] }, { "rank": 2, "depth": 30, "cp": 28, "mate": null, "wdl": { "win": 290, "draw": 640, "loss": 70 }, "moves": [ { "san": "d4", "uci": "d2d4" }, { "san": "Nf6", "uci": "g8f6" } ] } ], "usage": { "engine_ms": 7400 }, "cost_usd": "0.009250" } ``` ## Models `GET /v1/models` (public, no API key) List the Models, their IDs, aliases, limits and the APIs they serve. Public; no API key needed, so the Site and Docs read it too. ### Response | Field | Type | | Description | |---|---|---|---| | `data` | array of objects | required | | | `data[].id` | string | required | | | `data[].aliases` | array of strings | required | Empty for the Embedding model, which has none. | | `data[].name` | string | required | The public name, e.g. Knight. | | `data[].apis` | array of strings | required | The APIs that take this Model as `model`. | | `data[].context_window` | integer or null | required | Tokens, on Generate; over it is 400 `context_too_long`. Null for the Embedding model. | | `data[].embed_dimensions` | integer or null | required | Each vector's length, on Embed. Null otherwise. | | `data[].downloadable` | boolean | required | | | `data[].status` | string | required | `coming_soon` for a Model that is listed but isn't open yet: a call naming it returns 501 `coming_soon`. One of `available`, `coming_soon`. | ### Samples ```bash curl curl https://api.chessdrive.io/v1/models ``` ```python Python import requests r = requests.get("https://api.chessdrive.io/v1/models") print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/models"); console.log(await res.json()); ``` ```json Response { "data": [ { "id": "knight-1", "aliases": [ "knight" ], "name": "Knight", "apis": [ "generate" ], "context_window": 32768, "embed_dimensions": null, "downloadable": true, "status": "available" }, { "id": "queen-1", "aliases": [ "queen" ], "name": "Queen", "apis": [ "generate" ], "context_window": 131072, "embed_dimensions": null, "downloadable": false, "status": "available" }, { "id": "chessdrive-embed-1", "aliases": [], "name": "ChessDrive Embed", "apis": [ "embed" ], "context_window": null, "embed_dimensions": 512, "downloadable": false, "status": "available" } ] } ``` ## Usage `GET /v1/usage` Your requests and what they cost, per UTC day, by API, Model or API key. The numbers the Dashboard's Usage page shows for the same range and grouping. An Admin's or an Individual's key sees the whole Account; a Team member's key sees what its creator sees there: the calls of the keys they created, and their own Playground calls. The Dashboard's Playground calls are a series of their own, `playground`, last. Free: never refused for money (no 402), nothing drawn from the Balance and no row in the Request log, so you can check why calls fail. A key restricted to other APIs or Models may call it. Its rate limit is its own, 60 requests a minute per Account, shared with `GET /v1/balance`. ### Query parameters | Parameter | Type | | Description | |---|---|---|---| | `from` | string | required | The first UTC day, `YYYY-MM-DD`. | | `to` | string | required | The last UTC day, included, at most 365 days after `from`. | | `group_by` | string | optional | What each series is. `api`: one series per API. `model`: one per Model of Generate and Embed, with `""` (`No Model`) for the calls that name none: Search's, Engine's, and those refused before their Model was known. `key`: one per API key, revoked ones included. One of `api`, `model`, `key`. Default `"api"`. | ### Response | Field | Type | | Description | |---|---|---|---| | `from` | string | required | | | `to` | string | required | | | `group_by` | string | required | `api`: one series per API. `model`: one per Model of Generate and Embed, with `""` (`No Model`) for the calls that name none: Search's, Engine's, and those refused before their Model was known. `key`: one per API key, revoked ones included. One of `api`, `model`, `key`. Default `"api"`. | | `days` | array of strings | required | Every UTC day from `from` to `to`, in order. | | `series` | array of objects | required | One per API, Model or key with calls in the range, none for those without: APIs in this contract's order, Models in `GET /v1/models`'s order (then any no longer served, then `""`), keys oldest first, and the Playground last. | | `series[].id` | string | required | The API (`generate`), the Model ID (`knight-1`, or `""`), the API key's id, or `playground` for the Dashboard's Playground calls. | | `series[].name` | string | required | The Model's or the key's name, `No Model` or `Playground`; for an API, its id. | | `series[].requests` | array of integers | required | The calls each day, failed ones included, in the order of `days`. | | `series[].cost_usd` | array of strings | required | What the calls drew from the Balance each day, in the order of `days`. Only successes cost anything. | | `errors` | array of integers | required | The calls that failed each day, across every series, in the order of `days`. | | `total` | object | required | Every series over the whole range. | | `total.requests` | integer | required | | | `total.cost_usd` | string | required | An amount in dollars, as a decimal string to six places, like `cost_usd`. | ### Errors - **400**: `invalid_request_error`. Code: `invalid_field`, with `param` naming the query parameter at fault (`from`, `to` or `group_by`). - **401**: `authentication_error`. Codes: `missing_api_key`, `invalid_api_key`, `revoked_api_key`, `expired_api_key`, `disabled_api_key`. - **403**: `permission_error`. Codes: `account_suspended`, `key_not_allowed` (the API key is restricted to other APIs, or to another Model on an API that takes `model`; on `GET /v1/balance`, the key is a Team member's; a Study key anywhere but Engine and Generate), and `plan_required` (Queen on the Free plan past its 100 calls in any 7 days, counted per Account; Knight still works). A `plan_required` refusal carries the rate-limit headers, `Retry-After`, and `resets_at`, when the oldest of those calls leaves the 7 days. A Skill falls back to Knight on it; Hobby or Pro lifts it at once. - **429**: `rate_limit_error`: slow down; `Retry-After` says how long. The code names the limit: `rate_limited` (requests per minute, Embed items per minute, or requests in flight on Engine and Embed), `daily_limit_reached` (Free's requests per day), `token_rate_limited` (tokens per minute, Generate). - **500**: `api_error`. Code: `internal_error`. ### Samples ```bash curl curl "https://api.chessdrive.io/v1/usage?from=2026-10-01&to=2026-10-03&group_by=model" \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" ``` ```python Python import os import requests r = requests.get( "https://api.chessdrive.io/v1/usage", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, params={"from": "2026-10-01", "to": "2026-10-03", "group_by": "model"}, ) print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/usage?from=2026-10-01&to=2026-10-03&group_by=model", { headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}` }, }); console.log(await res.json()); ``` ```json Response { "from": "2026-10-01", "to": "2026-10-03", "group_by": "model", "days": [ "2026-10-01", "2026-10-02", "2026-10-03" ], "series": [ { "id": "knight-1", "name": "Knight", "requests": [ 120, 85, 0 ], "cost_usd": [ "0.014400", "0.010200", "0.000000" ] }, { "id": "playground", "name": "Playground", "requests": [ 0, 3, 1 ], "cost_usd": [ "0.000000", "0.000360", "0.000120" ] } ], "errors": [ 2, 0, 0 ], "total": { "requests": 209, "cost_usd": "0.025080" } } ``` ## Balance `GET /v1/balance` Your Account's Plan, Balance, Monthly credit, Trial credits left, this month's spend and Spend limit. The money the Dashboard's Billing page shows, for an Admin's or an Individual's key. A Team member's key is refused with 403 `key_not_allowed`, as Team members see none of an Organization's billing; `GET /v1/usage` still shows them their own keys' spend. Free: never refused for money (no 402), nothing drawn from the Balance and no row in the Request log. A key restricted to other APIs or Models may call it. Its rate limit is its own, 60 requests a minute per Account, shared with `GET /v1/usage`. To top up or change the Spend limit, use the Dashboard. ### Response | Field | Type | | Description | |---|---|---|---| | `plan` | string | required | The Account's Plan, which sets its rate limits. Every Account starts on `free`; a Top-up never changes it. On `free`, Queen takes 100 calls in any 7 days, then answers 403 `plan_required`. One of `free`, `hobby`, `pro`. | | `balance_usd` | string | required | What is left to spend on calls, Monthly credit and Promo credits included. At 0 or below, calls are refused with 402 `insufficient_balance`; a call already running may take it a little below 0. | | `monthly_credit_usd` | string | required | The Monthly credit left from the paid Plan's current month, part of `balance_usd` and spent before any other dollars. `0.000000` on Free. | | `monthly_credit_expires_at` | string or null | required | When the Monthly credit left expires, at the end of the Plan's month. Null when none is left. | | `trial_credits_usd` | string | required | The Trial credits left, part of `balance_usd`. They are spent after Monthly credit and expiring Promo credits, and before Top-ups. | | `trial_credits_expire_at` | string or null | required | When the Trial credits left expire. Null when none are left, or when they never expire, as Trial credits given today don't. | | `month_spend_usd` | string | required | The spend this calendar month in UTC, which the Spend limit counts against. | | `spend_limit_usd` | string or null | required | The Spend limit for each calendar month, in dollars like `cost_usd`; once `month_spend_usd` reaches it, calls are refused with 402 `spend_limit_reached`. Null when the Account has none. | ### Errors - **401**: `authentication_error`. Codes: `missing_api_key`, `invalid_api_key`, `revoked_api_key`, `expired_api_key`, `disabled_api_key`. - **403**: `permission_error`. Codes: `account_suspended`, `key_not_allowed` (the API key is restricted to other APIs, or to another Model on an API that takes `model`; on `GET /v1/balance`, the key is a Team member's; a Study key anywhere but Engine and Generate), and `plan_required` (Queen on the Free plan past its 100 calls in any 7 days, counted per Account; Knight still works). A `plan_required` refusal carries the rate-limit headers, `Retry-After`, and `resets_at`, when the oldest of those calls leaves the 7 days. A Skill falls back to Knight on it; Hobby or Pro lifts it at once. - **429**: `rate_limit_error`: slow down; `Retry-After` says how long. The code names the limit: `rate_limited` (requests per minute, Embed items per minute, or requests in flight on Engine and Embed), `daily_limit_reached` (Free's requests per day), `token_rate_limited` (tokens per minute, Generate). - **500**: `api_error`. Code: `internal_error`. ### Samples ```bash curl curl https://api.chessdrive.io/v1/balance \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" ``` ```python Python import os import requests r = requests.get( "https://api.chessdrive.io/v1/balance", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, ) print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/balance", { headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}` }, }); console.log(await res.json()); ``` ```json Response { "plan": "free", "balance_usd": "9.213500", "monthly_credit_usd": "0.000000", "monthly_credit_expires_at": null, "trial_credits_usd": "9.213500", "trial_credits_expire_at": null, "month_spend_usd": "0.786500", "spend_limit_usd": null } ``` ## Study keys `POST /v1/study_keys` Make a Study key, for one Study page to call Engine and Generate. A Study is a page a person's agent builds for them with the Study Skill. Its Study key lets the page call `POST /v1/engine` and `POST /v1/generate` from the browser when the person asks: the key can call only those two, with a Key limit of $1 a UTC day, and expires 7 days after it was made. Each is its own key, listed under Study keys on the Dashboard's API keys page, where it can be revoked. The page holds the key, so anyone who opens the page can spend it, up to its limit. Engine and Generate answer a browser from any origin, a page opened as a local file included, with the CORS headers, and so does `GET /v1/models`, which a page can read first, free and with no key, to learn whether it can reach the API. A Study key takes the Model restriction of the key that made it, and is refused when that key can't call both Engine and Generate. It is never refused for money (no 402), and its own calls are billed to the same Account. A Study key can't make another, read the Usage API or sign in to the Connector: each answers 403 `key_not_allowed`. Its rate limit is the Usage API's, 60 requests a minute per Account. ### Request body | Field | Type | | Description | |---|---|---|---| | `name` | string | required | The Study's name, as its title says, which the Dashboard lists the key by. | | `url` | string or null | optional | The Study's `https` link, such as a Claude artifact's, which the Dashboard links to. Leave it out for a local file, which the Dashboard can't open. | ### Errors - **400**: `invalid_request_error`. Codes: `invalid_json`, `missing_field`, `invalid_field`, `unknown_model`, `invalid_fen`, `invalid_pgn`, `invalid_ply`, `context_too_long` (Generate), `too_many_inputs` and `text_too_long` (Embed), `unknown_engine`, `unknown_network`, `limit_too_high` and `game_over` (Engine). - **401**: `authentication_error`. Codes: `missing_api_key`, `invalid_api_key`, `revoked_api_key`, `expired_api_key`, `disabled_api_key`. - **403**: `permission_error`. Codes: `account_suspended`, `key_not_allowed` (the API key is restricted to other APIs, or to another Model on an API that takes `model`; on `GET /v1/balance`, the key is a Team member's; a Study key anywhere but Engine and Generate), and `plan_required` (Queen on the Free plan past its 100 calls in any 7 days, counted per Account; Knight still works). A `plan_required` refusal carries the rate-limit headers, `Retry-After`, and `resets_at`, when the oldest of those calls leaves the 7 days. A Skill falls back to Knight on it; Hobby or Pro lifts it at once. - **429**: `rate_limit_error`: slow down; `Retry-After` says how long. The code names the limit: `rate_limited` (requests per minute, Embed items per minute, or requests in flight on Engine and Embed), `daily_limit_reached` (Free's requests per day), `token_rate_limited` (tokens per minute, Generate). - **500**: `api_error`. Code: `internal_error`. ### Samples ```bash curl curl https://api.chessdrive.io/v1/study_keys \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Your game against Ana", "url": "https://claude.ai/public/artifacts/0b6c1f0e-2a51-4d37-9a5e-7d3f8a9c2e11" }' ``` ```python Python import os import requests r = requests.post( "https://api.chessdrive.io/v1/study_keys", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={ "name": "Your game against Ana", "url": "https://claude.ai/public/artifacts/0b6c1f0e-2a51-4d37-9a5e-7d3f8a9c2e11", }, ) print(r.json()) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/study_keys", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ name: "Your game against Ana", url: "https://claude.ai/public/artifacts/0b6c1f0e-2a51-4d37-9a5e-7d3f8a9c2e11", }), }); console.log(await res.json()); ```