Documentation / API reference
POST /v1/analyze
Analyze a PGN game asynchronously with Stockfish. Submit up to 49 plies (50 positions including the starting position), then poll the job and download results.
- Auth
- Bearer API key; 100 free requests with a verified email, then add a card
Request body
| Field | Type | Default | Notes |
|---|---|---|---|
engine | string | latest | stockfish-14 through stockfish-19; pinned when queued |
path | auto | native | wasm | auto | |
options | object | Version-specific options from GET /v1/engines | |
pgn * | string | PGN with at most 49 plies. The starting position is also analyzed. | |
depth | integer | 10 | 1 to 14 |
multipv | integer | 1 | 1 to 3 |
curl -s https://stockfishapi.com/v1/analyze \
-H "Authorization: Bearer $STOCKFISH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"pgn":"1. e4 e5 2. Nf3 Nc6 *","depth":10,"multipv":1}' const res = await fetch("https://stockfishapi.com/v1/analyze", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.STOCKFISH_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
"pgn": "1. e4 e5 2. Nf3 Nc6 *",
"depth": 10,
"multipv": 1
}),
});
const data = await res.json(); import os, requests
r = requests.post(
"https://stockfishapi.com/v1/analyze",
headers={"Authorization": f"Bearer {os.environ['STOCKFISH_API_KEY']}"},
json={
"pgn": "1. e4 e5 2. Nf3 Nc6 *",
"depth": 10,
"multipv": 1
},
)
data = r.json() Responses
| Status | Meaning |
|---|---|
202 | Queued game analysis |
Example 202 response
Illustrative response for the request above. Your job ID and reserved cost are returned by the API.
{
"id": "job_example",
"status": "queued",
"cost_units": 5,
"poll": "/v1/jobs/job_example",
"events": "/v1/jobs/job_example/events"
} Poll the job and download results
Use the same API key that created the job, including for polling, results, events and cancellation. Replace job_example with the returned id, or use the returned poll path.
curl --fail-with-body -sS https://stockfishapi.com/v1/jobs/job_example \
-H "Authorization: Bearer $STOCKFISH_API_KEY" Job state includes status, progress.done and progress.total. This shortened example shows a game job in progress; batch totals match the number of FENs submitted.
{
"id": "job_example",
"status": "running",
"progress": {
"done": 1,
"total": 5
},
"error": null
} Poll every two seconds while status is queued or running. Stop on done, failed or cancelled. Only download the result after done; otherwise the result endpoint returns 409 not_ready.
curl --fail-with-body -sS https://stockfishapi.com/v1/jobs/job_example/result \
-H "Authorization: Bearer $STOCKFISH_API_KEY" The result contains id, engine and a positions array. Each position has its original zero-based index, FEN, reached depth and principal variations. The shortened output below is illustrative; scores, moves, reached depth and the engine label depend on the search.
{
"id": "job_example",
"engine": "stockfish-19-native",
"positions": [
{
"index": 0,
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"depth": 10,
"pvs": [
{
"rank": 1,
"eval": {
"type": "cp",
"value": 20
},
"moves": [
"e2e4",
"e7e5"
]
}
]
}
]
} JavaScript polling (Node.js 18+)
// Continue after the JavaScript submission example, where data is the 202 response.
if (!res.ok) throw new Error(JSON.stringify(data));
const headers = { Authorization: `Bearer ${process.env.STOCKFISH_API_KEY}` };
const jobUrl = `https://stockfishapi.com/v1/jobs/${encodeURIComponent(data.id)}`;
let finished = false;
for (let attempt = 0; attempt < 120; attempt++) {
const response = await fetch(jobUrl, { headers, signal: AbortSignal.timeout(30000) });
const job = await response.json();
if (!response.ok) throw new Error(JSON.stringify(job));
if (job.status === "done") { finished = true; break; }
if (["failed", "cancelled"].includes(job.status)) {
throw new Error(job.error || `Job ${job.status}`);
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
if (!finished) throw new Error("Polling timed out; save the job ID to resume later.");
const response = await fetch(`${jobUrl}/result`, { headers, signal: AbortSignal.timeout(30000) });
if (!response.ok) throw new Error(await response.text());
const analysis = await response.json();
console.log(analysis.positions); Python polling
# Continue after the Python submission example, where data is the 202 response.
import time
r.raise_for_status()
headers = {"Authorization": f"Bearer {os.environ['STOCKFISH_API_KEY']}"}
job_url = f"https://stockfishapi.com/v1/jobs/{data['id']}"
for attempt in range(120):
response = requests.get(job_url, headers=headers, timeout=30)
response.raise_for_status()
job = response.json()
if job["status"] == "done":
break
if job["status"] in ("failed", "cancelled"):
raise RuntimeError(job.get("error") or f"Job {job['status']}")
time.sleep(2)
else:
raise TimeoutError("Polling timed out; save the job ID to resume later.")
response = requests.get(f"{job_url}/result", headers=headers, timeout=30)
response.raise_for_status()
analysis = response.json()
print(analysis["positions"]) A local polling timeout does not cancel the job. Save the ID to resume, or DELETE /v1/jobs/{id} to request cancellation. Completed positions still count and unused units are refunded on failure or cancellation.
For live progress events, request the returned events URL with the same Bearer key. See job status and result download.
Errors follow problem+json with next_action.