Skip to content

Fine-tuning

Training data is some of the most sensitive material a team sends out. Through the gateway the training file's upload is recorded (name, size, fingerprint), and the job reaches the provider that holds it.

What it is

OpenAI's fine-tuning API (/v1/fine_tuning/jobs: create, retrieve, list, cancel, events, checkpoints, pause, resume). A job refers to training files by id, so the gateway sends it to the provider that holds your files, by the same rule as Files and uploads: OpenAI or Azure OpenAI.

The two settings

The same as for the OpenAI SDK: base address https://<your-gateway>/v1 and your Vidai key. See OpenAI SDK for Python.

A minimal call

from openai import OpenAI

client = OpenAI()

training = client.files.create(file=open("train.jsonl", "rb"), purpose="fine-tune")
job = client.fine_tuning.jobs.create(training_file=training.id, model="gpt-4o-mini-2024-07-18")

job = client.fine_tuning.jobs.retrieve(job.id)
print(job.status, job.fine_tuned_model)
import fs from "node:fs";
import OpenAI from "openai";

const client = new OpenAI();

const training = await client.files.create({ file: fs.createReadStream("train.jsonl"), purpose: "fine-tune" });
let job = await client.fineTuning.jobs.create({ training_file: training.id, model: "gpt-4o-mini-2024-07-18" });

job = await client.fineTuning.jobs.retrieve(job.id);
console.log(job.status, job.fine_tuned_model);
curl https://<your-gateway>/v1/fine_tuning/jobs \
  -H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" \
  -d '{"training_file": "file-…", "model": "gpt-4o-mini-2024-07-18"}'

The job's base model needn't be one of the gateway's models: it's the provider's name for the model to train. If your key is limited to some models, though, the base model is checked against that list, and a model the key may not use gets 403 model_not_allowed.

To call the fine-tuned model afterwards (ft:gpt-4o-mini-…), an admin adds it. If the provider lists it, Find models on the provider shows it, and the admin switches it on; if not, they add it by hand with Models › Add model and the provider's model id (Add a model). Then they price it, and it's called through Chat Completions.

Reading what the gateway did

Every call carries x-vidai-request-id (paste it into Request logs › Request reference). The training itself runs at the provider.

Errors

Status Code When
403 model_not_allowed Your key is limited to some models and the base model isn't one of them
400 bad_request Several providers could serve files and none is chosen
400 provider_override_not_allowed x-provider names a provider that serves none of your key's models

The other codes are those of Chat Completions.

What goes through the gateway

Feature Through the gateway
Jobs: create, retrieve, list, cancel, events, checkpoints, pause, resume Yes, to the provider that holds your files
Fine-tuning on other providers No

Check it works in a minute

curl https://<your-gateway>/v1/fine_tuning/jobs -H "Authorization: Bearer $OPENAI_API_KEY"

A list (perhaps empty) means the address and key are right.

Good to know

  • On Azure OpenAI, jobs go to the resource's own fine-tuning address with the provider's API version.
  • Guardrails don't read training files.