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.
Authorization: Bearer YOUR_API_KEY
Get your API key from the Dashboard.
Base URL
https://ltx-2api.comGenerate Video
POST /api/generateCreate a new video generation task. Supports both Text-to-Video and Image-to-Video modes.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| prompt | string | Yes | Text description of the video (max 2000 characters) |
| image | string | No | Image URL for Image-to-Video mode. If provided, aspect_ratio is determined by the image. |
| resolution | string | No | 480p, 720p, or 1080p. Default: 720p |
| aspect_ratio | string | No | 16:9 or 9:16. Default: 16:9. Only for Text-to-Video. |
| duration | integer | No | Video duration in seconds (5-20). Default: 5 |
| seed | integer | No | Random 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 -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
{
"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
| Parameter | Type | Required | Description |
|---|---|---|---|
| task_id | string | Yes | The task ID returned from the generate endpoint |
Request Example
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)
{
"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
| Status | Description |
|---|---|
| PENDING | Task is queued and waiting to be processed. Continue polling. |
| IN_PROGRESS | Video is being generated. Continue polling. |
| SUCCESS | Video generation completed. Check response array for video URLs. |
| FAILED | Generation 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
| Duration | 480p | 720p | 1080p |
|---|---|---|---|
| 5 seconds | 20 | 24 | 28 |
| 10 seconds | 36 | 40 | 44 |
| 15 seconds | 52 | 56 | 60 |
| 20 seconds | 68 | 72 | 76 |
Note: If generation fails, credits are automatically refunded to your account.
Error Codes
| Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters (missing prompt, invalid resolution, duration out of range, etc.) |
| 401 | Unauthorized - Missing or invalid API key |
| 404 | Not Found - Task ID not found |
| 500 | Internal Server Error - Please try again later or contact support |
Code Examples
Node.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
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}")