CLI
Call Generate, Embed and Engine from your terminal with `chessdrive`, one binary for macOS, Linux and Windows. Install it with the installer, npm or Homebrew, log in once, and read your usage and balance too.
chessdrive is the ChessDrive API on the command line: one command per API, readable output by default, and the API's own JSON with --json. It is generated from the same contract as the API, so its flags are the API's fields. chessdrive mcp gives the same calls to an AI tool: see MCP.
1Install
The installer picks the build for your machine, checks it against the release's SHA-256 checksums and refuses one that doesn't match, then puts chessdrive in ~/.local/bin. Set CHESSDRIVE_INSTALL_DIR to put it somewhere else.
Or install it with npm, on macOS, Linux and Windows, or with Homebrew, on macOS and Linux. Both give you the same release, and check it too: npm against the package's integrity hash, Homebrew against the release's checksum. npx chessdrive runs it without installing.
On Windows without npm, download https://api.chessdrive.io/cli/latest/chessdrive_windows_amd64.exe, check it against the checksums in https://api.chessdrive.io/cli/latest/SHA256SUMS, rename it chessdrive.exe and put it on your PATH.
curl -fsSL https://chessdrive.io/install.sh | sh2Log in
chessdrive login signs you in through your browser. It opens a page where it can, and always prints the link and a code, so it works over SSH and on a machine with no browser: open the link on any device, check the code, pick the Account and a daily limit, and choose Allow. It then saves a new API key in your config folder, readable by you alone. The key is named after your machine, so you can find it there and revoke it.
Only allow a code you started yourself: anyone you allow gets a key to your Account. For a tool that can't show output while a command runs, such as an AI agent, --no-wait prints the link and code and returns. Run chessdrive login again once you've allowed it.
In CI, or with a key you already have, pipe the key in, and it is checked and saved without a browser. chessdrive login --with-key, with nothing after it, asks for one at a prompt that doesn't show what you type. The key never goes on the command line, so it stays out of your shell history.
CHESSDRIVE_API_KEY, when set, is used instead of the saved key, as it is by every sample in these docs. chessdrive logout forgets the saved key.
chessdrive key prints the key, for an AI app to read when it connects to the hosted Connector, so one sign-in serves both, and chessdrive key --headers prints it as a header for Claude Code's and Codex's headers helpers. MCP has each app's settings.
$ chessdrive login
To sign in, open this link in a browser on any device:
https://chessdrive.io/device?code=BCDF-GHJK
Check it shows this code, then choose Allow:
BCDF-GHJK
Waiting for the approval. Ctrl-C stops.
Signed in to https://api.chessdrive.io: free plan, balance $10.00.
Next: add the Skills to your AI: https://chessdrive.io/cookbook/add-to-your-aiCommands
Every command has --help with its flags. A position is --fen, or --pgn with a file (- reads stdin) and --ply, the half-move to look at, as in the API.
Generate
generate asks Knight (the default) or Queen, --model queen, and prints the reply as it streams. Each Line the reply names is marked like [L1] in the text and listed with its moves after it. The arguments are your message; --system, --max-tokens and --temperature are the API's fields, and --messages sends a whole conversation from a JSON file. --no-stream waits for the whole reply.
chessdrive generate --fen "4kb1r/p2n1ppp/4q3/4p1B1/4P3/1Q6/PPP2PPP/2KR4 w k - 0 16" "What is White's best move here?"Embed
embed turns positions and texts into vectors, in the order you give them: each --fen, --text and --pgn adds an item. It prints the start of each vector; --json gives them whole. --dimensions and --precision ask for shorter or smaller vectors, at the same price.
chessdrive embed --fen "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1" --text "an isolated queen's pawn"Embed to a file
--out writes the vectors to a file instead, for code to read, and prints only the item count, the files and the cost. It takes any number of items and makes the calls, up to 256 items each and one at a time, waiting when rate limited and trying again for about three minutes when Embed is busy. A --pgn with no --ply is then every position of every game in the file, each with its earlier boards.
vectors.npy is a NumPy file of 32-bit floats, one row per item, so 2,000 positions give the shape (2000, 512). With --dimensions 128 the vectors are shorter, (2000, 128); the file takes no --precision. vectors.jsonl, beside it, has one line per row saying what that row is: the model, the type, and the item's fen or text. A position from a PGN file has its source, its game in that file, from 0, a game_id and its ply. A position you give as a PGN in --input keeps its pgn.
Stop a run at any point, or let it fail, and the same command carries on from the rows written, so nothing is paid for twice. The file loads at every step, with the rows it has so far. If the files hold anything else, such as other items, another Model or other --dimensions, the command refuses and leaves them as they are. Free's daily limit stops the run: the same command carries on after midnight UTC.
chessdrive embed --pgn games.pgn --out vectors.npySearch
search asks Search. --fen, or --pgn with --ply, prints every move played from that position, most played first, with how those games ended. --fide-id, or --name as FIDE's list writes it, prints that player's games, newest first: --limit up to 200, and --cursor for the next page, which the answer prints. --pgn with a player writes the games as a PGN file to stdout. The filters are --date-from, --date-to, --eco, --result, --color and --opponent. A name that could be several players lists them, at no cost. A search by text is coming soon.
chessdrive search --fen "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"
chessdrive search --fide-id 1503014 --limit 5 --color whiteEngine
engine analyses a position with Stockfish (Lc0 is coming soon). A FEN on its own is the position, as --fen gives it. It streams a line per completed depth, then the ranked Lines with their scores from White's point of view and their win, draw and loss chances. Give at most one limit: --depth, --nodes or --movetime-ms. --lines asks for up to 5 Lines.
One position below --depth 20 runs on your own Stockfish, free, when it's installed: --fen, or --pgn with --ply, at --depth 18 unless you give a limit. It prints the same Lines, and --json the same body, with "id": "local" and a cost_usd of 0.000000. --depth 20 and up, --positions, --games and a whole game run on Engine, billed. --api sends one position to Engine anyway, and --local keeps it on your Stockfish at any depth. chessdrive looks for stockfish on your PATH, or the binary CHESSDRIVE_STOCKFISH names. Without one, a position runs on Engine and chessdrive says how to install Stockfish: brew install stockfish on macOS, sudo apt install stockfish on Debian or Ubuntu, or a download from stockfishchess.org.
chessdrive engine "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"
chessdrive engine --fen "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1" --depth 24 --lines 2Engine on a list of positions
--positions reads a list, one position a line: {"fen": "..."}, {"pgn": "...", "ply": 12} or a bare FEN. Anything else on a line stays out of the call. --out writes one result a line, as Engine's list answers it with an id first, so line 7 of the results answers position 7 of the list. It takes any number of positions and makes the calls, up to 100 positions each and as many at once as your Plan's requests in flight, waiting when rate limited and sending again what a call didn't reach.
Stop a run at any point, or let it fail, and the same command carries on from the rows written, so nothing is paid for twice. If the file holds another list's rows, the command refuses and leaves it as it is. A list takes one limit for all its positions, and its default is --depth 14.
chessdrive engine --positions hits.jsonl --depth 10 --out checks.jsonlEngine on a file of games
--games reviews every game of a PGN file, each whole as --pgn alone reviews one, a call a game and as many at once as your Plan's requests in flight. --out writes one line per game, in the file's order: its game number from 1, its status, its tags, the pgn sent, then the whole game's answer. - reads the file from stdin.
A game Engine refuses, such as one it can't read, is a row with status refused and Engine's error, and the run goes on. A game too long for one call goes again once at --depth 10, and its row has retried_at_depth. Rate limits are waited out, and a run stopped at any point carries on from the rows written, sending no game twice. Give at most one limit; the default is --depth 14. The summary line counts the games, the ones analysed and refused, and this run's cost; --json prints it as JSON.
chessdrive engine --games games.pgn --out answers.jsonlModels, usage and balance
models lists the Models, with no key needed. usage prints your requests and cost per API, Model or key, --group-by, over the last 7 days or --from and --to: the numbers the Dashboard's Usage page shows. balance prints your Plan, Balance, Monthly credit, Trial credits, this month's spend and Spend limit, to the cent as the Dashboard's Billing page shows them; --json gives the API's six places. Both are free.
chessdrive models
chessdrive usage --group-by model
chessdrive balanceStudy keys
study-key makes a Study key for one Study page, named after the Study, and prints it: the key a Study calls Engine and Generate with when the person asks. It calls only those two, up to $1 a day, for 7 days. Your agent runs it while it builds the Study; --url gives the Study's link, such as a Claude artifact's. It's free, and the key is listed under Study keys in API keys.
chessdrive study-key "Your game against Ana"Scripts
--json prints the API's response body unchanged, for jq and your own code. On a streamed call that is the event stream as sent; add --no-stream for one JSON body. The cost and request ID of a readable call go to stderr, so stdout holds only the answer.
chessdrive engine --fen "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1" --depth 12 --no-stream --json | jq '.lines[0]'A failed call prints its code, message and request ID to stderr, as in Errors, and exits with a code for its kind, so a script can tell them apart:
| Exit code | When |
|---|---|
0 | It worked |
1 | The API or the network failed (5xx, upstream_unavailable); retry later |
2 | A flag or argument is wrong, the API found the request invalid (400, 413), or no API answers at the address (check --base-url) |
3 | No API key, or the API refused it (401, 403) |
4 | Refused for money (402): top up or raise a limit |
5 | Rate limited (429): wait the retry after it prints |
chessdrive engine --fen "8/8/8 w - - 0 1" || echo "exit code $?"Staging and other APIs
--base-url, or CHESSDRIVE_BASE_URL, points chessdrive at another API, such as staging with a staging key. A key logged in against another API keeps pointing there. A CLI installed from staging calls staging's API unless told another. An address with no API behind it says so: No ChessDrive API at <address>. chessdrive version, or chessdrive --version, prints the version you have.
Update
chessdrive update installs the latest release the way you installed this one. It runs Homebrew or npm if one of them put chessdrive there. Otherwise it downloads the build for your machine, checks it against the release's checksums, and replaces the binary. Under npx, or in a project's node_modules, it tells you what to run. A version from before update existed needs the install command above once more.
In a terminal, chessdrive tells you when a newer version is out, once a day. It asks in the background, so no command waits for it, and it says nothing when its output goes to a pipe or a file, or when it can't reach the network.