Stockfish Chess Engine API

Advanced chess analysis through a simple REST API

v1.0.0

Quick Start

Example Request

curl -X POST https://stockfish-api.didi.web.id/api/v1/analyze \
  -H "Content-Type: application/json" \
  -d '{"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "depth": 15}'

Endpoints

GET

/

Returns this documentation page.

GET

/health

Health check endpoint to verify the API is running.

POST

/api/v1/analyze

Analyze a chess position using the Stockfish engine. This is the main endpoint for chess analysis.

Request Body Parameters

Parameter Type Required Default Description
fen string Yes - Forsyth-Edwards Notation position string
depth int No 15 Search depth for the engine
multipv int No 1 Number of best lines to return (max: 10)
time int No 1000 Search time in milliseconds
POST

/api/v1/evaluate

Alias for /api/v1/analyze. Same functionality with different endpoint name.

WS

/ws

WebSocket endpoint for real-time analysis. Allows continuous position evaluation and analysis updates.

Response Format

{
  "best_move": "e2e4",
  "evaluations": [
    {"depth": 1, "score": {"cp": 0}},
    {"depth": 2, "score": {"cp": 15}},
    {"depth": 3, "score": {"cp": 28}}
  ],
  "fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
  "ponder": "e7e5"
}

Response Fields

Field Type Description
best_move string Best move in UCI format (e.g., "e2e4")
evaluations array Evaluation scores at each search depth
fen string The input FEN position (echoed back)
ponder string Ponder move in UCI format for the opponent's response

FEN Format (Forsyth-Edwards Notation)

FEN is the standard notation for describing a chess position. It consists of six fields separated by spaces:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
Field Description
1. Piece Placement Chess pieces on the board (lowercase black, uppercase white). Numbers represent empty squares.
2. Active Color w = White to move, b = Black to move
3. Castling Availability K, Q, k, q = available castling rights. - = no castling available
4. En Passant Target Target square for en passant capture, or - if none
5. Halfmove Clock Number of halfmoves since last pawn move or capture (for 50-move rule)
6. Fullmove Number Current move number (starts at 1, increment after Black's move)

Health Check

Verify the API is operational:

curl -X GET https://stockfish-api.didi.web.id/health

Rate Limiting

This API uses CORS and has no strict rate limits. For heavy usage, consider:

Error Handling

The API returns appropriate HTTP status codes:

Status Code Description
200 Success - Request processed successfully
400 Bad Request - Invalid FEN or missing parameters
429 Too Many Requests - Rate limit exceeded
500 Internal Server Error - Engine or server error