Documentation / Guides
Stockfish from JavaScript and TypeScript
Before your first request, sign in with Google, create a key for 100 free requests with a verified email, then add a card. Start with 100 free requests with a verified email, then add a card for 2,000 units/day and automatic overage billing. The trial is shared across your account, never resets, and is never charged. All prices are in USD.
fetch in Node, Deno, Bun and the browser
Node 18+ and the browser use the same code
const API = "https://stockfishapi.com/v1";
export async function evaluate(fen: string, depth = 14, multipv = 1) {
const res = await fetch(`${API}/eval`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.STOCKFISH_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ fen, depth, multipv }),
});
if (!res.ok) throw Object.assign(new Error("stockfishapi"), { problem: await res.json(), status: res.status });
return res.json() as Promise<{ bestmove: string; eval: { type: "cp" | "mate"; value: number }; cost_units: number }>;
}
In the browser
Engine calls require an API key. Call from your server so the key stays secret.
With chess.js
import { Chess } from "chess.js";
const game = new Chess();
game.move("e4");
const { bestmove } = await evaluate(game.fen(), 12);
game.move({ from: bestmove.slice(0, 2), to: bestmove.slice(2, 4), promotion: bestmove[4] }); Sign in to create a key. Free plan, depth 14, 2,000 units a day.