Luma AI Text-to-Video

Generate Videos from Text or Images

Overview

The Luma AI Dream Machine API allows developers to generate, retrieve, and extend AI-generated content using a variety of inputs. This API is particularly useful for creative applications, such as generating visual content from text prompts.

Authentication

All API requests require a Bearer token for authentication. Include your token in the Authorization header of each request.

Pricing

Each generation costs 500 000 AI/ML Tokens

API Reference

Ensure you replace "your-api-key" with your actual API key before running the code.

使用 Luma AI 生成视频。

post

使用 Luma AI 根据提示生成视频,允许根据文本描述创建视频。

请求体
aspect_ratiostring必填

The aspect ratio of the image

Example: 16:9
expand_promptboolean必填

Whether to expand the prompt

Example: true
image_end_urlstring必填

The URL for the end of the image

Example: https://example.com/image-end.jpg
image_urlstring必填

The URL of the main image

Example: https://example.com/main-image.jpg
user_promptstring必填

The user-provided prompt for image generation

Example: A beautiful sunset over the ocean
响应
200成功
application/json
post
/luma-ai/generations
POST /luma-ai/generations HTTP/1.1
Host: api.aimlapi.com
Content-Type: application/json
Accept: */*
Content-Length: 195

{
  "aspect_ratio": "16:9",
  "expand_prompt": true,
  "image_end_url": "https://example.com/image-end.jpg",
  "image_url": "https://example.com/main-image.jpg",
  "user_prompt": "A beautiful sunset over the ocean"
}
200成功
{
  "created_at": "text",
  "estimate_wait_seconds": "text",
  "id": "text",
  "liked": "text",
  "prompt": "text",
  "state": "text",
  "video": {
    "height": 1,
    "width": 1,
    "thumbnail": "text",
    "url": "text"
  }
}

Example

import requests

url = "https://api.aimlapi.com/luma-ai/generations"

payload = {
  "aspect_ratio": "16:9",
  "expand_prompt": True,
  "user_prompt": "Flying jellyfish"
}
headers = {
  "Authorization": "Bearer your-api-key",
  "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())

在 Luma AI 中按 ID 列出视频代。

get

根据 Luma AI 中的 ID 返回视频生成列表。

查询参数
idsstring[]必填
响应
200成功
application/json
get
/luma-ai/generation
GET /luma-ai/generation?ids=text HTTP/1.1
Host: api.aimlapi.com
Accept: */*
200成功
[
  {
    "created_at": "text",
    "estimate_wait_seconds": "text",
    "id": "text",
    "liked": "text",
    "prompt": "text",
    "state": "text",
    "video": {
      "height": 1,
      "width": 1,
      "thumbnail": "text",
      "url": "text"
    }
  }
]

Example

import requests

url = "https://api.aimlapi.com/luma-ai/generation"

querystring = {"ids[0]":"4c9126f3-d9a6-4eaf-aa4c-b64b634f65bd"}

headers = {
  "Authorization": "Bearer your-api-key",
  "content-type": "application/json"
}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())

上传图像以便在 Luma AI 中进行处理。

post

上传图像以便在 Luma AI 中进一步处理,通常用于 3D 建模或视频生成。

请求体
urlstring必填
响应
200成功
application/json
post
/luma-ai/generations/file-upload
POST /luma-ai/generations/file-upload HTTP/1.1
Host: api.aimlapi.com
Content-Type: application/json
Accept: */*
Content-Length: 14

{
  "url": "text"
}
200成功
[
  {
    "id": "text",
    "presigned_url": "https://example.com",
    "public_url": "https://example.com"
  }
]

Example

import requests

url = "https://api.aimlapi.com/luma-ai/generations/file-upload"

payload = { "url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDozQhfHZ0SUoYPxSsIp7FXZmwHcSBijueGg&s" }
headers = {
  "Authorization": "Bearer your-api-key",
  "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())

使用 Luma AI 扩展视频。

post

使用 Luma AI 扩展现有视频,为视频项目创建附加内容。

路径参数
taskIdstring必填
请求体
aspect_ratiostring必填

The aspect ratio of the image

Example: 16:9
expand_promptboolean必填

Whether to expand the prompt

Example: true
image_end_urlstring必填

The URL for the end of the image

Example: https://example.com/image-end.jpg
image_urlstring必填

The URL of the main image

Example: https://example.com/main-image.jpg
user_promptstring必填

The user-provided prompt for image generation

Example: A beautiful sunset over the ocean
响应
200成功
application/json
post
/luma-ai/generations/{taskId}/extend
POST /luma-ai/generations/{taskId}/extend HTTP/1.1
Host: api.aimlapi.com
Content-Type: application/json
Accept: */*
Content-Length: 195

{
  "aspect_ratio": "16:9",
  "expand_prompt": true,
  "image_end_url": "https://example.com/image-end.jpg",
  "image_url": "https://example.com/main-image.jpg",
  "user_prompt": "A beautiful sunset over the ocean"
}
200成功
{
  "id": "text",
  "created_at": "text",
  "estimate_wait_seconds": "text",
  "liked": "text",
  "prompt": "text",
  "state": "text",
  "video": {
    "height": 1,
    "width": 1,
    "thumbnail": "text",
    "url": "text"
  }
}

Example

import requests

url = "https://api.aimlapi.com/luma-ai/generations/57a6cb80-6da0-49bd-b29a-3f089b9e55e4/extend"

payload = {
  "aspect_ratio": "16:9",
  "expand_prompt": True,
  "user_prompt": "Flying jellyfish with a hat"
}
headers = {
  "Authorization": "Bearer your-api-key",
  "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())

最后更新于