> For the complete documentation index, see [llms.txt](https://docs.flora.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flora.ai/api/reference/loras/trainlora.md).

# Train and save a LoRA Style

Train and save a LoRA Style with the FLORA API: POST /loras/train.

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.

```http
POST https://app.flora.ai/api/v1/loras/train
```

* **Auth:** API key as a bearer token, `Authorization: Bearer $FLORA_API_KEY`. See [Authentication](https://docs.flora.ai/api/platform/authentication.md).
* **TypeScript SDK:** `client.loras.train()`.
* **Idempotency:** optional `Idempotency-Key` header. See [Idempotency](https://docs.flora.ai/api/platform/idempotency.md).
* **Operation ID:** `trainLora`.

## Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST 'https://app.flora.ai/api/v1/loras/train' \
  -H "Authorization: Bearer $FLORA_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "workspace_id": "ws_abc123",
  "project_id": "prj_abc123",
  "name": "<name>",
  "base_model": "<base_model>",
  "image_urls": [
    "<imageUrl>"
  ],
  "client_token": "<client_token>"
}'
```

{% endtab %}

{% tab title="TypeScript SDK" %}

```typescript
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);
```

{% endtab %}
{% endtabs %}

## Request body

Required.

| Field            | Type                               | Required | Description                                                                                                                                                                                                                                               |
| ---------------- | ---------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `workspace_id`   | string                             | Yes      | Workspace to authorize and bill for training. Pattern: `^ws_\S+$`. Example: `ws_abc123`.                                                                                                                                                                  |
| `project_id`     | string                             | Yes      | Project that owns the training run. Pattern: `^prj_\S+$`. Example: `prj_abc123`.                                                                                                                                                                          |
| `name`           | string                             | Yes      | Name of the saved Style. At least 1 character.                                                                                                                                                                                                            |
| `base_model`     | string                             | Yes      | LoRA base-model family key, such as flux-2 or krea-2, from the Flora Train dialog. At least 1 character.                                                                                                                                                  |
| `image_urls`     | array of string (uri)              | Yes      | Training images uploaded to Flora. The selected trainer enforces its own image-count range. External URLs must first be uploaded through the assets API. 1 to 100 items.                                                                                  |
| `captions`       | array of (string or null)          | No       | 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. At most 100 items.                                             |
| `trainer_params` | map of string or number or boolean | No       | 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.                               |
| `client_token`   | string                             | Yes      | 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. Pattern: `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`. |

## Responses

### 201: Training accepted, or the existing request recovered.

| Field          | Type           | Required | Description                                                                                                                          |
| -------------- | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `style_id`     | string or null | Yes      | Saved Style identifier; null when replaying a run whose Style was subsequently deleted. Pattern: `^sty_\S+$`. Example: `sty_abc123`. |
| `run_id`       | string         | Yes      | Training run identifier; poll GET /runs/{runId}. Pattern: `^run_\S+$`. Example: `run_abc123`.                                        |
| `workspace_id` | string         | Yes      | Workspace that owns the training run. Pattern: `^ws_\S+$`. Example: `ws_abc123`.                                                     |
| `project_id`   | string         | Yes      | Project that owns the training run. Pattern: `^prj_\S+$`. Example: `prj_abc123`.                                                     |
| `poll_url`     | string (uri)   | Yes      | URL for reading training progress and final charged cost                                                                             |

## Errors

Every error has the same body: `error.code`, `error.message`, and `error.fields` on validation errors. See [Errors](https://docs.flora.ai/api/platform/errors.md) for how to recover from each code.

| Status | Code                                         | Meaning                                                                             |
| ------ | -------------------------------------------- | ----------------------------------------------------------------------------------- |
| 400    | `invalid_json`, `input_validation_error`     | The body isn't valid JSON, or an input failed validation (`fields` lists each one). |
| 401    | `unauthorized`, `invalid_api_key`            | The API key is missing, invalid or revoked.                                         |
| 402    | `insufficient_credits`                       | The workspace balance is too low for this request.                                  |
| 403    | `forbidden`, `paid_plan_required`            | The key can't do this, or the workspace plan doesn't include it.                    |
| 404    | `not_found`                                  | The resource doesn't exist or isn't visible to this key.                            |
| 409    | `idempotency_duplicate`, `revision_conflict` | Duplicate `Idempotency-Key` or a stale `base_revision`.                             |
| 429    | `rate_limited`                               | Too many requests. Back off and retry.                                              |
| 500    | `unknown_error`, `internal_error`            | Something failed on FLORA's side. Retry with backoff.                               |
| 503    | `temporarily_unavailable`                    | Authorization is temporarily unavailable. Retry later.                              |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flora.ai/api/reference/loras/trainlora.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
