Skip to content
lumalabs.ai
Getting started

Quickstart

Generate and edit images with the Luma Agents REST API — quickstart, SDKs, and authentication.

The Luma Agents API provides access to uni-1, Luma’s image generation and editing model. The API is asynchronous: submit a generation request, poll for the result, and download your image.

The workflow is three steps:

  1. Submit a generation request via POST /v1/generations
  2. Poll for status via GET /v1/generations/{generation_id}
  3. Download images from presigned URLs once the state reaches completed
import time
from luma_agents import Luma
client = Luma()
# 1. Submit
generation = client.generations.create(
prompt="A glass of iced coffee on a marble countertop, morning light streaming through a window",
aspect_ratio="16:9",
)
# 2. Poll
while generation.state not in ("completed", "failed"):
time.sleep(2)
generation = client.generations.get(generation.id)
# 3. Download
if generation.state == "completed":
print(f"Image URL: {generation.output[0].url}")
else:
print(f"Failed: {generation.failure_reason} (code: {generation.failure_code})")

To edit an existing image instead, set type to "image_edit" and provide a source. Polling and download are identical to the generate flow above.

generation = client.generations.create(
type="image_edit",
prompt="Change the sky to a dramatic sunset with orange and purple clouds",
source={"url": "https://example.com/landscape.jpg"},
)

See Image editing for image_ref, style transfer, and base64 source images.

Don’t bother with exponential backoff — uni-1 generations typically take 30–60 seconds, so polling every 2 seconds is only ~15–30 GETs per job. What’s worth adding: a hard deadline so a stalled job can’t hang your worker, and a short initial wait so the first few polls aren’t wasted.

deadline = time.time() + 120 # 2-minute hard timeout
time.sleep(20) # uni-1 p50 is ~30s — no point polling sooner
while generation.state not in ("completed", "failed"):
if time.time() > deadline:
raise TimeoutError(f"Generation {generation.id} did not complete in time")
generation = client.generations.get(generation.id)
time.sleep(2)

Every request requires a Bearer token in the Authorization header. Set your API key as the LUMA_AGENTS_API_KEY environment variable — the official SDKs read it automatically.

Terminal window
export LUMA_AGENTS_API_KEY="luma-api-..."
https://agents.lumalabs.ai/v1
MethodPathDescription
POST/v1/generationsSubmit an image generation or edit job
GET/v1/generations/{generation_id}Poll for generation status and output
Terminal window
pip install luma-agents

Every response includes X-Request-Id and X-API-Version headers. Successful generation requests also include rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset). See Rate limits and headers for details.

  • Models — Model capabilities, limitations, and output specifications
  • Image generation — Full parameter reference for text-to-image
  • Image editing — Modify existing images with text prompts and reference images
  • Pricing — Pay-as-you-go and Provisioned Throughput plans
  • Rate limits and headers — Rate limiting, response headers, and retry strategies
  • Error handling — Every error code with troubleshooting steps
  • FAQ — Quick answers to common questions
  • API Reference — Complete endpoint specifications