Skip to navigation

Idempotent Requests

Retry a submit without creating a second job

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.

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",
},
)

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). 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 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.