> ## 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.

<CodeGroup>
  ```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.ai/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.ai/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.ai/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"));
  ```
</CodeGroup>

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

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


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