# Search Every move played from a position, one player's games, and the positions a filter holds for, from over two million games. Search by similar moments is coming soon. `POST /v1/search` answers from the Games database: over two million games, up to October 2025. It has three modes today: - **`position`**: every move played from a position, most played first, with how those games ended. One query, $5 per 1,000. - **`player`**: one player's games, newest first, by FIDE ID or name. $5 per 1,000 games. - **`where`**: the positions a Position filter holds for, such as every rook ending with White to move. $5 per 1,000 positions. A body takes exactly one mode. Sending none is `missing_field`, and two is `invalid_field`. Search takes no `model`, and no answer says where a game came from. Read the [known gaps](#known-gaps) before you build on it. ## 1. Get a position's moves `position` is a position as every API takes it: a `fen`, or a `pgn` and a `ply`. This one is the position after 1. e4. ```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"}}, ) r.raise_for_status() for m in r.json()["moves"]: print(m["san"], m["count"], m["white_wins"], m["draws"], m["black_wins"]) ``` ```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" } }), }); if (!res.ok) throw new Error(await res.text()); for (const m of (await res.json()).moves) console.log(m.san, m.count, m.white_wins, m.draws, m.black_wins); ``` ## 2. Read the moves The counts in this example are made up. - `fen`: the position you sent. - `moves`: every move played from it, most played first. Each has its `san` and `uci`, the `count` of games that played it, and how those games ended: `white_wins`, `draws` and `black_wins`. - A position no game in the Games database reaches answers `moves: []`, and is still billed. - `usage.queries` is always 1. `cost_usd` is what the call drew from your Balance. ```json Response { "id": "req_01M4G1J5W0HB8Z4TQ6CN3KRY7D", "fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1", "moves": [ { "uci": "c7c5", "san": "c5", "count": 4120, "white_wins": 1480, "draws": 1530, "black_wins": 1110 }, { "uci": "e7e5", "san": "e5", "count": 3210, "white_wins": 1190, "draws": 1290, "black_wins": 730 }, { "uci": "e7e6", "san": "e6", "count": 1050, "white_wins": 390, "draws": 410, "black_wins": 250 }, { "uci": "c7c6", "san": "c6", "count": 840, "white_wins": 300, "draws": 350, "black_wins": 190 } ], "usage": { "queries": 1 }, "cost_usd": "0.005000" } ``` ## 3. Get a player's games `player` says who: a `fide_id`, or a `name`, never both. `fide_id` is the surest: 1503014 is Magnus Carlsen. `limit` is how many games you want, 50 by default and at most 200. ```bash curl curl https://api.chessdrive.io/v1/search \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "player": { "fide_id": 1503014 }, "limit": 2 }' ``` ```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={"player": {"fide_id": 1503014}, "limit": 2}, ) r.raise_for_status() for item in r.json()["games"]: game = item["game"] print(game["date"], item["color"], game["white"]["name"], game["result"], game["black"]["name"]) ``` ```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({ player: { fide_id: 1503014 }, limit: 2 }), }); if (!res.ok) throw new Error(await res.text()); for (const { color, game } of (await res.json()).games) { console.log(game.date, color, game.white.name, game.result, game.black.name); } ``` ## 4. Read the answer The player and games in this example are made up. - `match`: `fide` for one player on FIDE's list, `ambiguous` for a name that could be several. - `player`: their FIDE ID, name, federation, title, ratings and birth year, as FIDE's list has them. - `games`: newest first, each with the `color` the player had and the `game`: its players with their rating and FIDE ID, event, date, ECO code and result. What we don't know is null, never a guess. - `next_cursor`: send it as `cursor` for the next page. Null on the last page. - `usage.games`: the true count of games returned. `cost_usd` is what the call drew from your Balance, at least one game. ```json Response { "id": "req_01M4G1J5W0HB8Z4TQ6CN3KRY7D", "match": "fide", "player": { "fide_id": 99000001, "name": "Fixture, Ada", "federation": "ENG", "title": "IM", "ratings": { "standard": 2412, "rapid": 2388, "blitz": 2401 }, "birth_year": 1999 }, "candidates": [], "games": [ { "color": "white", "game": { "id": "1006", "url": null, "white": { "name": "Fixture, Ada", "rating": 2412, "title": null, "fide_id": 99000001 }, "black": { "name": "Fixture, Bo", "rating": 2305, "title": null, "fide_id": 99000002 }, "event": "Fixture Open 2025", "date": "2025-09-12", "speed": null, "speed_basis": null, "time_control": null, "eco": "C65", "opening": null, "result": "1-0", "venue": null, "platform": null, "rated": null, "pgn": null } }, { "color": "black", "game": { "id": "1005", "url": null, "white": { "name": "Fixture, Bo", "rating": 2305, "title": null, "fide_id": 99000002 }, "black": { "name": "Fixture, Ada", "rating": 2412, "title": null, "fide_id": 99000001 }, "event": "Fixture Open 2025", "date": null, "speed": null, "speed_basis": null, "time_control": null, "eco": "B12", "opening": null, "result": "1/2-1/2", "venue": null, "platform": null, "rated": null, "pgn": null } } ], "next_cursor": "g1.eyJjIjoiMTAwNSJ9", "usage": { "games": 2 }, "cost_usd": "0.010000" } ``` ## 5. Say who you mean | Send | Finds | |---|---| | `fide_id` | Anyone on FIDE's list. One who isn't is `unknown_player`. | | `name` | A name as FIDE's list writes it, `"Carlsen, Magnus"`, case ignored. A name that matches nobody is `unknown_player`. | A name that could be several players isn't an error: `match` is `ambiguous`, `games` is empty, and `candidates` holds up to 5 players, each with their FIDE ID, name, federation, title and ratings. The call is free. Ask which one is meant, then call again with their `fide_id`. ```json Response { "id": "req_01M4G1J5W0HB8Z4TQ6CN3KRY7E", "match": "ambiguous", "player": null, "candidates": [ { "fide_id": 99000001, "name": "Fixture, Ada", "federation": "ENG", "title": "IM", "ratings": { "standard": 2412, "rapid": 2388, "blitz": 2401 } }, { "fide_id": 99000002, "name": "Fixture, Bo", "federation": "SCO", "title": "FM", "ratings": { "standard": 2305, "rapid": 2290, "blitz": 2298 } } ], "games": [], "next_cursor": null, "usage": { "games": 0 }, "cost_usd": "0.000000" } ``` ## 6. Filter the games `filters` narrows the games. Every filter is optional, and the ones you send must all match. | Filter | Shape | Matches | |---|---|---| | `date` | `from`, `to`, each `YYYY-MM` | Games played in those months, both included. | | `eco` | A list of ECO codes or prefixes, like `B90`, `C4` or `E` | Any of them. | | `result` | A list of `1-0`, `0-1`, `1/2-1/2` | Any of them, from White's side as PGN writes it. | | `color` | `white` or `black` | The side the player had. | | `opponent` | `fide_id` | Games against that player. | Any other filter is `invalid_field`. ```bash curl curl https://api.chessdrive.io/v1/search \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "player": { "fide_id": 1503014 }, "filters": { "color": "white", "eco": ["C6"], "date": { "from": "2025-01" } }, "limit": 10 }' ``` ```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={ "player": {"fide_id": 1503014}, "filters": {"color": "white", "eco": ["C6"], "date": {"from": "2025-01"}}, "limit": 10, }, ) r.raise_for_status() for item in r.json()["games"]: print(item["game"]["date"], item["game"]["event"], item["game"]["eco"]) ``` ```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({ player: { fide_id: 1503014 }, filters: { color: "white", eco: ["C6"], date: { from: "2025-01" } }, limit: 10, }), }); if (!res.ok) throw new Error(await res.text()); for (const { game } of (await res.json()).games) console.log(game.date, game.event, game.eco); ``` ## 7. Page through and get the moves `cursor` pages on, newest first: send the last answer's `next_cursor`, with the same `player` and `filters`. Every page bills again, so if a person is paying, confirm with them before you page past the first. `pgn: true` adds each game's moves, which every answer leaves out by default. The Games database is rebuilt now and then. A cursor from before a rebuild is `400 cursor_expired`: start again without it. ```python Python import os import requests def search(body): r = requests.post( "https://api.chessdrive.io/v1/search", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json=body, ) r.raise_for_status() return r.json() player = {"fide_id": 1503014} first = search({"player": player, "limit": 2, "pgn": True}) games = first["games"] if first["next_cursor"]: games += search({"player": player, "limit": 2, "pgn": True, "cursor": first["next_cursor"]})["games"] print(len(games), "games fetched") print(games[0]["game"]["pgn"]) ``` ```js JavaScript async function search(body) { 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(body), }); if (!res.ok) throw new Error(await res.text()); return res.json(); } const player = { fide_id: 1503014 }; const first = await search({ player, limit: 2, pgn: true }); const games = [...first.games]; if (first.next_cursor) { games.push(...(await search({ player, limit: 2, pgn: true, cursor: first.next_cursor })).games); } console.log(games.length, "games fetched"); console.log(games[0].game.pgn); ``` ## 8. Find positions by a filter `where` is a **Position filter**: a condition, true or false for each position, written as a small JSON tree. This one holds when a white bishop stands on b5 and a black knight on c6, the Ruy Lopez's pin. `limit` is 1 to 200, and 20 when you leave it out. ```bash curl curl https://api.chessdrive.io/v1/search \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "where": { "all": [ { "any": { "and": [{ "piece": "wB" }, { "squares": ["b5"] }] } }, { "any": { "and": [{ "piece": "bN" }, { "squares": ["c6"] }] } } ] }, "limit": 5 }' ``` ```python Python import os import requests ruy_lopez = {"all": [ {"any": {"and": [{"piece": "wB"}, {"squares": ["b5"]}]}}, {"any": {"and": [{"piece": "bN"}, {"squares": ["c6"]}]}}, ]} r = requests.post( "https://api.chessdrive.io/v1/search", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={"where": ruy_lopez, "limit": 5}, ) r.raise_for_status() for p in r.json()["positions"]: print(p["fen"], p["occurrences"], p["quiet"]) ``` ```js JavaScript const ruyLopez = { all: [ { any: { and: [{ piece: "wB" }, { squares: ["b5"] }] } }, { any: { and: [{ piece: "bN" }, { squares: ["c6"] }] } }, ], }; 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({ where: ruyLopez, limit: 5 }), }); if (!res.ok) throw new Error(await res.text()); for (const p of (await res.json()).positions) console.log(p.fen, p.occurrences, p.quiet); ``` ## 9. Read the positions The counts and the game in this example are made up. - `positions`: the positions the filter holds for, in the Games database's own order, which is stable but not by popularity. Each has its `fen`, how many times games reached it (`occurrences`), whether it is `quiet` (the side to move is out of check and has no capture or promotion that wins material), and in `examples` the highest-rated game that reaches it, without its moves, with the `ply` at which it first does. - `next_cursor`: send it back as `cursor`, with the same `where` and `define`, for the next page. It is null on the last page. - `usage.positions` is how many came back. A call is billed for at least one. ```json Response { "id": "req_01J9F3T7Y2Q0", "positions": [ { "fen": "r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 0 1", "occurrences": 412, "quiet": true, "examples": [ { "ply": 5, "game": { "id": "1938274", "url": null, "white": { "name": "Fixture, Ada", "rating": 2412, "title": null, "fide_id": 99000001 }, "black": { "name": "Fixture, Bo", "rating": 2305, "title": null, "fide_id": 99000002 }, "event": "Fixture Open 2024", "date": "2024-09-12", "speed": null, "speed_basis": null, "time_control": null, "eco": "C65", "opening": null, "result": "1-0", "venue": null, "platform": null, "rated": null, "pgn": null } } ] } ], "next_cursor": "p1.eyJjIjoiMjAifQ", "usage": { "positions": 1 }, "cost_usd": "0.005000" } ``` ## 10. Name the parts `define` names parts of a filter, each a board expression or a test, and `{"ref": name}` uses one. A part may use other parts, never itself. Here a rook ending is no queens, bishops or knights, and a rook on each side. ```python Python import os import requests rook_ending = {"all": [ {"none": {"or": [{"piece": p} for p in ["wQ", "bQ", "wB", "bB", "wN", "bN"]]}}, {"any": {"piece": "wR"}}, {"any": {"piece": "bR"}}, ]} r = requests.post( "https://api.chessdrive.io/v1/search", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={ "where": {"all": [{"ref": "rook_ending"}, {"to_move": "white"}]}, "define": {"rook_ending": rook_ending}, }, ) r.raise_for_status() print(len(r.json()["positions"]), "rook endings with White to move") ``` ## 11. Mend a filter A filter that isn't right is `400 invalid_filter` and costs nothing. `param` points at the node at fault, so a program, or an agent, can mend that node and send again. Here `pice` should be `piece`: ```json Response { "type": "error", "error": { "type": "invalid_request_error", "code": "invalid_filter", "message": "This isn't a node of the Position filter, or its value is wrong. A node is one key, such as {\"piece\": \"wN\"}, with count's gte, lte or eq beside it.", "param": "where.all[0].any.pice" }, "request_id": "req_01J9F3T7Y2Q1" } ``` A filter that takes too long is `503 upstream_unavailable`, also free: narrow it, for example with `to_move` or a piece count. ## The Position filter A filter is a **test**, built from **board expressions**, each a JSON object with one key. A board expression gives a set of squares, and a test turns sets into true or false. | Board expression | The squares | |---|---| | `{"piece": "wN"}` | Holding that piece: `w` or `b`, then `P N B R Q K`. | | `{"attacks": "wB"}`, `{"attacks": "white"}` | Attacked by that kind of piece, or by that side. A side's own pieces count as attacked, so this is also "defended". | | `{"occupied": "white"}` | Holding a piece of that side, or of either with `"any"`. | | `{"squares": ["g8", "h7"]}`, `{"rank": 7}`, `{"file": "a"}` | Those squares, that rank (1 to 8) or that file. | | `{"and": [X, Y]}`, `{"or": [X, Y]}`, `{"not": X}` | Both, either, or the other squares. | | `{"shift": [X, "N"]}` | X moved one step: `N S E W NE NW SE SW`. What leaves the board is dropped. | | `{"fill": [X, "N"]}` | X moved 1 to 7 steps that way, X itself left out. | | `{"flip": X}` | X with the colours swapped and the ranks mirrored. | | Test | True when | |---|---| | `{"any": X}`, `{"none": X}` | X has a square, or none. | | `{"count": X, "gte": 3}` | X has at least 3 squares; `lte` is at most, `eq` exactly. | | `{"to_move": "white"}` | That side is to move. | | `{"castling": "K"}` | That castling right is left: `K Q k q`. | | `{"en_passant": true}` | An en passant capture is possible, or with a board expression, possible onto it. | | `{"all": [T, U]}`, `{"some": [T, U]}`, `{"not": T}` | Every one, at least one, or not. | | `{"flip": T}` | T holds with the colours swapped. "Either side" is `{"some": [T, {"flip": T}]}`. | `{"ref": name}` stands for a part named in `define`, of whichever kind it is. A filter is at most 2,000 nodes and 64 levels deep, counted with every `ref` replaced. The `chessdrive-position-filter` Skill, in the [Plugin](/skills), teaches an agent to write filters from plain words. ## Known gaps What the games don't do yet, so you can plan around it: - **No venue.** The Games database doesn't say whether a game was played over the board or online, so `venue`, `url`, `platform` and `rated` are null. No games come from sites where people play online yet, so Search takes no usernames from them. - **Up to October 2025.** Nothing played after October 2025 is in the Games database yet. - **Mostly strong players.** Most games are titled and master-level players'. A club player may have few games, or none. - **Few game details.** A game has no `speed`, `time_control` or `opening` name yet, so those are null, and a game's players have no `title`. `eco` names the opening, and `player` gives the title from FIDE's list. `date` is null when only the year or month is known. - **No games to choose for a filter.** `where` looks at every game. It can't yet look only at one player's games, a range of dates or ratings, or take `filters`. - **No player in the explorer.** `position` counts every game. It can't yet count only one player's games, or take `filters`. - **Duplicates.** The same game can come back twice, if its copies don't look like one game. ## Search by similar moments Finding the moments in real games nearest a position or a text is coming soon. Until it opens, a `query` answers `501 coming_soon` and costs nothing. Its opening is announced in the [Changelog](/changelog). To find an idea across your own games today, embed them with [Embed](/docs/embed). ## What a call costs - **`position`**: one query, $5 per 1,000, whether or not any game reaches the position. - **`player`**: $5 per 1,000 games returned, at least one game a call. `usage.games` reports the true count. An ambiguous name, which returns no games, is free. - **`where`**: $5 per 1,000 positions returned, at least one position a call. `usage.positions` reports the true count. - Repeat calls bill again, even for the same games. Errors never bill. The prices are on [Pricing](/pricing). ## Limits and errors | Code | When | |---|---| | `missing_field` | A body with no mode, a `player` with nothing in it, or a `define` with no `where`. | | `invalid_field` | Two modes, a `model` (Search takes none), `filters` with `position` or `where`, `define` without `where`, a field or filter of another mode, a filter value out of its range, or a `cursor` that isn't a `next_cursor`. | | `invalid_filter` | A `where` or `define` that isn't a Position filter. `param` names the node. | | `invalid_fen`, `invalid_pgn`, `invalid_ply` | A `position` that can't be read. | | `limit_too_high` | A `limit` over 200. | | `unknown_player` | No player on FIDE's list with that FIDE ID or name. | | `cursor_expired` | A cursor from before the Games database was rebuilt. Start again without it. | | `rate_limited` | Your requests per minute, or the Games database is busy. Wait for `Retry-After`. | | `upstream_unavailable` | The games can't be reached right now, or the call ran out of time. Retry with backoff; a filter that ran too long, narrow. | | `coming_soon` | A `query`, until it opens. | A refused call is not billed. Search's rate limits are on [Rate limits](/docs/rate-limits). See [Errors](/docs/errors) for what to do about each code, and the [API reference](/docs/api#search) for every field.