> ## Documentation Index
> Fetch the complete documentation index at: https://docs.legnext.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Get started with the Legnext Python SDK in 5 minutes

## 1. Install

```bash theme={null}
pip install legnext
```

## 2. Set API Key

```bash theme={null}
export LEGNEXT_API_KEY="your-api-key"
```

## 3. Basic Example

```python theme={null}
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](/sdk/python/image-generation) reference
* **Async** - Learn about `AsyncClient` in [Task Management](/sdk/python/task-management)
* **Errors** - See error handling in [Task Management](/sdk/python/task-management)

***

## Common Use Cases

**Generate and upscale:**

```python theme={null}
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):**

```python theme={null}
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:**

```python theme={null}
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

* [Installation Details](/sdk/python/installation)
* [Authentication Guide](/sdk/python/authentication)
* [Image Generation API](/sdk/python/image-generation)
* [Video Generation API](/sdk/python/video-generation)
* [Task Management & Error Handling](/sdk/python/task-management)
