Batch and fine-tuning API

# Agent quickstart

Point an AI agent at Gridline and let it fine-tune, evaluate and batch open models for you. There are no GPUs, containers or sandboxes to manage: the agent calls the same API you would.

## Overview

Gridline's MCP server gives any MCP client (Claude Code, Claude Desktop and others) tools for the whole loop: upload data, fine-tune, evaluate the result against its base, batch on the winner and download the merged weights. Each tool wraps one OpenAI-compatible route under Gridline's base URL, so an agent without MCP can do the same over HTTP.

```
https://api.gridlinegpu.com/openai/v1
```

The [OpenAPI 3.1 spec](https://gridlinegpu.com/openapi.json) describes every documented route.

## Getting access

- Free credit: $5 for new accounts once the email is verified: one per email address (+tag variants count as one) and per network, while today's credits last.
- Self-serve API keys: create one in the dashboard (https://gridlinegpu.com/dashboard/tokens), or let an agent sign up with POST https://gridlinegpu.com/api/agent/signup, which returns the key with no browser.

## No account yet

An agent can create the account, its API key and the person's credit with no browser. First it shows the person the [terms of use](https://gridlinegpu.com/terms), the [job terms](https://gridlinegpu.com/job-terms.md) and the [privacy policy](https://gridlinegpu.com/privacy) and gets their yes: it accepts them on the person's behalf.

```
curl -X POST https://gridlinegpu.com/api/agent/signup -H "Content-Type: application/json" \
  -d '{"email": "THE_PERSON_S_EMAIL", "accept_terms": true, "terms_of_use_sha256": "cd31d803738870acde75635d8941deb807388b66a273a179609e988bbc8bac4a"}'
```

The answer carries the API key once. The agent saves it to a private file and loads it as `GRIDLINE_TOKEN`. Before anything else (uploads, quotes, jobs) it verifies the email with the 6-digit code Gridline sends, subject "Your Gridline code": an agent that can read the person's inbox finds the newest one itself, using only an email from the sender `GET https://gridlinegpu.com/api/agent` names; otherwise the person opens their email and reads it the code. Then it opens the account once, before the first upload: it claims the free credit (one per email address, where +tag variants count as one, and per network, while it lasts), or asks for a card checkout link the person pays once (or a USDC payment request, when those are open). Until then uploads and jobs are refused. `GET https://gridlinegpu.com/api/agent` lists every step, body and current terms digest; each digest is the terms' version id, sent as given (it is not a hash of the `.md` file). For an existing account, or a key about to expire, the agent posts the email to `/api/agent/login` and the emailed code to `/api/agent/login/verify` for a new key.

Keys: `POST /api/agent/key/revoke` revokes the key the agent holds. Listing the keys or revoking another one needs an emailed code (`/api/agent/keys/code`, then `/api/agent/keys/list` and `/api/agent/keys/revoke`). Closing the account is not available to agents: the person does it in [settings](https://gridlinegpu.com/settings).

## Connect an agent

With no browser, the server's `signup` tool creates an account and its key, and `email_login` gets a key for an existing account from an emailed code. The browser approval below is the fallback.

No key is needed up front. When a tool answers `not_logged_in`, the agent calls the server's `login` tool and shows you a link and a code: sign in (or sign up), check the code and click Approve. The server saves the key in a private file on your machine, the same one `gridline login` from the Python SDK uses. To use a key you already have, give it to the server as `GRIDLINE_TOKEN`. The key stays on your machine: the server sends it only to Gridline's API, never prints it and never returns it in a tool result.

Claude Code:

```
claude mcp add gridline -- npx -y @gridlinegpu/mcp
```

Any MCP client that reads a JSON config:

```
{
  "mcpServers": {
    "gridline": {
      "command": "npx",
      "args": ["-y", "@gridlinegpu/mcp"],
      "env": { "GRIDLINE_TOKEN": "<your Gridline API key>" }
    }
  }
}
```

The server runs over stdio as `gridline-mcp`. It also runs hosted at a URL, with nothing to install: see [Remote MCP](https://gridlinegpu.com/docs/mcp#remote-mcp).

## A worked loop

Ask the agent in plain language, for example:

```
Fine-tune qwen3.5-9b on ./train.jsonl. Then compare the fine-tuned model
with the base on ./eval.jsonl, and run ./requests.jsonl as a batch on whichever scores
higher. Tell me what each paid step will cost before you run it.
```

A capable agent then:

1. Uploads `train.jsonl` with `upload_file`, purpose `fine-tune`.
2. Quotes the job with `create_fine_tune` and `dry_run`, tells you the cost, and starts it once you agree, then polls `get_fine_tune` and `list_fine_tune_events` until it has an `ft:` model.
3. Defines an eval with `create_eval`, quotes a run on the base and on the `ft:` model with `create_eval_run` and `dry_run`, and runs both once you agree.
4. Compares the scores with `get_eval_run` and `list_output_items`.
5. Uploads `requests.jsonl` (purpose `batch`), runs it on the better model with `create_batch`, and saves the results with `download_results`.

## Spending credit

Four tools spend credit: `create_fine_tune`, `create_eval_run` and `create_distillation` (unless `dry_run` is true), and `create_batch`. Each refuses unless the call carries `confirm_spend: true`, so an agent cannot spend by accident: it has to read the quote or the price first, and a well-behaved agent tells you before it confirms. Every other tool is free. What each job costs is on the [pricing page](https://gridlinegpu.com/pricing); fine-tunes are charged per training token, batches per input and output token, each with its minimum.

## Tools

| Tool | Spends credit | What it does |
| --- | --- | --- |
| `list_models` | No | Base models you can batch or fine-tune on, and your ft: models. |
| `get_credit_balance` | No | Your credit balance and recent charges. |
| `upload_file` | No | Upload a local JSONL file (purpose fine-tune or batch). |
| `create_fine_tune` | Yes | Start a LoRA, QLoRA or DPO fine-tuning job, or quote it with dry_run. |
| `list_fine_tunes` | No | Your fine-tuning jobs. |
| `get_fine_tune` | No | A job's status, its quote and its ft: model once it succeeds. |
| `list_fine_tune_events` | No | A job's progress and loss. |
| `cancel_fine_tune` | No | Cancel a fine-tuning job. |
| `create_batch` | Yes | Run a batch on a base model or your ft: model. |
| `get_batch` | No | A batch's status, counts and output file ids. |
| `cancel_batch` | No | Cancel a batch. |
| `download_results` | No | Save a batch's output or error file to a local path. |
| `create_eval` | No | Define an eval: its item schema and graders. |
| `create_eval_run` | Yes | Run an eval, or quote it with dry_run. |
| `get_eval_run` | No | A run's status and per-grader results. |
| `list_output_items` | No | A run's graded rows. |
| `create_distillation` | Yes | Run a one-call distillation job (teacher, student, prompt baking), or quote it with dry_run. |
| `list_distillations` | No | Your distillation jobs. |
| `get_distillation` | No | A job's status, stage, costs and its ft: model once it succeeds. |
| `list_distillation_events` | No | A job's stage events. |
| `cancel_distillation` | No | Cancel a distillation job and its current stage. |
| `request_merged_weights` | No | Export an ft: model merged into its base. |
| `get_merged_weights` | No | A merged-weights export's status and files. |
| `get_merged_file_url` | No | A short-lived download URL for one merged file. |

## Plain HTTP

An agent without MCP can run the same loop with any HTTP client, using a Gridline API key as the bearer token. The routes and objects are OpenAI's (see the [quickstart](https://gridlinegpu.com/docs#access)).

```
# 1. Upload training data
curl https://api.gridlinegpu.com/openai/v1/files -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -F purpose=fine-tune -F file=@train.jsonl

# 2. Quote the fine-tune first (dry_run), then create it without dry_run (creating starts it)
curl https://api.gridlinegpu.com/openai/v1/fine_tuning/jobs -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen3.5-9b", "training_file": "file-...", "method": "qlora", "dry_run": true}'

# 3. Quote an eval run first (dry_run), then run it without dry_run
curl https://api.gridlinegpu.com/openai/v1/evals/eval_.../runs -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"data_source": {...}, "dry_run": true}'

# 4. Batch on the fine-tuned model
curl https://api.gridlinegpu.com/openai/v1/batches -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input_file_id": "file-...", "endpoint": "/v1/chat/completions", "completion_window": "24h"}'
```

---

Source: https://gridlinegpu.com/docs/agents
