Guide

# Distillation

Turn a large model into a small one you own. Use our teacher and student models, or bring answers your own teacher already wrote. Then your batches run on the student.

Paste it into your coding agent. It works out your task and data (or asks), uses our teacher or your own answers, and shows you the cost before anything runs.

See the prompt

```
Read https://gridlinegpu.com/docs/distillation.md, then use it to distill a small model for me on Gridline.

1. Work out what the model should do and where my data is from this project and our conversation. If either is unclear, ask me.
2. Ask whether I already have answers from a teacher model. If I do, follow "Bring your own answers". If not, use a distillation job with Gridline's teacher and student.
3. Before anything is charged, show me the cost and wait for my yes. A distillation job with "dry_run": true returns its quote; cap the real job at that total with spend_cap_usd. With my own answers, send the fine-tuning job with "dry_run": true first: it returns the quote and creates nothing.
4. When it finishes, tell me how often the student agrees with the teacher on the held-out prompts.

The API key is in $GRIDLINE_TOKEN. Never print it.
```

## A cheaper model that beats your API bill.

Label your data with a large open teacher in one batch job, fine-tune a small open model on it, then run your batches on the model you own.

## How it works: distill, fine-tune, batch

Distillation trains a small model (the student) on the answers of a large model (the teacher). The student learns your task from the teacher's examples, then does it at a fraction of the size, so every batch after that costs less.

1. Your prompts
2. Teacher answers
3. Training files
4. Student trains
5. Your batches

Your prompts go to the teacher in one batch. Its answers become training files, the student is fine-tuned on them, and your batches run on the student.

1. Distill **A large teacher answers your prompts**

One batch on the teacher, over every prompt you upload.

A training file and a held-out validation file, made from its answers.
2. Fine-tune **A small student learns from the answers**

One LoRA fine-tuning job on the student, on the training file.

An ft: model in your account, yours to run here or download.
3. Batch **Your traffic runs on the student**

Batches on the ft: model, at the student's rates.

Answers in the teacher's style, from a model a fraction of its size.

It is one call to `POST /distillation/jobs`, or five calls to the Batch and fine-tuning APIs if you want to see each file. Both use Gridline's base URL with a Gridline token as the API key (see the [quickstart](https://gridlinegpu.com/docs#access) for the token):

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

This guide uses `qwen3.8-27b` (Apache-2.0) as the teacher and `qwen3.5-9b` as the student. Any of these fine-tuning bases can be the student: qwen3.5-9b, qwen3.5-4b, qwen3.5-2b, qwen3.5-0.8b, gpt-oss-20b and qwen3-8b. Older models, still served: qwen2.5-0.5b-instruct, qwen2.5-1.5b-instruct, qwen2.5-7b-instruct, llama-3.1-8b-instruct and mistral-7b-instruct-v0.3. You are responsible for having the right to train on what you upload, including model outputs.

## One call

A distillation job runs every stage for you. Upload your prompts as a `purpose=batch` file, one `{"messages": [...]}` line each (see [Recipes](https://gridlinegpu.com/docs/distillation#recipes)), then create the job:

```
curl https://api.gridlinegpu.com/openai/v1/distillation/jobs \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"teacher": "qwen3.8-27b", "student": "qwen3.5-9b", "prompts_file": "file-...", "spend_cap_usd": 5, "dry_run": true}'
```

With `dry_run` the answer is the quote: what each step can charge at most, and the total. Without it, the job runs the teacher batch, makes the training files, fine-tunes the student and runs the student on the held-out prompts.

When not every prompt fits the fine-tuning time limit, `spend_cap_usd` or your credit, the job picks a seeded random sample of the prompts that fit before the teacher runs, so the teacher is never paid for a row that will not train. Each answer is estimated at `max_tokens` times the measured answer size of the teacher. The`selection` field of the quote says how many prompts train, what limited them and how to train on all of them, and the job shows the same. If the answers run longer than estimated, the job trains on a seeded sample of the rows that fit and keeps every row in the first training file.

From Python:

```
from gridlinegpu import GridlineClient

job = GridlineClient().distillation.create(
    teacher="qwen3.8-27b", student="qwen3.5-9b",
    prompts="prompts.jsonl", spend_cap_usd=5)
```

Or from the command line:

```
gridline distill --teacher qwen3.8-27b --student qwen3.5-9b prompts.jsonl --max-usd 5 --wait
```

| Field | Default | What it does |
| --- | --- | --- |
| `teacher` | Required | A chat model GET /v1/models lists for your account. |
| `student` | Required | A fine-tuning base, from the list above. |
| `prompts_file` | Required | A purpose=batch file, one prompt a line: {"messages": [...]} ending with the user's turn, or a batch request line. |
| `n_epochs` | 1 | Epochs over the training rows. |
| `method` | The student's default | "lora" or "qlora". |
| `lora_rank` | 16 | The student's LoRA rank. |
| `max_tokens` | 1,024, or the teacher's limit if lower | The longest answer the teacher writes. |
| `temperature` | The teacher's default | The teacher's sampling temperature, from 0 to 2. |
| `validation_split` | 0.1 | The share of prompts held out for the validation file and the student batch. |
| `run_student_batch` | true | Run the fine-tuned model on the held-out prompts. |
| `keep_truncated` | false | true trains on teacher answers that stopped at max_tokens. Off, they are left out (and still charged by the teacher batch). |
| `student_system` | None | The student's system message: "" for none, or a short text in place of yours. The teacher still answers your prompts as written. |
| `spend_cap_usd` | None | The most the job may charge. When not every prompt fits it, the teacher gets a seeded random sample that does (the quote's selection says how many, and the cap that trains on all); refused only when fewer than the minimum rows fit. |
| `dry_run` | false | true returns the quote and creates nothing. |
| `metadata` | None | Up to 16 string pairs, kept on the job. |

Each step is an ordinary batch, file or fine-tuning job in your account, billed as it always is. `GET /distillation/jobs/{id}` shows each step's ids, status and charge, and the `ft:` model. `POST /distillation/jobs/{id}/cancel` cancels the step that is running.

## Pick a teacher and a student

- **Bigger teacher, smaller student.** The student can only learn what the teacher gets right, so the teacher sets the ceiling. The student's size sets what every batch after training costs.
- **Start small, then step up.** Try the smallest student first and [check how often it agrees](https://gridlinegpu.com/docs/distillation#check) with the teacher. Move up a size only if it falls short.
- **One tokenizer for logit distillation.** Logit distillation (live) and on-policy distillation (next) need a teacher and student that share a tokenizer. The pairs below say which do.
- **Answers you may train on.** Every teacher here is Apache-2.0.

### Teachers

| Teacher | Size | Licence | Prompt plus answer | Longest answer | Batch, per 1M tokens |
| --- | --- | --- | --- | --- | --- |
| `gpt-oss-120b` | 117B, 5.1B active | Apache-2.0 | 4,096 tokens | 1,024 tokens | $0.06 in, $0.28 out; $1.00 a batch at least |
| `qwen3.8-27b` | 27B | Apache-2.0 | 8,192 tokens | 1,024 tokens | $0.25 in, $1.00 out; $0.20 a batch at least |
| `inkling-2-mini` | 26.4B, 3.4B active | Apache-2.0 | 16,384 tokens | 4,096 tokens | $0.25 in, $0.60 out; $1.00 a batch at least |
| `gemma4-26b-a4b-it` | 26B, 4B active | Apache-2.0 | 8,192 tokens | 1,024 tokens | $0.05 in, $0.26 out; $0.50 a batch at least |
| `gpt-oss-20b` | 21B, 3.6B active | Apache-2.0 | 16,384 tokens | 4,096 tokens | $0.029 in, $0.12 out; $0.20 a batch at least |

### Students

| Student | Size | Generation | Fine-tune, per 1M trained tokens | Batches on its ft: models, per 1M tokens |
| --- | --- | --- | --- | --- |
| `qwen3.5-9b` | 9B | Latest | $0.35 | $0.05 in, $0.115 out |
| `qwen3.5-4b` | 4B | Latest | $0.27 | $0.03 in, $0.056 out |
| `qwen3.5-2b` | 2B | Latest | $0.20 | $0.022 in, $0.04 out |
| `qwen3.5-0.8b` | 0.8B | Latest | $0.15 | $0.015 in, $0.025 out |
| `gpt-oss-20b` | 21B, 3.6B active | Latest | $0.45 | $0.029 in, $0.12 out |
| `qwen3-8b` | 8B | Latest | $0.33 | $0.06 in, $0.14 out |
| `qwen2.5-0.5b-instruct` | 0.5B | Older, still served | $0.15 | $0.03 in, $0.05 out |
| `qwen2.5-1.5b-instruct` | 1.5B | Older, still served | $0.15 | $0.029 in, $0.049 out |
| `qwen2.5-7b-instruct` | 7B | Older, still served | $0.29 | $0.049 in, $0.115 out |
| `llama-3.1-8b-instruct` | 8B | Older, still served | $0.29 | $0.049 in, $0.115 out |
| `mistral-7b-instruct-v0.3` | 7B | Older, still served | $0.29 | $0.049 in, $0.115 out |

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

### Pairs to start with

| Teacher | Student | One tokenizer | Why |
| --- | --- | --- | --- |
| `qwen3.8-27b` | `qwen3.5-9b` | Yes | The pair this guide uses: the teacher takes long prompts, and both models share one tokenizer. |
| `gpt-oss-120b` | `qwen3.5-9b` | No | The largest teacher, for tasks the smaller ones get wrong. Its prompt plus answer must fit a shorter context. |
| `gpt-oss-120b` | `gpt-oss-20b` | Yes | One family end to end. The student is a mixture of experts with few active parameters. |

### Methods

| Method | Status | How it works |
| --- | --- | --- |
| Answer distillation | Live | The teacher writes an answer to each prompt and the student is fine-tuned on those answers. Works across model families. |
| Logit distillation | Live | Set "distillation_method": "logit". The student learns from the teacher's top 20 token probabilities as well as the token it chose, through a KD loss tuned by kd_alpha and kd_temperature. At the default kd_temperature of 1, the teacher's probability outside those top tokens counts as one extra bucket. At any other temperature the loss renormalises both sides over the top tokens alone, so that tail is left out. Supported for qwen3.8-27b to qwen3.5-9b, qwen3.5-4b, qwen3.5-2b and qwen3.5-0.8b, which share a tokenizer. On qwen3.5-9b it costs the same as answer distillation in our measurement. On qwen3.5-4b, 2b and 0.8b we have checked only that a logit job trains and serves end to end; we have not measured how well it does there. Every job reports its own eval loss, so compare it with an answer distillation run on your data. Answer distillation stays the default. |
| On-policy distillation | Next | The student writes its own answers and the teacher scores each token, so it learns from its own mistakes. Needs one tokenizer. |

## Recipes

A prompts file has one line per input. Put your instructions in the system message and the input in the user message, the same way on every line. Each job below also sets `student_system`, so the student learns to answer without the long instructions (see [Make the student's prompts shorter](https://gridlinegpu.com/docs/distillation#shorter-prompts)). Three starting points:

### Sort tickets into queues

Labels, intents, routing, moderation: one short answer from a fixed list. One line of the prompts file:

```
{"messages": [{"role": "system", "content": "Sort the support ticket into one queue: billing, refunds, login, bug, shipping or other. Answer with the queue name only."}, {"role": "user", "content": "I was charged twice for my November plan and want one of the charges back."}]}
```

The job, with settings that suit it:

```
{"teacher": "qwen3.8-27b", "student": "qwen3.5-9b", "prompts_file": "file-...", "max_tokens": 64, "temperature": 0, "student_system": "", "spend_cap_usd": 5, "dry_run": true}
```

Teachers that reason first count their reasoning toward max_tokens, so leave room above the answer itself.

### Pull fields into JSON

Invoices, contracts, emails, logs: the same fields out of every document. One line of the prompts file:

```
{"messages": [{"role": "system", "content": "Extract invoice_number, total and due_date from the email as one JSON object. Use null for a missing field. Answer with the JSON only."}, {"role": "user", "content": "Hi, attached is invoice INV-2207 for 1,240.00 EUR, payable by 15 December 2026. Thanks, Mia"}]}
```

The job, with settings that suit it:

```
{"teacher": "qwen3.8-27b", "student": "qwen3.5-9b", "prompts_file": "file-...", "max_tokens": 256, "temperature": 0, "student_system": "", "spend_cap_usd": 5, "dry_run": true}
```

By hand, pass require_json to POST /files/distill and answers that are not valid JSON are left out of training.

### Write support replies

Replies, summaries, rewrites: longer answers in your house style. One line of the prompts file:

```
{"messages": [{"role": "system", "content": "You answer customers of a photo-printing shop. Reply in under 120 words, warmly, and end with one clear next step."}, {"role": "user", "content": "My order 5521 says delivered but nothing arrived."}]}
```

The job, with settings that suit it:

```
{"teacher": "qwen3.8-27b", "student": "qwen3.5-9b", "prompts_file": "file-...", "max_tokens": 400, "student_system": "You answer customers of a photo-printing shop.", "spend_cap_usd": 5, "dry_run": true}
```

Read twenty of the teacher's answers before you train: the student copies their tone and length.

## Make the student's prompts shorter

The teacher needs your instructions: the label list, the policy, the answer format. The student, once trained on the teacher's answers, often does not. Set `student_system` and the student is trained without them, so every request it serves after that carries little more than the input.

- `"student_system": ""`: no system message. The student learns from the user's message alone.
- `"student_system": "<short text>"`: this system message instead of yours.
- Left out, the student is trained on your prompts exactly as the teacher saw them.

```
curl https://api.gridlinegpu.com/openai/v1/distillation/jobs \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"teacher": "qwen3.8-27b", "student": "qwen3.5-9b", "prompts_file": "file-...", "student_system": "", "spend_cap_usd": 5, "dry_run": true}'
```

From Python, pass `student_system=""` to `GridlineClient().distillation.create`; from the command line, `gridline distill --student-system ""`. By hand, send the same field to `POST /files/distill`.

The teacher always answers your prompts as written. The training rows, the held-out rows in the validation file and the student batch that answers them all use the student's shorter prompt, so [the agreement check](https://gridlinegpu.com/docs/distillation#check) measures the student as you will run it, and the quote counts the shorter rows.

For example, 1,000,000 requests on `qwen3.5-9b`, each answer 10 tokens, cost $91.15 with a 1,800-token prompt and $4.15 with the 60-token input alone, 21 times less.

Only the system message changes. Earlier turns of a conversation are kept, and instructions written inside the user's message stay there: move them to the system message if the student should learn them. If the student misses cases the long prompt covered, keep the part it needs in `student_system`.

## Bring your own answers

If you already have good answers to your prompts, from another model, your team or past tickets, skip the teacher batch and train the student on them. Three ways in:

### 1. Prompt and answer pairs

Write one line per pair: the prompt's messages, then the answer as the assistant's turn. That is a fine-tuning file as it stands; it needs at least 10 lines.

```
{"messages": [{"role": "user", "content": "I was charged twice for my November plan."}, {"role": "assistant", "content": "billing"}]}
```

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

Then create the fine-tuning job on it as in [step 4](https://gridlinegpu.com/docs/distillation#student), and run batches on the student as in [step 5](https://gridlinegpu.com/docs/distillation#batch).

### 2. A results file from another batch API

Upload the results file and the requests it answers, both as `purpose=batch`, and name both in `POST /files/distill`. It pairs them by `custom_id` and writes the training and validation files, as in [step 3](https://gridlinegpu.com/docs/distillation#distill):

```
curl https://api.gridlinegpu.com/openai/v1/files/distill \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"results_file": "file-...", "requests_file": "file-..."}'
```

It reads these formats, and tells which from the file (or pass `provider`):

| `provider` | Results file | Requests file |
| --- | --- | --- |
| `"openai"` | Batch output lines: {"custom_id", "response": {"body": {"choices": [...]}}}. A Gridline batch's output file is in this format. | Batch request lines on /v1/chat/completions: {"custom_id", "method", "url", "body": {"messages": [...]}}. |
| `"anthropic"` | Message batch result lines: {"custom_id", "result": {"type": "succeeded", "message": {"content": [...]}}}. Thinking blocks are left out. | Message batch request lines: {"custom_id", "params": {"system", "messages": [...]}}. |

### 3. A Gridline batch you already ran

Name the batch's `output_file_id` as `results_file` in [step 3](https://gridlinegpu.com/docs/distillation#distill), or as the fine-tuning job's `training_file`, which skips step 3.

Whichever way, you are responsible for having the right to train on the answers: check the terms of the model that wrote them.

## Step by step

The same job as five calls, for when you want to read the teacher's answers or the training files before going on. Each call is an ordinary Batch or fine-tuning call.

1. [Upload your prompts](https://gridlinegpu.com/docs/distillation#prompts) as batch input, `purpose=batch`.
2. [Run a batch on the teacher](https://gridlinegpu.com/docs/distillation#teacher), `qwen3.8-27b`.
3. [Call POST /files/distill](https://gridlinegpu.com/docs/distillation#distill) on the batch's output file. It writes a training file and a validation file.
4. [Create a fine-tuning job](https://gridlinegpu.com/docs/distillation#student) on the student with those files.
5. [Run batches](https://gridlinegpu.com/docs/distillation#batch) on the job's `ft:` model.

## 1. Upload prompts

Each line is a batch request to `/v1/chat/completions` on the teacher, as on the [Batch API](https://gridlinegpu.com/docs/batch-api). Its last message must be a user message. On `qwen3.8-27b` a system message may only come first.

```
{"custom_id": "q-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "qwen3.8-27b", "max_tokens": 512, "messages": [{"role": "system", "content": "Answer in one short paragraph."}, {"role": "user", "content": "Why does ice float on water?"}]}}
```

Set `max_tokens` high enough for a whole answer (`qwen3.8-27b` writes at most 1,024 tokens a request): an answer that stops at the limit is dropped in step 3 unless you pass `keep_truncated`.

```
curl https://api.gridlinegpu.com/openai/v1/files \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -F purpose=batch \
  -F file=@prompts.jsonl
```

## 2. Run the teacher

```
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"}'
```

Poll `GET /batches/{batch_id}` until its status is `completed`. Its `output_file_id` is the results file for the next step:

```
{"id": "batch_...", "object": "batch", "status": "completed", "input_file_id": "file-...", "output_file_id": "file-...", "request_counts": {"total": 1000, "completed": 1000, "failed": 0}, ...}
```

## 3. Make training files

```
curl https://api.gridlinegpu.com/openai/v1/files/distill \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"results_file": "file-..."}'
```

Each result becomes one training row: the request's messages, then the teacher's answer as the assistant message. The rows go to a training file and, held out, a validation file, both `purpose=fine-tune`. The same files and options always give the same rows. The body takes:

| Field | Default | What it does |
| --- | --- | --- |
| `results_file` | Required | The batch's output_file_id. An uploaded results file (purpose=batch) also works, with its requests_file. |
| `requests_file` | The batch's input file | The requests the results answer. Needed with an uploaded results file, and once the batch's input file is gone (it is kept 7 days after the batch). |
| `provider` | "auto" | The results file's format: "openai" (a Gridline batch's output file) or "anthropic". "auto" reads it from the file. |
| `require_json` | false | true drops answers that are not valid JSON. |
| `keep_truncated` | false | true keeps answers that stopped at max_tokens. |
| `eval_fraction` | 0.1 | The share of rows held out for the validation file, from 0 up to (not including) 1. |
| `seed` | 0 | Which rows are held out: an integer from 0 to 2,147,483,647. |
| `student_system` | None | The system message every row gets instead of the prompt's: "" for none, or a short text. See Make the student's prompts shorter. |
| `max_train_rows` | None | At most this many training rows, a seeded random sample (the seed's order, as the held-out rows are drawn). Set, rows past it or past the training-file limit are left out (counted in rows_over_limit) instead of the request being refused. |

Any other field is refused by name. The answer:

```
{
  "object": "gridline.distill",
  "converter": "gridline-distill/2",
  "provider": "openai",
  "training_file": {"id": "file-...", "object": "file", "purpose": "fine-tune", "filename": "distill-train.jsonl", ...},
  "validation_file": {"id": "file-...", "object": "file", "purpose": "fine-tune", "filename": "distill-validation.jsonl", ...},
  "results": 1000,
  "missing_results": 0,
  "dropped": {"truncated": 4},
  "train_rows": 897,
  "eval_rows": 99,
  "min_training_rows": 10
}
```

A result that cannot become a row is dropped and counted in `dropped` by reason: invalid_line, duplicate, unmatched, errored, refused, unsupported, truncated, empty, invalid_json, too_long and no_reasoning. `validation_file` is null when no row is held out. Each file names its sources in `gridline.derived_from`.

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request` | The body is not a JSON object, a field is unknown or out of range, or requests_file is missing with an uploaded results file. |
| 400 | `invalid_value` | results_file is not a batch output or batch file, or requests_file is not a batch file. |
| 404 | `not_found` | A file does not exist, or the batch's input file is gone: upload the requests and name them as requests_file. |
| 400 | `invalid_file_format` | The results file's format cannot be told (pass provider), the requests file is not valid, or no result could become a row. |
| 400 | `file_too_large` | The rows are over the 64 MiB training-file limit, or a file written would be over 200 MB: split the batch, or send max_train_rows to keep the rows that fit. |
| 413 | `file_too_large` | A file has over 50,000 lines, or the conversion ran over 120 seconds: split the batch. |
| 429 | `storage_limit_exceeded` | Your account holds the most files allowed, or its file storage is full: delete some files. |

## 4. Fine-tune the student

```
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-...", "validation_file": "file-...", "hyperparameters": {"n_epochs": 2}}'
```

The job needs at least 10 training rows (the answer's `min_training_rows`). Its quote, status and errors are as on the [Fine-tuning](https://gridlinegpu.com/docs/fine-tuning) page. When it is `succeeded`, its `fine_tuned_model` is the student, for example `ft:qwen3.5-9b:o3f9a1c2d4e5:7b2c9e41a0d3`.

Creating the job starts it. To see its quote and credit check first, send the same body with `dry_run` set to `true`: nothing is created, held or charged.

To skip step 3, name the batch's `output_file_id` as the job's `training_file`: the job converts it with the defaults first, and uses the held-out rows as its validation file when you name none. A dry run refuses this shortcut, because it would write files: make them in step 3 to see the quote.

## 5. Run the student

Batches on the `ft:` model work like any other: the same lines, with its name as `model`.

```
{"custom_id": "q-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "ft:qwen3.5-9b:o3f9a1c2d4e5:7b2c9e41a0d3", "max_tokens": 512, "messages": [{"role": "system", "content": "Answer in one short paragraph."}, {"role": "user", "content": "Why does ice float on water?"}]}}
```

Create the batch as in step 2. When it is `completed`, download the results:

```
curl https://api.gridlinegpu.com/openai/v1/files/file-.../content \
  -H "Authorization: Bearer $GRIDLINE_TOKEN" \
  -o results.jsonl
```

## Check the student

Before you move traffic, check the student on prompts it never trained on. The fine-tuning job reports its eval loss on the validation file. A distillation job also runs the student on those held-out prompts: its output line `eval-n` answers row n of the validation file, whose last message is the teacher's answer. Download both:

```
curl https://api.gridlinegpu.com/openai/v1/distillation/jobs/distjob-... \
  -H "Authorization: Bearer $GRIDLINE_TOKEN"
# stages.distill.validation_file_id    -> validation.jsonl (the teacher's answers)
# stages.student_batch.output_file_id  -> student.jsonl (the student's answers)
curl https://api.gridlinegpu.com/openai/v1/files/file-.../content -H "Authorization: Bearer $GRIDLINE_TOKEN" -o validation.jsonl
curl https://api.gridlinegpu.com/openai/v1/files/file-.../content -H "Authorization: Bearer $GRIDLINE_TOKEN" -o student.jsonl
```

Then count how often the student gives the teacher's answer:

```
import json

teacher = [json.loads(line)["messages"][-1]["content"].strip() for line in open("validation.jsonl")]

same = total = 0
for line in open("student.jsonl"):
    row = json.loads(line)
    n = int(row["custom_id"].removeprefix("eval-"))
    answer = row["response"]["body"]["choices"][0]["message"]["content"].strip()
    total += 1
    same += answer == teacher[n - 1]

print(f"The student agrees with the teacher on {same} of {total} held-out prompts")
```

An exact match suits labels and JSON. For longer answers, read a sample of the two side by side. If the student falls short, add prompts where it disagrees, or step up a size.

## Costs

The two batches and the fine-tuning job are each charged at their model's rates; `POST /files/distill` is not charged. For example, with every prompt 200 tokens and every answer 300:

| Step | Tokens | Charge |
| --- | --- | --- |
| Teacher batch, 1,000 prompts | 200,000 input, 300,000 output | $0.35 |
| Fine-tuning, 900 rows for 2 epochs | 900,000 trained | $0.50 (the minimum per job) |
| Student batch, 50,000 prompts | 10,000,000 input, 15,000,000 output | $2.225 |

$3.075 in all. The same 50,000 prompts on `qwen3.8-27b` would be $17.50. The student's answers are not the teacher's: [check the student](https://gridlinegpu.com/docs/distillation#check) before you switch.

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

## Questions

### Do I own the student?

Yes. It is an ft: model in your account: run batches on it here, or download it (see Fine-tuning).

### Which teachers can I use?

Any chat model GET /v1/models lists. The table above lists the Apache-2.0 teachers, whose terms let you train on their answers. For answers from any other model, check the terms of the model that wrote them.

### How many prompts do I need?

At least 10 training rows, and up to 50,000 prompts in one job. Prompts from your real traffic, with its odd cases, teach more than many near-copies.

### How long does it take?

Three jobs run one after another: the teacher batch, the fine-tune and the student batch. Each waits for a GPU, then runs. The job's events say which stage it is in.

### Is there a fee for distillation?

No. You pay for the two batches and the fine-tune at their rates, from your credits. A dry run shows the most the job can charge before anything runs.

## Limits

- A results or requests file holds at most 50,000 lines and 200 MB.
- The training file is at most 64 MiB, and a conversion runs at most 120 seconds. Past either, split the batch.
- The files `POST /files/distill` writes are kept 30 days and count toward your file limits.
- A batch's input file is kept 7 days after the batch ends; after that, name your uploaded requests as `requests_file`.

---

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