Skip to main content

Fine-Tuning

Fine-Tuning​

@toothfairyai/sdk@latest…

Fine-Tuning Management Module Dataset generation, training lifecycle, the adapter registry (versioning/rollback) and serving modes for fine-tuned models.

Accessed via client.finetuning.

Methods​

MethodHTTPEndpoint
listModelsGETGET /models
listJobsGETGET /jobs
generateDatasetPOSTPOST /dataset
getStatusGETGET /status/{id}
startTrainingPOSTPOST /start/{id}
cancelTrainingPOSTPOST /cancel/{id}
downloadDatasetGETGET /dataset/{id}
listAdaptersGETGET /adapters
createAdapterVersionPOSTPOST /adapters/{id}/version
rollbackAdapterPOSTPOST /adapters/{id}/rollback
getServingGETGET /serving/{id}
setServingPOSTPOST /serving/{id}
servingPowerPOSTPOST /serving/{id}/power

listModels​

List trainable models with their configurations

async listModels()

Endpoint: GET /models · AI service

Example​

const result = await client.finetuning.listModels();

listJobs​

List fine-tuning jobs for the workspace

async listJobs(status?: FinetuningJobStatus | string)

Endpoint: GET /jobs · Fine-Tuning service

Example​

const result = await client.finetuning.listJobs();

generateDataset​

Generate a training dataset from workspace documents

async generateDataset(
data: {
name: string;
base_model: string;
training_type?: string;
topics?: string[];
test_size?: number;
test_size_threshold?: number;
rlvr?: boolean;
description?: string;
}
)

Endpoint: POST /dataset · Fine-Tuning service

Request fields​

FieldTypeRequiredDescription
namestringyesHuman-readable name for the training job
training_typestringnoTraining method to use. Each method maps to a document type:
  • conversationalTraining (SFT) — uses Conversation documents
  • generativeTraining (DPO) — uses Preference documents
  • grpoTraining (GRPO) — uses Conversation documents (model self-generates); with rlvr: true or config.rl.enabled it instead builds a task manifest from rlTask documents (see the TaskSpec schema)
  • ktoTraining (KTO) — uses Preference documents (unpaired)
  • continuedPretraining (CPT) — uses Conversation documents (plain text)

Defaults to conversationalTraining. Note: the REST endpoint does not enforce the enum at request time (validation occurs in the async worker); send one of the listed values.

Allowed: conversationalTraining, generativeTraining, grpoTraining, ktoTraining, continuedPretraining | | base_model | string | yes | Base model to fine-tune (canonical id from the /models endpoint) | | topics | array<string> | no | Optional list of topic IDs to filter documents by | | test_size | number | no | Fraction of the dataset to reserve as the test split (0.0–1.0) | | test_size_threshold | integer | no | Minimum number of examples required in the test split | | rlvr | boolean | no | RL with verifiable rewards. Only valid with training_type: grpoTraining — builds a task manifest from the workspace's rlTask documents (each carrying a TaskSpec: prompt + checker) instead of a conversation dataset. Configure the RL run itself via config.rl on /start. | | description | string | no | Optional human-readable description of the training job |

Example​

const result = await client.finetuning.generateDataset('…');

getStatus​

Get detailed status of a fine-tuning job

async getStatus(trainingLogId: string)

Endpoint: GET /status/{id} · Fine-Tuning service

Response fields​

FieldTypeDescription
training_log_idstringTraining log ID
statusstringCurrent job status. Lifecycle: dispatched → inProgress → datasetReady → fineTuningRequested → training → completed (or inError).

Allowed: dispatched, inProgress, datasetReady, fineTuningRequested, training, completed, inError, cancellationRequested | | name | string | Job name | | training_type | string | Training method | | created_at | string | Job creation timestamp (ISO 8601) | | duration | integer | Training duration in seconds (present once training has progressed) | | dataset | object | Dataset paths (present after dataset generation reaches the relevant stage) | | compute_uoi | number | UoI consumed by the training job (present when status is completed) | | model_id | string | S3 path to the fine-tuned LoRA adapter (present when status is completed) | | base_model | string | Base model used for training (present when status is completed) | | metrics_summary | object | Final training metrics (present when status is completed) | | downloads | object | Presigned download URLs (present when status is completed) | | error | object | Error detail (present when status is inError) | | config_warnings | array<string> | Why the executed training configuration differs from what was originally submitted — e.g. a learning rate that was clamped into the model's safe band, or a deprecated key that was ignored. Written when the run is dispatched. Omitted when empty. |

Example​

const result = await client.finetuning.getStatus('agent-id');

startTraining​

Start a fine-tuning training job The job must be in 'datasetReady' status.

async startTraining(trainingLogId: string, config?: Record<string, any>)

Endpoint: POST /start/{id} · Fine-Tuning service

Request fields​

FieldTypeRequiredDescription
configobjectnoTraining configuration overrides merged over the existing training configuration. Keys not present retain their prior values. Every accepted key is listed in x-recognized-config-keys; an unrecognised key is REJECTED with 400 (it used to be persisted and silently ignored, which made learningRate a no-op that returned 200). Suffixed keys use the family matching the training_type: RC for the SFT family (conversationalTraining, grpoTraining, continuedPretraining) and GN for the DPO family (generativeTraining, ktoTraining). Learners are bounded per model size — see maxLearningRateSft / maxLearningRateDpo on GET /models; a value above the band for the job's base model is rejected with 400. Bare spellings such as learningRate are accepted for backwards compatibility but ignored (reported in warnings). Evaluation and checkpoint frequency are controllable via evalStrategy*/evalSteps*, saveStrategy*/saveSteps*, and checkpointsNumber* (save_total_limit).

Example​

const result = await client.finetuning.startTraining('agent-id');

cancelTraining​

Cancel a running fine-tuning job

async cancelTraining(trainingLogId: string): Promise<

Endpoint: POST /cancel/{id} · Fine-Tuning service

Example​

const result = await client.finetuning.cancelTraining('agent-id');

downloadDataset​

Get a presigned download URL for a job's generated dataset

async downloadDataset(
trainingLogId: string,
which: 'dataset' | 'test' = 'dataset'
)

Endpoint: GET /dataset/{id} · Fine-Tuning service

Example​

const result = await client.finetuning.downloadDataset('agent-id');

listAdapters​

List completed LoRA adapters for the workspace (adapter registry)

async listAdapters(
options: {
baseModel?: string;
limit?: number;
nextToken?: string;
} = {}
)

Endpoint: GET /adapters · Fine-Tuning service

Example​

const result = await client.finetuning.listAdapters();

createAdapterVersion​

Snapshot a completed adapter as an immutable version (vN)

async createAdapterVersion(trainingLogId: string, label?: string)

Endpoint: POST /adapters/{id}/version · Fine-Tuning service

Request fields​

FieldTypeRequiredDescription
labelstringnoOptional human-readable label for this version (e.g. "best-held-out", "promoted-2026-07").

Response fields​

FieldTypeDescription
adapter_idstringTraining log ID of the snapshotted adapter
versionintegerThe version number assigned (1, 2, 3, …)
snapshotobjectThe immutable version record written to the manifest
manifest_keystringS3 key of the manifest storing this adapter's versions

Example​

const result = await client.finetuning.createAdapterVersion('agent-id');

rollbackAdapter​

Get presigned artefacts to roll back to a pinned adapter version The Chat inference layer performs the actual served-adapter swap; this endpoint returns the pinned version's weights + config URLs.

async rollbackAdapter(trainingLogId: string, version?: number)

Endpoint: POST /adapters/{id}/rollback · Fine-Tuning service

Request fields​

FieldTypeRequiredDescription
versionintegernoVersion number to roll back to (from a prior /version call). Omit to use the latest snapshot.

Response fields​

FieldTypeDescription
adapter_idstringTraining log ID the rollback was requested on
rolled_back_tointegerThe version that was resolved (explicit version or latest); null when the latest snapshot was used implicitly
target_adapter_idstringThe training log ID whose S3 prefix holds the target weights. May differ from adapter_id when rolling back along a parent-adapter lineage (a snapshot taken from a different completed job).
weights_urlstringPresigned URL (valid 1h) to the pinned adapter_model.safetensors
config_urlstringPresigned URL (valid 1h) to the pinned adapter_config.json, or null if the config file is absent in S3
base_modelstringBase model of the resolved snapshot (from the manifest, falling back to the training meta)
inference_templatestringInference chat-template key to use for serving this base model
notestringExplains that the inference switch is performed by the Chat routing layer; this endpoint only returns the pinned adapter artefacts.
available_versionsarray<integer>Present only in the 404 response body (not on 200) when the requested version was not found — lists all known version numbers to aid retry. Returned here for reference.

Example​

const result = await client.finetuning.rollbackAdapter('agent-id');

getServing​

Get the serving config and live lane state for a fine-tuned model

async getServing(trainingLogId: string)

Endpoint: GET /serving/{id} · Fine-Tuning service

Response fields​

FieldTypeDescription
modelIdstringThe fine-tuned model's API name (usable as model on chat-completions)
trainingLogIdstringTraining log ID that produced this fine-tuned model
base_modelstringTrainable base the model was fine-tuned from
inference_basestringCanonical checkpoint the lane serves
modestringCurrent serving mode

Allowed: on-demand, scheduled, always | | schedule | object | A recurring warm window in the given IANA timezone, or, for maximum flexibility, a cron rule. end must be later than start (overnight windows are not supported). If cron is set it takes precedence over the days/start/end window. | | lane | object | Live lane state for the fine-tuned model's inference lane. | | warm_seconds_accrued | integer | Warm seconds accrued in the current billing day | | warm_seconds_note | string | Billing note: warm hours bill daily in 1-hour units (minimum 1) at the size-tier hourly rate | | adapter | object | Which saved artifact of the run is currently being served. A checkpoint is a complete adapter set saved during training; it is loaded into the same serving lane as the final adapter (no restart, no extra cost). | | available_adapters | array<object> | Every artifact this run can serve — the final adapter first, then saved checkpoints newest step first (capped at 20). Mirrors downloads.checkpoints on GET /status, minus presigned URLs. |

Example​

const result = await client.finetuning.getServing('agent-id');

setServing​

Set the serving mode for a fine-tuned model

async setServing(
trainingLogId: string,
mode: 'on-demand' | 'scheduled' | 'always' = 'on-demand',
schedule?: Record<string, any>,
adapter?: string
)

Endpoint: POST /serving/{id} · Fine-Tuning service

Request fields​

FieldTypeRequiredDescription
modestringnoon-demand (default when omitted — wakes on first request, sleeps after ~15 min idle, $0 while idle), scheduled (warm inside recurring time windows), or always (kept warm continuously).

Allowed: on-demand, scheduled, always | | schedule | object | no | A recurring warm window in the given IANA timezone, or, for maximum flexibility, a cron rule. end must be later than start (overnight windows are not supported). If cron is set it takes precedence over the days/start/end window. | | adapter | string | no | Which saved artifact of this run to serve. Omit (or send "final" / "lora_adapter") for the run's final adapter — the historical behaviour. Send "checkpoint-<step>" (exactly as named in available_adapters) to serve that intermediate checkpoint instead. The checkpoint must have both adapter_model.safetensors and adapter_config.json in storage; otherwise the call is rejected with 400 and the list of servable checkpoints. |

Response fields​

FieldTypeDescription
modelIdstringThe fine-tuned model's API name (usable as model on chat-completions)
trainingLogIdstringTraining log ID that produced this fine-tuned model
modestringThe stored serving mode

Allowed: on-demand, scheduled, always | | schedule | object | A recurring warm window in the given IANA timezone, or, for maximum flexibility, a cron rule. end must be later than start (overnight windows are not supported). If cron is set it takes precedence over the days/start/end window. | | adapter | object | The artifact now being served. | | previous_adapter | string | The artifact that was served before this call | | lane_recycled | boolean | Whether the serving lane had to be rebuilt to apply the switch. A lane created before checkpoint support runs an older resolver image and cannot load a checkpoint; it is recycled automatically (one cold start, not billed). | | mirrored_to_training_log | boolean | Whether the config was also mirrored onto the TrainingLog entity (inside trainingMeta) | | note | string | scheduled/always modes take effect within ~2 minutes (the serving monitor picks up the change). An adapter switch is lazy: the chat layer picks up the new artifact within ~60 seconds and the lane loads it on the next request (~30 s, once). |

Example​

const result = await client.finetuning.setServing('agent-id');

servingPower​

Turn a fine-tuned model on or off right now state='on' wakes and holds the lane warm for hours (minimum 1); state='off' releases the hold.

async servingPower(trainingLogId: string, state: 'on' | 'off', hours?: number)

Endpoint: POST /serving/{id}/power · Fine-Tuning service

Request fields​

FieldTypeRequiredDescription
statestringyeson = wake and hold warm for hours; off = release the hold now

Allowed: on, off | | hours | integer | no | Hours to hold the lane warm (minimum 1, 1-hour billing units) |

Response fields​

FieldTypeDescription
modelIdstringThe fine-tuned model's API name
trainingLogIdstringTraining log ID that produced this fine-tuned model
statestringThe power state applied

Allowed: on, off | | hours | integer | Hours booked (0 for off) | | lane | object | Lane result returned by the serving power endpoint. With state: on, the orchestrator returns the lane's status plus pinned_until (epoch seconds the lane is held warm until). With state: off, it returns status: unpinned and the lane idles out per normal rules (up to 15 min grace). | | billing_note | string | Warm hours accrue while held and bill daily in 1-hour units (minimum 1) |

Example​

const result = await client.finetuning.servingPower('agent-id', …);