> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ltx.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ltx.io/_mcp/server.

# Idempotent Requests

> Use the Idempotency-Key header to retry a request safely. A retry with the same key returns the original job instead of creating a new one.

The API supports idempotency, so you can retry a request without creating a second job. Add an `Idempotency-Key` header to a `POST` that creates a job. When a request times out, the connection drops, or you get a `5xx` error, send the same request again with the same key. You get back the job the first request created.

**`Python`**

```python title="Python"
import uuid
import requests

# One key per job. Reuse it when you retry this request.
idempotency_key = str(uuid.uuid4())

response = requests.post(
    "https://api.ltx.io/v2/text-to-video",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
        "Idempotency-Key": idempotency_key,
    },
    json={
        "prompt": "A majestic eagle soaring through clouds at sunset",
        "model": "ltx-2-5-pro",
        "duration": 8,
        "resolution": "1920x1080",
    },
)
```

**`TypeScript`**

```typescript title="TypeScript"
// One key per job. Reuse it when you retry this request.
const idempotencyKey = crypto.randomUUID();

const response = await fetch("https://api.ltx.io/v2/text-to-video", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "Idempotency-Key": idempotencyKey,
  },
  body: JSON.stringify({
    prompt: "A majestic eagle soaring through clouds at sunset",
    model: "ltx-2-5-pro",
    duration: 8,
    resolution: "1920x1080",
  }),
});
```

**`cURL`**

```curl title="cURL"
# One key per job. Reuse it when you retry this request.
idempotency_key=$(uuidgen)

curl -X POST https://api.ltx.io/v2/text-to-video \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $idempotency_key" \
  -d '{
    "prompt": "A majestic eagle soaring through clouds at sunset",
    "model": "ltx-2-5-pro",
    "duration": 8,
    "resolution": "1920x1080"
  }'
```

Sending the same request again with a key you already used returns `202` with the first job's `id` and `created_at`, plus the header `Idempotent-Replayed: true`. This works whether that job is pending, processing, completed or failed. No new job is created. When several identical requests with the same key arrive at the same time, they all get the same `id`, and one job runs.

A key belongs to one job. To start another job, or to try again after a job failed, use a new key.

Keys are scoped to your organization and to the endpoint. A key lasts as long as its job's status (see [Retention](/async-jobs#retention)). Once the status is removed, a request with the same key creates a new job.

A request rejected before its job is created (`400`, `401`, `413` or `429`) doesn't use up its key, so you can send it again with the same key.

Every `POST` that creates a job accepts an idempotency key. Other requests ignore it, including `POST /v1/upload`.

## Key format

* 1 to 255 printable ASCII characters, not counting quotes: letters, digits, punctuation and spaces.
* Keys are case-sensitive: `abc` and `ABC` are different keys.
* Send the key as is, or in double quotes. Both are the same key: `Idempotency-Key: 9c7d2b4a-0e1f-4c83-9a2d-1b0f4e3c5a7d` and `Idempotency-Key: "9c7d2b4a-0e1f-4c83-9a2d-1b0f4e3c5a7d"`. A key that starts with `"` is read as quoted: inside the quotes, write `\"` for a quote and `\\` for a backslash.
* Send the header only once per request.

## Key errors

A header that breaks a [Key format](#key-format) rule gets `400` `invalid_request_error`. Fix the header and send the request again.

A key already used with a different request gets `422` `idempotency_error`. To retry, resend the first request's body unchanged. For a new job, use a new key.