Skip to content

Train and save a LoRA Style

POST
/loras/train
import { FloraClient } from '@flora-ai/flora';
const client = new FloraClient({ apiKey: process.env['FLORA_API_KEY'] });
const lora = await client.loras.train({
workspace_id: 'ws_abc123',
project_id: 'prj_abc123',
name: '<name>',
base_model: '<base_model>',
image_urls: [
'<imageUrl>',
],
client_token: '<client_token>',
});
console.log(lora);

Trains a LoRA through the same dataset preparation, captioning defaults, authorization, billing and saved Style lifecycle as the web Train dialog. Upload image files through the assets API first, then pass their Flora URLs. Returns a run_id for GET /runs/{runId} and style_id for GET /loras/{styleId}; use the ready style_id as params.lora_id with a compatible inference model. Training spends workspace usage. Persist client_token before dispatch and reuse it with identical inputs to recover a lost response. The optional Idempotency-Key header separately rejects duplicate HTTP requests for two hours with idempotency_duplicate.

Error responses use the standard error body.

Media type application/json
object
workspace_id
required

Workspace to authorize and bill for training

string
/^ws_\S+$/
project_id
required

Project that owns the training run

string
/^prj_\S+$/
name
required

Name of the saved Style

string
>= 1 characters
base_model
required

LoRA base-model family key, such as flux-2 or krea-2, from the Flora Train dialog

string
>= 1 characters
image_urls
required

Training images uploaded to Flora. The selected trainer enforces its own image-count range. External URLs must first be uploaded through the assets API.

Array<string>
>= 1 items <= 100 items
captions

Optional per-image captions in image_urls order. Null or blank entries use the shared training flow’s fallback caption. Omit to use the same captioning defaults as the web Train dialog.

Array
<= 100 items
trainer_params

Model-specific training parameters, such as steps, learning_rate or captioning mode. Omitted parameters use the same defaults as the web Train dialog. Parameters are validated by the shared trainer preparation service.

object
key
additional properties
Any of:
string
client_token
required

Lowercase UUID for this logical training request. Persist it before submitting and reuse it with the same inputs after a lost response; do not create a new token for a retry.

string
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/

Training accepted, or the existing request recovered.

Media type application/json
object
style_id
required
Any of:

Saved Style identifier

string
/^sty_\S+$/
run_id
required

Training run identifier; poll GET /runs/{runId}

string
/^run_\S+$/
workspace_id
required

Workspace that owns the training run

string
/^ws_\S+$/
project_id
required

Project that owns the training run

string
/^prj_\S+$/
poll_url
required

URL for reading training progress and final charged cost

string format: uri
Example
{
"style_id": "sty_abc123",
"run_id": "run_abc123",
"workspace_id": "ws_abc123",
"project_id": "prj_abc123"
}