Docs /APIs /Engine .md

Engine

Analyse a position with Stockfish (Lc0 is coming soon) and get its evaluation in numbers and its best Lines, ranked. Stream each depth as it completes.

POST /v1/engine runs a chess engine on a position and returns its evaluation and its best Lines. Set engine to stockfish (lc0 is coming soon), choose how long it searches, and ask for up to five Lines. Engine runs no Model of ours, so it judges in numbers: centipawns, mate counts and win, draw and loss chances. When you want the position explained in words, ask Generate. To judge every move of a game in one call, send it whole; to check many positions, send a list; to have Knight explain the mistakes too, follow the Review a game Recipe; to score how well each side played, Grade a game's accuracy.

Where a search runs. Engine earns its price on deep and bulk work: a whole game, a list of positions, several games at once, or a search at depth 20 or more, on engines faster than most laptops. One position at a shallower depth answers just as well on your own Stockfish, at no cost: chessdrive engine runs it there when Stockfish is installed, and says how to install it when it isn't. A Study page runs Stockfish in the browser for the position on view.

1Analyse a position

engine and position, or a list as positions, are required. position is a FEN, or a PGN with a ply, as on every API. Set at most one limit: depth, nodes or movetime_ms, under the caps below. Without one, Stockfish searches to depth 20.

lines is how many Lines you want, ranked best first: 1 by default, at most 5. Engine takes no model.

curl https://api.chessdrive.io/v1/engine \
  -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "engine": "stockfish",
    "position": { "fen": "r1bqk2r/1pppbppp/p1n2n2/4p3/B3P3/5N2/PPPP1PPP/RNBQ1RK1 w kq - 4 6" },
    "depth": 24,
    "lines": 3
  }'

2Read the Lines

best_move is the first move of the top Line. Each Line in lines has its rank, the depth it was searched to, and its moves as san and uci. Its score is from White's point of view, whoever is to move:

  • cp is the evaluation in centipawns: +100 is about a pawn up for White, negative favours Black.
  • mate, when the engine sees a forced mate, is the number of moves to it: positive when White mates, negative when Black does. Exactly one of cp and mate is set; the other is null.
  • wdl is White's chances of a win, a draw and a loss, per mille, so they add up to 1,000.

The response also echoes the engine, its version and network, the fen it analysed, how deep and wide it searched (depth, seldepth, nodes) and for how long (time_ms). stop_reason is limit when it reached your limit and time_cap when the time cap stopped it first.

{
  "id": "req_01M4G2Q9C6TE3W7N5XKB8HJF0R",
  "engine": "stockfish",
  "version": "Stockfish 19",
  "network": null,
  "fen": "r1bqk2r/1pppbppp/p1n2n2/4p3/B3P3/5N2/PPPP1PPP/RNBQ1RK1 w kq - 4 6",
  "depth": 24,
  "seldepth": 33,
  "nodes": 9870000,
  "time_ms": 1840,
  "stop_reason": "limit",
  "best_move": { "san": "Re1", "uci": "f1e1" },
  "lines": [
    {
      "rank": 1,
      "depth": 24,
      "cp": 32,
      "mate": null,
      "wdl": { "win": 98, "draw": 880, "loss": 22 },
      "moves": [
        { "san": "Re1", "uci": "f1e1" },
        { "san": "b5", "uci": "b7b5" },
        { "san": "Bb3", "uci": "a4b3" },
        { "san": "d6", "uci": "d7d6" },
        { "san": "c3", "uci": "c2c3" },
        { "san": "O-O", "uci": "e8g8" }
      ]
    },
    {
      "rank": 2,
      "depth": 24,
      "cp": 24,
      "mate": null,
      "wdl": { "win": 80, "draw": 893, "loss": 27 },
      "moves": [
        { "san": "Qe2", "uci": "d1e2" },
        { "san": "b5", "uci": "b7b5" },
        { "san": "Bb3", "uci": "a4b3" },
        { "san": "O-O", "uci": "e8g8" }
      ]
    },
    {
      "rank": 3,
      "depth": 24,
      "cp": 17,
      "mate": null,
      "wdl": { "win": 64, "draw": 904, "loss": 32 },
      "moves": [
        { "san": "d3", "uci": "d2d3" },
        { "san": "b5", "uci": "b7b5" },
        { "san": "Bb3", "uci": "a4b3" },
        { "san": "d6", "uci": "d7d6" }
      ]
    }
  ],
  "usage": { "engine_ms": 1840 },
  "cost_usd": "0.002300"
}

4Run Lc0

Lc0 guides its search with a large neural network: it looks at far fewer positions than Stockfish and judges each one more deeply, so the two often prefer different moves. Its limit is nodes, counted in visits, or movetime_ms; it takes no depth. Without a limit it searches 10,000 nodes.

network picks the Lc0 Network. It is optional, and only Lc0 takes one:

networkNetwork
bt4BT4-it332, the default and Lc0's recommended network
t82T82, an earlier main-run network
t1-256T1-256, a small network: more nodes per second, less knowledge in each

The response echoes the network it ran.

curl https://api.chessdrive.io/v1/engine \
  -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "engine": "lc0",
    "network": "bt4",
    "position": { "fen": "r1bqk2r/1pppbppp/p1n2n2/4p3/B3P3/5N2/PPPP1PPP/RNBQ1RK1 w kq - 4 6" },
    "nodes": 100000,
    "lines": 2
  }'

5Review a whole game

Send a pgn with no ply and Engine runs on every position of its main line in one call: one entry per move, in order. A game review is then one call, or one tool call in an agent app, rather than one per position.

Each entry has the move (san and uci), the ply it was played from, which is the position to send Generate when you want it explained, its fen, eval_before and eval_after from White's point of view, the win_chance_lost by the side that played it, its Move verdict and Engine's best_line from before it, up to 8 half-moves. The verdict is Lichess's: the win chance 2 / (1 + exp(−0.00368208 × cp)) − 1, ±1 for a mate, and 0.1 of it lost is an inaccuracy, 0.2 a mistake and 0.3 a blunder; best is Engine's own move and anything else is good. A game that ends in mate has eval_after mate 0 on its last move, and wdl says who won.

Your limit applies to each position; without one Stockfish searches each to depth 14, which reviews a 40-move game in about 10 to 15 seconds. The game shares a call's 60 seconds: a movetime_ms its positions can't fit is refused, and a game still running at 60 seconds fails with limit_too_high and costs nothing. Send a lower limit, or review the game in parts with {pgn, ply}. For a file of games, the CLI's --games sends them as many at once as your Plan allows. It is billed by the Engine time of all its positions together. A whole game takes no lines and no stream.

The game below is Légal's trap from the Review a game Recipe; the response shows two of its twelve moves.

curl https://api.chessdrive.io/v1/engine \
  -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "engine": "stockfish",
    "position": { "pgn": "1. e4 e5 2. Nf3 d6 3. Bc4 Bg4 4. Nc3 g6 5. Nxe5 Bxd1 6. Bxf7+ Ke7" }
  }'

6Check a list of positions

Send positions instead of position to analyse up to 100 positions in one call, each a FEN or a PGN with a ply. It is one request and one in flight, so checking a list doesn't take a burst of calls, and it's much faster and cheaper than separate calls: at depth 10, 100 positions take about 3 to 7 seconds and cost about $0.002.

results holds one answer per position, in the order you sent them. Each has a status:

statusWhat it means
okAnalysed, with the same fields as one position: depth, best_move, lines and the rest. Each Line stops at its first 8 half-moves.
game_overThe position has no legal moves. It isn't analysed or billed, and doesn't stop the others.
not_runThe call ended before this position. It isn't billed, so send it again.

Your limit and lines apply to each position; without a limit Stockfish searches each to depth 14. The positions run one after another inside a call's 60 seconds. A position that can't be read refuses the whole call and costs nothing, and the error's param names it, such as positions[17].fen. At 60 seconds, or if the engine fails part way, the call still answers 200: what finished is billed, and the rest comes back as not_run. If nothing finished, you get the usual error, and it costs nothing. It is billed by the Engine time of all its positions together. A list takes no stream.

For more than 100, send calls of 100, up to your requests in flight at once, or use the CLI's --positions, which does that for you.

curl https://api.chessdrive.io/v1/engine \
  -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "engine": "stockfish",
    "positions": [
      { "fen": "r1bqk2r/1pppbppp/p1n2n2/4p3/B3P3/5N2/PPPP1PPP/RNBQ1RK1 w kq - 4 6" },
      { "pgn": "1. e4 e5 2. Nf3 d6 3. Bc4 Bg4", "ply": 6 }
    ],
    "depth": 10
  }'

7Stream each depth

A deep search can take seconds. With "stream": true the response is Server-Sent Events, so you can show the analysis improving as it runs:

  1. analysis_start, with the request id, the engine, its version and network.
  2. depth, once per completed depth, with the analysis so far: every field of the response except stop_reason, usage and cost_usd.
  3. analysis_end, with the full response body.

If something fails after the stream has started, an error event with the usual error body ends it, and the call is not billed. If you close the connection early, you are billed for the Engine time used until then, so a client can stop as soon as the analysis is good enough.

curl -N https://api.chessdrive.io/v1/engine \
  -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "engine": "stockfish",
    "stream": true,
    "position": { "fen": "r1bqk2r/1pppbppp/p1n2n2/4p3/B3P3/5N2/PPPP1PPP/RNBQ1RK1 w kq - 4 6" },
    "depth": 24
  }'

Limits and caps

Send at most one limit. Each engine has its own caps, and a value over one is a 400 limit_too_high, never quietly lowered.

LimitStockfishLc0
depth1 to 50Not taken
nodesUp to 1,000,000,000Up to 2,000,000 visits
movetime_msUp to 60,000Up to 60,000
Without a limitdepth 20, or 14 on each position of a whole game or a listnodes 10,000

A search runs to your limit, with no lower cap of ours. The one other limit is time: a search that hasn't reached its limit at 60 seconds stops with stop_reason time_cap, and returns the deepest analysis it completed. The default depth 20 ends with stop_reason limit.

Each call runs Stockfish 19 with 2 threads and 256 MiB of hash to itself, whatever else is running. That searches about 1 million nodes per second in openings and middlegames, and up to about 2 million in simple endgames (measured October 2026). The default depth 20 takes about a second from the starting position, and a 60-second search reaches about depth 37.

CodeWhen
unknown_engineAn engine we don't run.
coming_soonlc0, until it opens.
unknown_networkA network Lc0 doesn't have.
limit_too_highA limit over the engine's cap, or a whole game that doesn't fit a call's 60 seconds.
invalid_fieldTwo limits, depth on Lc0, network on Stockfish, lines outside 1 to 5, or a model; lines or stream on a whole game; stream on a list; both position and positions.
game_overThe side to move has no legal moves: the position is mate or stalemate. In a list, that position's status instead.
too_many_inputsMore than 100 positions.
invalid_fen, invalid_pgn, invalid_plyA position that can't be read, or a whole game with no moves.

Engine time

Engine is billed by Engine time: how long the engine searched for your call, not counting any time it waited for a free engine. usage.engine_ms reports it, and each engine has its own price per hour on Pricing.

Every call is billed for at least 100 ms of Engine time, and a list or a whole game counts as one call. A shallow search that took 40 ms still shows "engine_ms": 40 in usage, and is billed as 100 ms; cost_usd is always the amount actually drawn. Failed calls are free.

Each search has an engine to itself. Engine limits how many of your calls run at once on each engine. A call over that limit waits up to 5 seconds for one to finish, so a short burst just takes turns, then gets a 429 rate_limited with Retry-After. Its responses report the limit in x-ratelimit-limit-concurrent and x-ratelimit-remaining-concurrent, next to the usual requests-per-minute headers; a call refused before the rate limits are checked, such as a 400, carries none of them.