Sign in to sync history and unlock more features

LTX-2 API Documentation

Complete API reference for the LTX-2 API video generation service.

Important Notice

Webhook/callback mode is not currently available. Please use the polling method by calling the /api/status endpoint to check task completion status.

Recommended polling interval: 5-10 seconds. Video generation typically takes 1-3 minutes depending on duration and resolution.

Authentication

All API requests require authentication via Bearer token in the Authorization header.

Request Header
Authorization: Bearer YOUR_API_KEY

Get your API key from the Dashboard.

Base URL

https://ltx-2api.com

Generate Video

POST /api/generate

Create a new video generation task. Supports both Text-to-Video and Image-to-Video modes.

Request Parameters

ParameterTypeRequiredDescription
promptstringYesText description of the video (max 2000 characters)
imagestringNoImage URL for Image-to-Video mode. If provided, aspect_ratio is determined by the image.
resolutionstringNo480p, 720p, or 1080p. Default: 720p
aspect_ratiostringNo16:9 or 9:16. Default: 16:9. Only for Text-to-Video.
durationintegerNoVideo duration in seconds (5-20). Default: 5
seedintegerNoRandom seed for reproducibility. Default: -1 (random)

Generation Modes

Text-to-Video

Only prompt is required. You can specify aspect_ratio.

Image-to-Video

Both prompt and image are required. Aspect ratio is determined by the input image.

Request Example

cURL
curl -X POST https://ltx-2api.com/api/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A golden retriever running through a sunlit meadow",
    "resolution": "1080p",
    "aspect_ratio": "16:9",
    "duration": 10
  }'

Response

200 OK
{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "n50abc123ltx2",
    "status": "IN_PROGRESS",
    "consumed_credits": 44
  }
}

In this example: 10 seconds at 1080p = 36 (base) + 8 (1080p) = 44 credits

Check Task Status

GET /api/status

Check the status of a video generation task. Poll this endpoint until status is SUCCESS or FAILED.

Query Parameters

ParameterTypeRequiredDescription
task_idstringYesThe task ID returned from the generate endpoint

Request Example

cURL
curl "https://ltx-2api.com/api/status?task_id=n50abc123ltx2"

Note: This endpoint does not require authentication. The task ID serves as a unique identifier.

Response (Success)

200 OK
{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "n50abc123ltx2",
    "status": "SUCCESS",
    "consumed_credits": 44,
    "error_message": null,
    "created_at": "2024-01-01T12:00:00Z",
    "request": {
      "prompt": "A golden retriever running through a sunlit meadow",
      "resolution": "1080p",
      "aspect_ratio": "16:9",
      "duration": 10
    },
    "response": [
      "https://cdn.example.com/videos/abc123.mp4"
    ]
  }
}

Status Values

StatusDescription
PENDINGTask is queued and waiting to be processed. Continue polling.
IN_PROGRESSVideo is being generated. Continue polling.
SUCCESSVideo generation completed. Check response array for video URLs.
FAILEDGeneration failed. Check error_message for details. Credits are refunded.

Credit Calculation

Credits are consumed based on video duration and resolution. The base formula is:

base_credits = 20 + (duration - 5) × 3.2

Resolution adjustment: 480p = base, 720p = base + 4, 1080p = base + 8

Duration480p720p1080p
5 seconds202428
10 seconds364044
15 seconds525660
20 seconds687276

Note: If generation fails, credits are automatically refunded to your account.

Error Codes

CodeDescription
400Bad Request - Invalid parameters (missing prompt, invalid resolution, duration out of range, etc.)
401Unauthorized - Missing or invalid API key
404Not Found - Task ID not found
500Internal Server Error - Please try again later or contact support

Code Examples

Node.js

generate-video.js
const API_KEY = 'your_api_key_here';
const BASE_URL = 'https://ltx-2api.com/api';

async function generateVideo(prompt, options = {}) {
  // Submit generation request
  const response = await fetch(`${BASE_URL}/generate`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      prompt,
      duration: options.duration || 5,
      resolution: options.resolution || '720p',
      aspect_ratio: options.aspectRatio || '16:9'
    })
  });

  const { data } = await response.json();
  console.log(`Task created: ${data.task_id}`);

  // Poll for completion
  return await pollForCompletion(data.task_id);
}

async function pollForCompletion(taskId, maxAttempts = 60) {
  for (let i = 0; i < maxAttempts; i++) {
    const response = await fetch(`${BASE_URL}/status?task_id=${taskId}`);
    const { data } = await response.json();

    if (data.status === 'SUCCESS') {
      return data.response[0]; // Video URL
    } else if (data.status === 'FAILED') {
      throw new Error(data.error_message);
    }

    console.log('Processing...');
    await new Promise(r => setTimeout(r, 5000)); // Poll every 5 seconds
  }
  throw new Error('Timeout');
}

// Usage
generateVideo('A sunset over the ocean', { duration: 10 })
  .then(url => console.log('Video URL:', url))
  .catch(err => console.error('Error:', err));

Python

generate_video.py
import requests
import time

API_KEY = "your_api_key_here"
BASE_URL = "https://ltx-2api.com/api"

def generate_video(prompt, duration=5, resolution="720p"):
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }

    # Submit request
    response = requests.post(f"{BASE_URL}/generate", json={
        "prompt": prompt,
        "duration": duration,
        "resolution": resolution
    }, headers=headers)

    data = response.json()["data"]
    task_id = data["task_id"]
    print(f"Task created: {task_id}")

    # Poll for completion (no auth required for status endpoint)
    for _ in range(60):
        status_resp = requests.get(f"{BASE_URL}/status?task_id={task_id}")
        status_data = status_resp.json()["data"]

        if status_data["status"] == "SUCCESS":
            return status_data["response"][0]
        elif status_data["status"] == "FAILED":
            raise Exception(status_data["error_message"])

        print("Processing...")
        time.sleep(5)  # Poll every 5 seconds

    raise Exception("Timeout")

# Usage
if __name__ == "__main__":
    url = generate_video("A sunset over the ocean", duration=10)
    print(f"Video URL: {url}")