Docs

# Gridline API quickstart

Create a token, point the OpenAI client at Gridline, then fine-tune a model, run a batch, or do both. Each takes a few minutes.

Step 1

## Sign up, get free credit, create a token

1. [Sign up](https://gridlinegpu.com/signup) and verify your email: you get $5 of free credit to start, while today's credits last.
2. Add more by card any time from your [dashboard](https://gridlinegpu.com/dashboard).
3. Create a token in the dashboard: open your [dashboard](https://gridlinegpu.com/dashboard/tokens), choose **Create token**, name it and pick an expiry (30, 60 or 90 days).

The dashboard shows the token once, as lines you can paste into your shell. Copy them then; you won't see it again.

```
export GRIDLINE_TOKEN="gla_..."   # the token the dashboard shows once
export OPENAI_API_KEY="$GRIDLINE_TOKEN"
export OPENAI_BASE_URL="https://api.gridlinegpu.com/openai/v1"
```

The token carries the `read` and `routing:write` scopes, which is what fine-tuning and batches need. You can revoke it from the dashboard at any time.

### Or create a token with the CLI instead

Install the Gridline CLI and run `gridline login`. It prints a link and a code at once, waits up to 10 minutes while you approve it in your browser, then saves a private token, valid for 90 days, to `~/.config/gridline/python-token`. An agent can run it for you. Export it as `GRIDLINE_TOKEN`:

```
python -m pip install -U gridlinegpu
gridline login
export GRIDLINE_TOKEN="$(cat ~/.config/gridline/python-token)"
```

Step 2

## Set up the client

Gridline speaks OpenAI's API, so the OpenAI Python and Node SDKs work unchanged. Install the Python SDK if you don't have it:

```
python -m pip install openai
```

Point the client at Gridline's base URL and give it your token:

```
import os, time
from openai import OpenAI

client = OpenAI(base_url="https://api.gridlinegpu.com/openai/v1", api_key=os.environ["GRIDLINE_TOKEN"])
```

Then pick what you came to do:

- [Fine-tune a model](https://gridlinegpu.com/docs#fine-tune) On your chat data, then download it.
- [Run a batch](https://gridlinegpu.com/docs#batch) A file of requests on a catalog model, such as `qwen3.5-9b` or `bge-m3`.
- [Do both](https://gridlinegpu.com/docs#both) Fine-tune, then run a batch on your `ft:` model.

Fine-tuning

## Fine-tune a model

Write your examples as JSONL in OpenAI's chat format, at least 11 of them. The job holds at least one out to measure the model and needs 10 of them to train on. Each line is one conversation in a `messages` list, and the assistant turns are what the model learns to write:

```
{"messages": [{"role": "system", "content": "You answer support tickets for Acme."}, {"role": "user", "content": "My invoice is wrong."}, {"role": "assistant", "content": "Sorry about that. Send the invoice number and I will check it."}]}
```

Upload the file, create the job and wait for it to finish:

```
training = client.files.create(file=open("train.jsonl", "rb"), purpose="fine-tune")
job = client.fine_tuning.jobs.create(model="qwen3.5-9b", training_file=training.id)
print(job.gridline["quote"])  # creating the job started it; the quote shows what it can cost

while job.status not in ("succeeded", "failed", "cancelled"):
    time.sleep(60)
    job = client.fine_tuning.jobs.retrieve(job.id)

print(job.status, job.fine_tuned_model)
```

Queued

You aren't charged for time spent waiting.

Running

A job must finish within 5 hours.

Succeeded

The model is yours. Download it.

Your account trains one job at a time. An account can have 16 fine-tuning jobs and 64 batches open at once; a create over that answers `429` until one ends. There is no daily spend limit: you can use all the credit you have bought.

The job trains a bf16 LoRA adapter (the default). You don't choose a GPU or tune a recipe: Gridline runs it, and it trains QLoRA on smaller bases such as `qwen2.5-0.5b-instruct`. To show how much the model improved, the job measures eval loss before and after training and reports both in `job.gridline["result"]`. It measures on a validation file if you pass one, and otherwise on 5% of your training rows, held out.

When the job succeeds, `job.fine_tuned_model` names your model:

```
ft:qwen3.5-9b:o3f9a1c2d4e5:7b2c9e41a0d3
```

The model is yours. Download it, two files, with your token:

```
curl https://api.gridlinegpu.com/openai/v1/gridline/adapters/ft:qwen3.5-9b:o3f9a1c2d4e5:7b2c9e41a0d3/files/adapter_model.safetensors \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" -o adapter_model.safetensors
curl https://api.gridlinegpu.com/openai/v1/gridline/adapters/ft:qwen3.5-9b:o3f9a1c2d4e5:7b2c9e41a0d3/files/adapter_config.json \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" -o adapter_config.json
```

Fine-tunes of `qwen3-14b` are download-only for now: they cannot run in a batch yet, and `job.fine_tuned_model` stays `None`. Download those by the name in `job.gridline["fine_tuned_adapter"]["model"]`.

The [fine-tuning guide](https://gridlinegpu.com/docs/fine-tuning) covers the file rules, the settings you can change and how to delete a model.

Batch inference

## Run a batch

Write one request per line, with `body.model` set to a catalog model:

```
{"custom_id": "t-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "qwen3.5-9b", "messages": [{"role": "user", "content": "My invoice is wrong."}], "max_tokens": 256}}
```

Upload the file with `purpose=batch`, create the batch with the `24h` completion window (or `72h`, at the same price, for work that can wait: see the Batch API's [completion window](https://gridlinegpu.com/docs/batch-api#completion-window)), and download the results when it finishes:

```
batch_input = client.files.create(file=open("requests.jsonl", "rb"), purpose="batch")
batch = client.batches.create(
    input_file_id=batch_input.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
)

while batch.status not in ("completed", "failed", "expired", "cancelled"):
    time.sleep(60)
    batch = client.batches.retrieve(batch.id)

if batch.output_file_id:
    open("results.jsonl", "wb").write(client.files.content(batch.output_file_id).content)
if batch.error_file_id:
    open("errors.jsonl", "wb").write(client.files.content(batch.error_file_id).content)
```

Each line of the results carries your `custom_id` and the usual response body, including `usage`. A request that failed on its own is in the error file, and the rest of the batch still completes.

For embeddings, use `/v1/embeddings` with `bge-m3`. The [Batch API](https://gridlinegpu.com/docs/batch-api) page has the details.

Both

## Run a batch on your model

[Fine-tune a model](https://gridlinegpu.com/docs#fine-tune), then [run a batch](https://gridlinegpu.com/docs#batch) with `body.model` set to your `ft:` model instead of a catalog one:

```
{"custom_id": "t-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "ft:qwen3.5-9b:o3f9a1c2d4e5:7b2c9e41a0d3", "messages": [{"role": "user", "content": "My invoice is wrong."}], "max_tokens": 256}}
```

One batch can use up to 8 of your `ft:` models (fewer on some bases: [Models](https://gridlinegpu.com/docs/models#serving)), as long as they share a base model. Nobody else can use them: a batch from another account that names one gets `model_not_found`. The [Batch API](https://gridlinegpu.com/docs/batch-api#fine-tuned) page has the rest of the rules.

Billing

## What it costs

Fine-tuning and batch jobs are paid for from your prepaid credits. A fine-tuning job is charged for its training tokens times the number of epochs, at its base model's rate, and at least the per-job minimum. It is quoted when you create it, before it starts: creating the job starts it, and the same response carries the quote, with those tokens, the minimum and the most the job can cost. To see the quote without creating the job, send the same request with dry_run. When the job succeeds the charge is deducted from your credits, and it is never more than the quote. You can read the quote from `job.gridline["quote"]`.

A batch is charged for the input and output tokens of the results it delivers, at its model's rates (a fine-tuned model's are its base's); embeddings are charged for their input tokens only. Credits are held when a batch is validated and settled when it ends.

If your credits can't cover a job, it fails with `insufficient_quota` before anything runs: a fine-tuning job when it starts, a batch when it is validated.

What a credit is worth, the credit packs and each model's rates are on the [pricing page](https://gridlinegpu.com/pricing).

For agents

## Hand it to your agent

Most code that calls Gridline will be written by an agent. So every page here can be read without a browser, and the API is the one your agent already knows.

- **One index.** llms.txt lists every public page and the docs, with the quickstart inline.
- **Every page as Markdown.** Add .md to a page's URL, or send Accept: text/markdown to the URL you already have.
- **An API it already knows.** Files, fine-tuning jobs and batches follow OpenAI's API. Change the base URL and the key.

The index is [/llms.txt](https://gridlinegpu.com/llms.txt); this page is [/docs.md](https://gridlinegpu.com/docs.md). The agent quickstart, with the MCP server and the same loop over plain HTTP, is [/docs/agents](https://gridlinegpu.com/docs/agents). To hand the whole job to a coding agent, paste this prompt into it and add what you want to do on the last line:

Paste this into your agent

```
Help me use Gridline (https://gridlinegpu.com): managed fine-tuning and batch inference on open models, through an OpenAI-compatible API.

Before you write any code, read https://gridlinegpu.com/llms.txt and the docs it links. Every page there is also plain Markdown: add .md to its URL.

Rules:
- Base URL: https://api.gridlinegpu.com/openai/v1. The API key goes in the GRIDLINE_TOKEN environment variable. If it is not set, do not ask me to paste one: get one with no browser, as https://gridlinegpu.com/llms.txt says. Show me the terms and get my yes, then sign me up with my email (or log in with an emailed code if I already have an account). Gridline emails me a 6-digit code: read it from my inbox if you can, using only an email from the sender https://gridlinegpu.com/api/agent names, otherwise ask me for it. If I'd rather approve in a browser, run `pip install -U gridlinegpu && PYTHONUNBUFFERED=1 gridline login` instead (or the login tool of the Gridline MCP server, `npx -y @gridlinegpu/mcp`). Never print the key, paste it or commit it.
- Use the OpenAI client I already have. Do not add another SDK.
- Fine-tunes are quoted before they run, and every job is paid from my prepaid credits. Show me the quote, or the cost you expect, and wait for my yes before you create a fine-tune or a batch.
- Use only the models and parameters the docs list. If the docs do not cover something, say so instead of guessing.

What I want to do:
```

[![](https://gridlinegpu.com/brand/claude.svg)](https://claude.ai/new?q=Help%20me%20use%20Gridline%20(https%3A%2F%2Fgridlinegpu.com)%3A%20managed%20fine-tuning%20and%20batch%20inference%20on%20open%20models%2C%20through%20an%20OpenAI-compatible%20API.%0A%0ABefore%20you%20write%20any%20code%2C%20read%20https%3A%2F%2Fgridlinegpu.com%2Fllms.txt%20and%20the%20docs%20it%20links.%20Every%20page%20there%20is%20also%20plain%20Markdown%3A%20add%20.md%20to%20its%20URL.%0A%0ARules%3A%0A-%20Base%20URL%3A%20https%3A%2F%2Fapi.gridlinegpu.com%2Fopenai%2Fv1.%20The%20API%20key%20goes%20in%20the%20GRIDLINE_TOKEN%20environment%20variable.%20If%20it%20is%20not%20set%2C%20do%20not%20ask%20me%20to%20paste%20one%3A%20get%20one%20with%20no%20browser%2C%20as%20https%3A%2F%2Fgridlinegpu.com%2Fllms.txt%20says.%20Show%20me%20the%20terms%20and%20get%20my%20yes%2C%20then%20sign%20me%20up%20with%20my%20email%20(or%20log%20in%20with%20an%20emailed%20code%20if%20I%20already%20have%20an%20account).%20Gridline%20emails%20me%20a%206-digit%20code%3A%20read%20it%20from%20my%20inbox%20if%20you%20can%2C%20using%20only%20an%20email%20from%20the%20sender%20https%3A%2F%2Fgridlinegpu.com%2Fapi%2Fagent%20names%2C%20otherwise%20ask%20me%20for%20it.%20If%20I%27d%20rather%20approve%20in%20a%20browser%2C%20run%20%60pip%20install%20-U%20gridlinegpu%20%26%26%20PYTHONUNBUFFERED%3D1%20gridline%20login%60%20instead%20(or%20the%20login%20tool%20of%20the%20Gridline%20MCP%20server%2C%20%60npx%20-y%20%40gridlinegpu%2Fmcp%60).%20Never%20print%20the%20key%2C%20paste%20it%20or%20commit%20it.%0A-%20Use%20the%20OpenAI%20client%20I%20already%20have.%20Do%20not%20add%20another%20SDK.%0A-%20Fine-tunes%20are%20quoted%20before%20they%20run%2C%20and%20every%20job%20is%20paid%20from%20my%20prepaid%20credits.%20Show%20me%20the%20quote%2C%20or%20the%20cost%20you%20expect%2C%20and%20wait%20for%20my%20yes%20before%20you%20create%20a%20fine-tune%20or%20a%20batch.%0A-%20Use%20only%20the%20models%20and%20parameters%20the%20docs%20list.%20If%20the%20docs%20do%20not%20cover%20something%2C%20say%20so%20instead%20of%20guessing.%0A%0AWhat%20I%20want%20to%20do%3A%20)[![](https://gridlinegpu.com/brand/cursor.svg)](https://cursor.com/link/prompt?text=Help%20me%20use%20Gridline%20(https%3A%2F%2Fgridlinegpu.com)%3A%20managed%20fine-tuning%20and%20batch%20inference%20on%20open%20models%2C%20through%20an%20OpenAI-compatible%20API.%0A%0ABefore%20you%20write%20any%20code%2C%20read%20https%3A%2F%2Fgridlinegpu.com%2Fllms.txt%20and%20the%20docs%20it%20links.%20Every%20page%20there%20is%20also%20plain%20Markdown%3A%20add%20.md%20to%20its%20URL.%0A%0ARules%3A%0A-%20Base%20URL%3A%20https%3A%2F%2Fapi.gridlinegpu.com%2Fopenai%2Fv1.%20The%20API%20key%20goes%20in%20the%20GRIDLINE_TOKEN%20environment%20variable.%20If%20it%20is%20not%20set%2C%20do%20not%20ask%20me%20to%20paste%20one%3A%20get%20one%20with%20no%20browser%2C%20as%20https%3A%2F%2Fgridlinegpu.com%2Fllms.txt%20says.%20Show%20me%20the%20terms%20and%20get%20my%20yes%2C%20then%20sign%20me%20up%20with%20my%20email%20(or%20log%20in%20with%20an%20emailed%20code%20if%20I%20already%20have%20an%20account).%20Gridline%20emails%20me%20a%206-digit%20code%3A%20read%20it%20from%20my%20inbox%20if%20you%20can%2C%20using%20only%20an%20email%20from%20the%20sender%20https%3A%2F%2Fgridlinegpu.com%2Fapi%2Fagent%20names%2C%20otherwise%20ask%20me%20for%20it.%20If%20I%27d%20rather%20approve%20in%20a%20browser%2C%20run%20%60pip%20install%20-U%20gridlinegpu%20%26%26%20PYTHONUNBUFFERED%3D1%20gridline%20login%60%20instead%20(or%20the%20login%20tool%20of%20the%20Gridline%20MCP%20server%2C%20%60npx%20-y%20%40gridlinegpu%2Fmcp%60).%20Never%20print%20the%20key%2C%20paste%20it%20or%20commit%20it.%0A-%20Use%20the%20OpenAI%20client%20I%20already%20have.%20Do%20not%20add%20another%20SDK.%0A-%20Fine-tunes%20are%20quoted%20before%20they%20run%2C%20and%20every%20job%20is%20paid%20from%20my%20prepaid%20credits.%20Show%20me%20the%20quote%2C%20or%20the%20cost%20you%20expect%2C%20and%20wait%20for%20my%20yes%20before%20you%20create%20a%20fine-tune%20or%20a%20batch.%0A-%20Use%20only%20the%20models%20and%20parameters%20the%20docs%20list.%20If%20the%20docs%20do%20not%20cover%20something%2C%20say%20so%20instead%20of%20guessing.%0A%0AWhat%20I%20want%20to%20do%3A%20)[![](https://gridlinegpu.com/brand/chatgpt.svg)](https://chatgpt.com/?q=Help%20me%20use%20Gridline%20(https%3A%2F%2Fgridlinegpu.com)%3A%20managed%20fine-tuning%20and%20batch%20inference%20on%20open%20models%2C%20through%20an%20OpenAI-compatible%20API.%0A%0ABefore%20you%20write%20any%20code%2C%20read%20https%3A%2F%2Fgridlinegpu.com%2Fllms.txt%20and%20the%20docs%20it%20links.%20Every%20page%20there%20is%20also%20plain%20Markdown%3A%20add%20.md%20to%20its%20URL.%0A%0ARules%3A%0A-%20Base%20URL%3A%20https%3A%2F%2Fapi.gridlinegpu.com%2Fopenai%2Fv1.%20The%20API%20key%20goes%20in%20the%20GRIDLINE_TOKEN%20environment%20variable.%20If%20it%20is%20not%20set%2C%20do%20not%20ask%20me%20to%20paste%20one%3A%20get%20one%20with%20no%20browser%2C%20as%20https%3A%2F%2Fgridlinegpu.com%2Fllms.txt%20says.%20Show%20me%20the%20terms%20and%20get%20my%20yes%2C%20then%20sign%20me%20up%20with%20my%20email%20(or%20log%20in%20with%20an%20emailed%20code%20if%20I%20already%20have%20an%20account).%20Gridline%20emails%20me%20a%206-digit%20code%3A%20read%20it%20from%20my%20inbox%20if%20you%20can%2C%20using%20only%20an%20email%20from%20the%20sender%20https%3A%2F%2Fgridlinegpu.com%2Fapi%2Fagent%20names%2C%20otherwise%20ask%20me%20for%20it.%20If%20I%27d%20rather%20approve%20in%20a%20browser%2C%20run%20%60pip%20install%20-U%20gridlinegpu%20%26%26%20PYTHONUNBUFFERED%3D1%20gridline%20login%60%20instead%20(or%20the%20login%20tool%20of%20the%20Gridline%20MCP%20server%2C%20%60npx%20-y%20%40gridlinegpu%2Fmcp%60).%20Never%20print%20the%20key%2C%20paste%20it%20or%20commit%20it.%0A-%20Use%20the%20OpenAI%20client%20I%20already%20have.%20Do%20not%20add%20another%20SDK.%0A-%20Fine-tunes%20are%20quoted%20before%20they%20run%2C%20and%20every%20job%20is%20paid%20from%20my%20prepaid%20credits.%20Show%20me%20the%20quote%2C%20or%20the%20cost%20you%20expect%2C%20and%20wait%20for%20my%20yes%20before%20you%20create%20a%20fine-tune%20or%20a%20batch.%0A-%20Use%20only%20the%20models%20and%20parameters%20the%20docs%20list.%20If%20the%20docs%20do%20not%20cover%20something%2C%20say%20so%20instead%20of%20guessing.%0A%0AWhat%20I%20want%20to%20do%3A%20)

Next

## Where to go from here

---

Source: https://gridlinegpu.com/docs
