Skip to main content

Quick Start

1. Install

pip install legnext

2. Set API Key

export LEGNEXT_API_KEY="your-api-key"

3. Basic Example

import os
from legnext import Client

client = Client(api_key=os.getenv("LEGNEXT_API_KEY"))

# Generate image
response = client.midjourney.diffusion(
    text="a beautiful sunset over mountains"
)

# Wait for completion
result = client.tasks.wait_for_completion(response.job_id)

print(f"Images: {result.output.image_urls}")
That’s it! Your first API call is complete.

Next Steps

  • Polling - Use client.tasks.wait_for_completion() with on_progress callback
  • Webhooks - Set callback parameter for async notifications
  • API Methods - See Image Generation reference
  • Async - Learn about AsyncClient in Task Management
  • Errors - See error handling in Task Management

Common Use Cases

Generate and upscale:
response = client.midjourney.diffusion(text="...")
result = client.tasks.wait_for_completion(response.job_id)

upscale = client.midjourney.upscale(
    job_id=response.job_id,
    image_no=0
)
With webhook (production):
response = client.midjourney.diffusion(
    text="...",
    callback="https://your-api.com/webhooks/image"
)
print(f"Job {response.job_id} will post to your webhook")
Async batch:
import asyncio
from legnext import AsyncClient

async with AsyncClient(api_key=os.getenv("LEGNEXT_API_KEY")) as client:
    responses = await asyncio.gather(*[
        client.midjourney.diffusion(text=f"prompt {i}")
        for i in range(5)
    ])

Learn More