API reference
Start, follow and export fine-tuning runs from your own code. Every endpoint lives under https://api.langtrain.xyz/api/v1 and returns JSON.
Authentication
Create an API key in the dashboard under API keys; it is shown once. Send it in the X-API-Key header (or as Authorization: Bearer). Keep it in an environment variable, never in code.
python
1export LANGTRAIN_API_KEY=sk-lt-...23curl https://api.langtrain.xyz/api/v1/training/training-methods \4 -H "X-API-Key: $LANGTRAIN_API_KEY"
Datasets
Upload a dataset in the dashboard (Data), then copy its ID. Runs refer to datasets by ID. The format is chat JSONL, one conversation per line; see Datasets.
Start a run
POST /training/jobs
- base_model - a Hugging Face model ID
- dataset_id - from the dashboard
- training_method - qlora (default), lora, dora, sft, ia3, prefix, dpo, orpo or kto
- hyperparameters - optional: n_epochs, learning_rate, batch_size, max_seq_length, lora_rank, lora_alpha, lora_dropout
- name - optional
python
1curl -X POST https://api.langtrain.xyz/api/v1/training/jobs \2 -H "X-API-Key: $LANGTRAIN_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "name": "support-assistant",6 "base_model": "meta-llama/Llama-3.1-8B-Instruct",7 "dataset_id": "YOUR_DATASET_ID",8 "training_method": "qlora",9 "hyperparameters": { "n_epochs": 3, "learning_rate": 0.0002, "lora_rank": 16 }10 }'
Follow a run
GET /training/jobs/{id} returns the run: status (pending, running, completed, failed or cancelled), progress from 0 to 100, metrics such as loss, and error_message if it failed.GET /training/jobs/{id}/stream sends the same updates as server-sent events while it trains.
python
1curl https://api.langtrain.xyz/api/v1/training/jobs/$JOB_ID \2 -H "X-API-Key: $LANGTRAIN_API_KEY"34curl -N https://api.langtrain.xyz/api/v1/training/jobs/$JOB_ID/stream \5 -H "X-API-Key: $LANGTRAIN_API_KEY"
List and cancel runs
GET /training/jobs?organization_id=…&limit=10 lists a workspace's runs, newest first. POST /training/jobs/{id}/cancel stops a pending or running run.
python
1curl -X POST https://api.langtrain.xyz/api/v1/training/jobs/$JOB_ID/cancel \2 -H "X-API-Key: $LANGTRAIN_API_KEY"
Export the weights
POST /training/jobs/{id}/export merges the adapter into the base model and pushes the result to a Hugging Face repo you own. Fields: repo_id (required), private (default true), merge_lora (default true), hf_token (or the one saved in your settings). Check progress with GET /training/jobs/{id}/export/{export_id}/status.
python
1curl -X POST https://api.langtrain.xyz/api/v1/training/jobs/$JOB_ID/export \2 -H "X-API-Key: $LANGTRAIN_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{"repo_id": "you/support-assistant", "private": true}'
Errors
Errors come back with an HTTP status and a JSON detail message:
- 401 - missing or invalid API key
- 404 - no run with that ID
- 422 - the request body failed validation; detail says which field