Node.js and TypeScript
Start and follow fine-tuning runs from Node or TypeScript by calling the Langtrain REST API with fetch. No extra package is needed.
- Node 18+
- TypeScript
- fetch
Authenticate
Create an API key in the dashboard under API keys and put it in LANGTRAIN_API_KEY. Keep it on the server; never ship it to a browser.
python
1export LANGTRAIN_API_KEY=sk-lt-...
Start a run from TypeScript
Upload your dataset in the dashboard and copy its ID, then start a run. The API reference lists every field.
python
1const API = "https://api.langtrain.xyz/api/v1";2const headers = {3 "X-API-Key": process.env.LANGTRAIN_API_KEY!,4 "Content-Type": "application/json",5};67const res = await fetch(`${API}/training/jobs`, {8 method: "POST",9 headers,10 body: JSON.stringify({11 base_model: "meta-llama/Llama-3.1-8B-Instruct",12 dataset_id: "YOUR_DATASET_ID",13 training_method: "qlora",14 }),15});16if (!res.ok) throw new Error(`${res.status}: ${await res.text()}`);17const job = await res.json();
Wait for it to finish
Poll the run until its status is completed, failed or cancelled.
python
1let run = job;2while (!["completed", "failed", "cancelled"].includes(run.status)) {3 await new Promise((r) => setTimeout(r, 10_000));4 run = await (await fetch(`${API}/training/jobs/${job.id}`, { headers })).json();5 console.log(run.status, run.progress);6}