STOCKFISH 14–19Latest release: 19Explore engines ↗

Documentation / Guides

Stockfish from Python

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.

requests, async, and python-chess

Install nothing, call the API

import os, requests

API = "https://stockfishapi.com/v1"
H = {"Authorization": f"Bearer {os.environ['STOCKFISH_API_KEY']}"}

def evaluate(fen: str, depth: int = 14, lines: int = 1) -> dict:
    r = requests.post(f"{API}/eval", headers=H, json={"fen": fen, "depth": depth, "multipv": lines}, timeout=60)
    r.raise_for_status()
    return r.json()

pos = evaluate("r1bqkbnr/pppp1ppp/2n5/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3", depth=16)
print(pos["bestmove"], pos["eval"], pos["cost_units"])

With python-chess

import chess
board = chess.Board()
board.push_san("e4"); board.push_san("e5")
best = evaluate(board.fen(), depth=12)["bestmove"]
board.push_uci(best)

Handle limits like a program, not a person

r = requests.post(f"{API}/eval", headers=H, json={"fen": fen, "depth": 24})
if r.status_code == 402:
    problem = r.json()
    if problem["next_action"] == "upgrade":
        print("Open this to upgrade:", problem["checkout"]["url"])
    elif problem["next_action"] == "raise_budget":
        ...
elif r.status_code == 429:
    time.sleep(int(r.headers["Retry-After"]))

Get a key: Sign in with Google at https://stockfishapi.com/dashboard, create an API key for your first 100 free requests. 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.

Sign in to create a key. Free plan, depth 14, 2,000 units a day.