# 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. > > Using ChessDrive in Claude, ChatGPT or a coding agent? You don't need a key or this page. [Add ChessDrive to your AI](/cookbook/add-to-your-ai) takes two minutes, then ask it to review your last game. 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. ## 1. Create an API key In the [Dashboard](/dashboard/keys), 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. ```text Shown once # Shown once, right after you create the key. # Copy it now: you won't be able to see it again. ck_••••••••••••••••••••••••••••••••••••••••7Qf2Lm ``` ## 2. Set 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. ```bash macOS / Linux export CHESSDRIVE_API_KEY="ck_…" ``` ```powershell Windows setx CHESSDRIVE_API_KEY "ck_…" ``` ```bash .env # Keep .env out of version control CHESSDRIVE_API_KEY=ck_… ``` > **Keep keys out of your repository** > > Don't paste a key into code you commit or into a browser app. If a key leaks, revoke it in API keys and create a new one: revoking is immediate and permanent. ## 3. Call 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. ```bash curl 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?" }] }' ``` ```python Python import os import requests r = requests.post( "https://api.chessdrive.io/v1/generate", headers={"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"}, json={ "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?"}], }, ) print(r.json()["content"]) ``` ```js JavaScript const res = await fetch("https://api.chessdrive.io/v1/generate", { method: "POST", headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ 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?" }], }), }); console.log((await res.json()).content); ``` ## 4. Read 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. ```json Body { "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" } ``` ```http Headers HTTP/2 200 content-type: application/json request-id: req_01M4FY8WAW29J77H1C078Y9X1J x-ratelimit-limit-requests: 20 x-ratelimit-remaining-requests: 19 x-ratelimit-reset-requests: 3 ``` ## 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](/docs/errors#retrying). | Status | Code | Meaning | Next step | |---|---|---|---| | 402 | `insufficient_balance` | Your Balance is used up, or has no credits yet. | Top up, or turn on Auto-recharge. | | 402 | `spend_limit_reached` | The Account hit its monthly Spend limit. | An Admin raises or removes the Spend limit. | | 402 | `key_limit_reached` | This API key hit its Key limit. | Raise the Key limit, or wait for its reset. | | 429 | `rate_limited` | Too many requests for this Model. | Wait for `Retry-After` seconds, then retry. | Every field and error code is in the [API reference](/docs/api).