Docs /Get started /Quickstart .md

Quickstart

Make your first ChessDrive call in about five minutes. Create an API key, put it in your environment, ask Generate about a position and read what comes back.

You need an account. Each new User's own account gets $10 in Trial credits once, without a card, that never expire, which covers thousands of calls like the one below. An Organization starts without any.

1Create an API key

In the Dashboard, open API keys and choose Create API key. Name it after where it will run, like "Production: tournament app". The defaults are a 1-year expiry and no Key limit; Customize sets a Key limit, which caps what this key can spend, so a leaked or looping key can't drain your Balance.

The key is shown once. Copy it before you close the dialog.

# Shown once, right after you create the key.
# Copy it now: you won't be able to see it again.

ck_••••••••••••••••••••••••••••••••••••••••7Qf2Lm

2Set the environment variable

Every sample in these docs reads the key from CHESSDRIVE_API_KEY, so it never ends up in your code. Set it in the shell you run your code from.

export CHESSDRIVE_API_KEY="ck_…"

3Call Generate

Ask POST /v1/generate about a position. model is required, so you are never billed for Queen by accident; this call uses knight-1, the cheaper and faster Model. The position is a FEN; a PGN with a ply works too. messages is the conversation, ending with your question.

Authentication is a bearer token in the Authorization header. That is the only way to pass a key.

curl https://api.chessdrive.io/v1/generate \
  -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "knight-1",
    "position": { "fen": "4kb1r/p2n1ppp/4q3/4p1B1/4P3/1Q6/PPP2PPP/2KR4 w k - 0 16" },
    "messages": [{ "role": "user", "content": "What is White'\''s best move here?" }]
  }'

4Read the response

A successful call returns JSON. The fields you will use first:

  • content: the answer, in Markdown. It links each move it names as [text](line:L1).
  • lines: those moves as Lines, each from its from_fen, every move {san, uci, fen} and legal.
  • usage: tokens processed, input and output, including any the Model spent on grounding and reasoning. Every processed token is billed, and cost_usd is what this call drew from your Balance, as a decimal string.
  • request-id: a response header, repeated as id in the body. Search for it in the Request log, and quote it when you contact us.
{
  "id": "req_01M4FY8WAW29J77H1C078Y9X1J",
  "model": "knight-1",
  "content": "Give up the queen. [Qb8+ forces Nxb8](line:L1), then Rd8 is mate: the bishop on g5 covers e7.",
  "lines": [
    {
      "id": "L1",
      "from_fen": "4kb1r/p2n1ppp/4q3/4p1B1/4P3/1Q6/PPP2PPP/2KR4 w k - 0 16",
      "moves": [
        { "san": "Qb8+", "uci": "b3b8", "fen": "1Q2kb1r/p2n1ppp/4q3/4p1B1/4P3/8/PPP2PPP/2KR4 b k - 1 16" },
        { "san": "Nxb8", "uci": "d7b8", "fen": "1n2kb1r/p4ppp/4q3/4p1B1/4P3/8/PPP2PPP/2KR4 w k - 0 17" },
        { "san": "Rd8#", "uci": "d1d8", "fen": "1n1Rkb1r/p4ppp/4q3/4p1B1/4P3/8/PPP2PPP/2K5 b k - 1 17" }
      ]
    }
  ],
  "finish_reason": "end",
  "usage": {
    "input_tokens": 618,
    "output_tokens": 74,
    "cached_tokens": 0,
    "grounding_tokens": 607,
    "reasoning_tokens": 0
  },
  "cost_usd": "0.000741"
}

When a call is refused

Failed calls are free. Two statuses mean very different things: retrying a 402 soon won't help; a 429 clears on its own. A 402 stays until someone tops up or raises a limit. See Retrying.

StatusCodeMeaningNext step
402insufficient_balanceYour Balance is used up, or has no credits yet.Top up, or turn on Auto-recharge.
402spend_limit_reachedThe Account hit its monthly Spend limit.An Admin raises or removes the Spend limit.
402key_limit_reachedThis API key hit its Key limit.Raise the Key limit, or wait for its reset.
429rate_limitedToo many requests for this Model.Wait for Retry-After seconds, then retry.

Every field and error code is in the API reference.