# Generations

## Start a generation

`client.generations.create(GenerationCreateParamsbody, RequestOptionsoptions?): GenerationCreateResponse`

**post** `/generate`

Starts a model generation using type, prompt, workspace_id, project_id, optional model endpoint ID, and optional model parameters. Use type=image|video|audio|text and model IDs returned by GET /models or list_models. Poll the returned run_id via GET /runs/{runId} for progress and outputs. Mutating public API requests support an optional Idempotency-Key header for client retries; duplicate keys within two hours return idempotency_duplicate.

### Parameters

- `body: GenerationCreateParams`

  - `project_id: string`

    Project identifier. Use the public API ID returned by list projects; it must start with prj_.

  - `prompt: string`

    Generation prompt

  - `type: "image" | "video" | "audio" | "text"`

    Generation type. Use "image", "video", "audio", or "text"; do not pass model families such as "t2i" or "i2v".

    - `"image"`

    - `"video"`

    - `"audio"`

    - `"text"`

  - `workspace_id: string`

    Workspace identifier. Use the public API ID returned by list workspaces; it must start with ws_.

  - `model?: string`

    Model endpoint ID, not a display name. Use list_models (or GET /models) to find accessible endpoint IDs for the requested type.

  - `params?: Record<string, unknown>`

    Model parameters

### Returns

- `GenerationCreateResponse`

  - `charged_cost: number`

    Cost charged in USD

  - `estimated_seconds: number | null`

  - `run_id: string`

    Run identifier

  - `type: "generation" | "technique" | "action"`

    Run type

    - `"generation"`

    - `"technique"`

    - `"action"`

  - `action?: Action | null`

    - `action_id: "split-text" | "find-and-replace-text" | "concat-text" | 34 more`

      Action identifier

      - `"split-text"`

      - `"find-and-replace-text"`

      - `"concat-text"`

      - `"ken-burns-video"`

      - `"color-grade-image"`

      - `"change-image-ar"`

      - `"rotate-image"`

      - `"flip-image"`

      - `"color-filter-image"`

      - `"color-tint-image"`

      - `"filter-color-image"`

      - `"blur-image"`

      - `"duplicate-image"`

      - `"side-by-side-composite"`

      - `"add-shape-to-image"`

      - `"generate-shape-image"`

      - `"add-text-to-image"`

      - `"generate-text-image"`

      - `"qr-code-generator"`

      - `"stitch-videos"`

      - `"split-video"`

      - `"extract-video-frames"`

      - `"color-grade-video"`

      - `"video-to-frame-grid"`

      - `"boomerang-video"`

      - `"reverse-video"`

      - `"video-to-long-exposure"`

      - `"video-effect"`

      - `"color-filter-video"`

      - `"speed-up-video"`

      - `"slow-down-video"`

      - `"duplicate-video"`

      - `"greenscreen-video"`

      - `"resize-video"`

      - `"change-video-ar"`

      - `"split-audio-from-video"`

      - `"merge-audio-into-video"`

  - `model?: Model | null`

    - `model_id: string`

      Model identifier

  - `poll_url?: string | null`

    URL to poll pending/running runs or fetch completed/failed run details.

  - `project_id?: string | null`

    Project identifier

  - `technique?: Technique | null`

    - `name: string`

      Technique name

    - `technique_id: string`

      Technique identifier

### Example

```typescript
import FLORA from '@flora-ai/flora';

const client = new FLORA({
  apiKey: process.env['FLORA_API_KEY'], // This is the default and can be omitted
});

const generation = await client.generations.create({
  project_id: 'prj_abc123',
  prompt: 'A cinematic product photo of a ceramic mug on a sunlit table',
  type: 'image',
  workspace_id: 'ws_abc123',
});

console.log(generation.run_id);
```

#### Response

```json
{
  "charged_cost": 0,
  "estimated_seconds": 0,
  "run_id": "run_abc123",
  "type": "generation",
  "action": {
    "action_id": "split-text"
  },
  "model": {
    "model_id": "t2i-flux-2-pro"
  },
  "poll_url": "https://example.com",
  "project_id": "prj_abc123",
  "technique": {
    "name": "name",
    "technique_id": "tech_abcd1234"
  }
}
```

## Get a run

`client.generations.retrieve(stringrunID, RequestOptionsoptions?): GenerationRetrieveResponse`

**get** `/runs/{runId}`

Returns status and completed output URLs for a public API run, including action runs started through POST /runs/action.

### Parameters

- `runID: string`

  Run identifier

### Returns

- `GenerationRetrieveResponse`

  - `created_at: number`

  - `progress: number`

  - `run_id: string`

    Run identifier

  - `status: "pending" | "running" | "completed" | "failed"`

    - `"pending"`

    - `"running"`

    - `"completed"`

    - `"failed"`

  - `charged_cost?: number`

    Cost charged in USD

  - `completed_at?: number`

  - `error_code?: string`

    Machine-readable run error code

  - `error_message?: string`

    Human-readable run error message

  - `outputs?: Array<Output>`

    - `output_id: string`

      Run output identifier

    - `type: "imageUrl" | "videoUrl" | "audioUrl" | 2 more`

      Run output media type

      - `"imageUrl"`

      - `"videoUrl"`

      - `"audioUrl"`

      - `"text"`

      - `"documentUrl"`

    - `url: string`

      Run output URL or text content

  - `poll_url?: string`

    URL to poll pending/running runs or fetch completed/failed run details.

  - `started_at?: number`

### Example

```typescript
import FLORA from '@flora-ai/flora';

const client = new FLORA({
  apiKey: process.env['FLORA_API_KEY'], // This is the default and can be omitted
});

const generation = await client.generations.retrieve('run_abc123');

console.log(generation.run_id);
```

#### Response

```json
{
  "created_at": 0,
  "progress": 0,
  "run_id": "run_abc123",
  "status": "pending",
  "charged_cost": 0,
  "completed_at": 0,
  "error_code": "provider_error",
  "error_message": "The provider failed to complete the generation.",
  "outputs": [
    {
      "output_id": "output_1",
      "type": "imageUrl",
      "url": "https://media.flora.ai/output.png"
    }
  ],
  "poll_url": "https://example.com",
  "started_at": 0
}
```

## List generation history

`client.generations.list(GenerationListParamsquery?, RequestOptionsoptions?): GenerationsCursorPage<GenerationListResponse>`

**get** `/generations`

Lists generation history for the authenticated caller, including pending, running, completed, and failed generations. Results are newest first and can be filtered by workspace_id, project_id, and status. Each item includes poll_url; use it to poll pending/running generations and to fetch completed or failed run details and outputs.

### Parameters

- `query: GenerationListParams`

  - `cursor?: string`

    Opaque cursor for fetching the next page

  - `limit?: number`

    Maximum number of results to return

  - `project_id?: string`

    Project identifier

  - `status?: "pending" | "running" | "completed" | "failed"`

    Run status filter

    - `"pending"`

    - `"running"`

    - `"completed"`

    - `"failed"`

  - `workspace_id?: string`

    Workspace identifier

### Returns

- `GenerationListResponse`

  - `created_at: number`

  - `generation_id: string`

    Run identifier

  - `progress: number`

  - `project_id: string`

    Project identifier

  - `run_id: string`

    Run identifier

  - `status: "pending" | "running" | "completed" | "failed"`

    - `"pending"`

    - `"running"`

    - `"completed"`

    - `"failed"`

  - `workspace_id: string`

    Workspace identifier

  - `charged_cost?: number`

    Cost charged in USD

  - `completed_at?: number`

  - `error_code?: string`

    Machine-readable run error code

  - `error_message?: string`

    Human-readable run error message

  - `model?: Model`

    - `model_id: string | null`

      Model identifier

  - `outputs?: Array<Output>`

    - `output_id: string`

      Run output identifier

    - `type: "imageUrl" | "videoUrl" | "audioUrl" | 2 more`

      Run output media type

      - `"imageUrl"`

      - `"videoUrl"`

      - `"audioUrl"`

      - `"text"`

      - `"documentUrl"`

    - `url: string`

      Run output URL or text content

  - `poll_url?: string`

    URL to poll pending/running runs or fetch completed/failed run details.

  - `started_at?: number`

### Example

```typescript
import FLORA from '@flora-ai/flora';

const client = new FLORA({
  apiKey: process.env['FLORA_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const generationListResponse of client.generations.list()) {
  console.log(generationListResponse.generation_id);
}
```

#### Response

```json
{
  "generations": [
    {
      "created_at": 0,
      "generation_id": "run_abc123",
      "progress": 0,
      "project_id": "prj_abc123",
      "run_id": "run_abc123",
      "status": "pending",
      "workspace_id": "ws_abc123",
      "charged_cost": 0,
      "completed_at": 0,
      "error_code": "provider_error",
      "error_message": "The provider failed to complete the generation.",
      "model": {
        "model_id": "t2i-flux-2-pro"
      },
      "outputs": [
        {
          "output_id": "output_1",
          "type": "imageUrl",
          "url": "https://media.flora.ai/output.png"
        }
      ],
      "poll_url": "https://example.com",
      "started_at": 0
    }
  ],
  "meta": {
    "next_cursor": "eyJvZmZzZXQiOjIwfQ",
    "total_estimate": 0
  }
}
```

## Domain Types

### Generation Create Response

- `GenerationCreateResponse`

  - `charged_cost: number`

    Cost charged in USD

  - `estimated_seconds: number | null`

  - `run_id: string`

    Run identifier

  - `type: "generation" | "technique" | "action"`

    Run type

    - `"generation"`

    - `"technique"`

    - `"action"`

  - `action?: Action | null`

    - `action_id: "split-text" | "find-and-replace-text" | "concat-text" | 34 more`

      Action identifier

      - `"split-text"`

      - `"find-and-replace-text"`

      - `"concat-text"`

      - `"ken-burns-video"`

      - `"color-grade-image"`

      - `"change-image-ar"`

      - `"rotate-image"`

      - `"flip-image"`

      - `"color-filter-image"`

      - `"color-tint-image"`

      - `"filter-color-image"`

      - `"blur-image"`

      - `"duplicate-image"`

      - `"side-by-side-composite"`

      - `"add-shape-to-image"`

      - `"generate-shape-image"`

      - `"add-text-to-image"`

      - `"generate-text-image"`

      - `"qr-code-generator"`

      - `"stitch-videos"`

      - `"split-video"`

      - `"extract-video-frames"`

      - `"color-grade-video"`

      - `"video-to-frame-grid"`

      - `"boomerang-video"`

      - `"reverse-video"`

      - `"video-to-long-exposure"`

      - `"video-effect"`

      - `"color-filter-video"`

      - `"speed-up-video"`

      - `"slow-down-video"`

      - `"duplicate-video"`

      - `"greenscreen-video"`

      - `"resize-video"`

      - `"change-video-ar"`

      - `"split-audio-from-video"`

      - `"merge-audio-into-video"`

  - `model?: Model | null`

    - `model_id: string`

      Model identifier

  - `poll_url?: string | null`

    URL to poll pending/running runs or fetch completed/failed run details.

  - `project_id?: string | null`

    Project identifier

  - `technique?: Technique | null`

    - `name: string`

      Technique name

    - `technique_id: string`

      Technique identifier

### Generation Retrieve Response

- `GenerationRetrieveResponse`

  - `created_at: number`

  - `progress: number`

  - `run_id: string`

    Run identifier

  - `status: "pending" | "running" | "completed" | "failed"`

    - `"pending"`

    - `"running"`

    - `"completed"`

    - `"failed"`

  - `charged_cost?: number`

    Cost charged in USD

  - `completed_at?: number`

  - `error_code?: string`

    Machine-readable run error code

  - `error_message?: string`

    Human-readable run error message

  - `outputs?: Array<Output>`

    - `output_id: string`

      Run output identifier

    - `type: "imageUrl" | "videoUrl" | "audioUrl" | 2 more`

      Run output media type

      - `"imageUrl"`

      - `"videoUrl"`

      - `"audioUrl"`

      - `"text"`

      - `"documentUrl"`

    - `url: string`

      Run output URL or text content

  - `poll_url?: string`

    URL to poll pending/running runs or fetch completed/failed run details.

  - `started_at?: number`

### Generation List Response

- `GenerationListResponse`

  - `created_at: number`

  - `generation_id: string`

    Run identifier

  - `progress: number`

  - `project_id: string`

    Project identifier

  - `run_id: string`

    Run identifier

  - `status: "pending" | "running" | "completed" | "failed"`

    - `"pending"`

    - `"running"`

    - `"completed"`

    - `"failed"`

  - `workspace_id: string`

    Workspace identifier

  - `charged_cost?: number`

    Cost charged in USD

  - `completed_at?: number`

  - `error_code?: string`

    Machine-readable run error code

  - `error_message?: string`

    Human-readable run error message

  - `model?: Model`

    - `model_id: string | null`

      Model identifier

  - `outputs?: Array<Output>`

    - `output_id: string`

      Run output identifier

    - `type: "imageUrl" | "videoUrl" | "audioUrl" | 2 more`

      Run output media type

      - `"imageUrl"`

      - `"videoUrl"`

      - `"audioUrl"`

      - `"text"`

      - `"documentUrl"`

    - `url: string`

      Run output URL or text content

  - `poll_url?: string`

    URL to poll pending/running runs or fetch completed/failed run details.

  - `started_at?: number`
