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

> ## Agent Instructions
> Authenticate every request with your API key in the `X-API-Key` header or `Authorization: Bearer`. Keys start with `sk-nunchux-`.
> Image generation is synchronous: the image is in the response.
> Video generation is asynchronous: submit the job, poll its task until it reaches a terminal status, then download the output promptly, because output URLs expire.

# QuickStart

> Get started generating images and videos with the Nunchux API in minutes.

# Quickstart

### Generate your first image in under 5 minutes.

## 1. Create your API key

Before you begin, [sign up](https://nunchux.ai/sign-up) for an account to get an API key.

Once you've registered, create an API key from your [dashboard](https://nunchux.ai/dashboard) and set it as an environment variable.

```bash Export an environment variable theme={"system"}
export NUNCHUX_API_KEY=xxxxx
```

## 2. Make your first request

Generate your first image with a simple API request and save your result.

```bash cURL theme={"system"}
# Replace $NUNCHUX_API_KEY with your API key.
# Change output.jpg to the filename you want.
curl -X POST https://api.nunchux.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $NUNCHUX_API_KEY" \
  -d '{
    "model": "nunchux-flux.2-klein-4b",
    "prompt": "A beautiful sunset over mountains",
    "tier": "radical_speed",
    "width": 1024,
    "height": 1024,
    "response_format": "b64_json"
  }' | jq -r '.data[0].b64_json // error(.error.message // .detail // tostring)' | base64 -d > output.jpg
```

```python Python theme={"system"}
import base64
import os
import requests

response = requests.post(
    "https://api.nunchux.com/v1/images/generations",
    headers={
        "Content-Type": "application/json",
        "X-API-Key": os.environ["NUNCHUX_API_KEY"],
    },
    json={
        "model": "nunchux-flux.2-klein-4b",
        "prompt": "A beautiful sunset over mountains",
        "tier": "radical_speed",
        "width": 1024,
        "height": 1024,
        "response_format": "b64_json",
    },
)

# Decode the base64 image and save it. Change output.jpg to any filename.
image_b64 = response.json()["data"][0]["b64_json"]
with open("output.jpg", "wb") as f:
    f.write(base64.b64decode(image_b64))
```

```javascript JavaScript theme={"system"}
import { writeFile } from "node:fs/promises";

const response = await fetch("https://api.nunchux.com/v1/images/generations", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": process.env.NUNCHUX_API_KEY,
  },
  body: JSON.stringify({
    model: "nunchux-flux.2-klein-4b",
    prompt: "A beautiful sunset over mountains",
    tier: "radical_speed",
    width: 1024,
    height: 1024,
    response_format: "b64_json",
  }),
});

const data = await response.json();

// Decode the base64 image and save it. Change output.jpg to any filename.
await writeFile("output.jpg", Buffer.from(data.data[0].b64_json, "base64"));
```

Congratulations – you've just made your first call to Nunchux! From here:

* [Nunchux Optimized models](https://docs.nunchux.ai/nunchux-optimized/overview.md): the models in this example, and the video models.
* [Partner models](https://docs.nunchux.ai/partner-models/overview.md): third-party image and video models.
* [Performance Tiers](https://docs.nunchux.ai/performance-tiers.md): what the tier field does, and when to change it.
* [Text-to-Image reference](https://docs.nunchux.ai/nunchux-optimized/text-to-image.md): all parameters and response formats.
* [Image-to-Image reference](https://docs.nunchux.ai/nunchux-optimized/image-to-image.md): edit an input image with a prompt.
* [Video](https://docs.nunchux.ai/partner-models/overview.md): the async submit, poll and download flow that every partner video model uses.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.