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

# Image Generation API: Create and Edit Images in NexLLM

> Use POST /v1/images/generations to generate images from text prompts, or POST /v1/images/edits to modify existing images — all via one unified API.

NexLLM's image endpoints let you generate brand-new images from natural language descriptions and edit or modify existing images. Both endpoints are OpenAI-compatible, so any code written for the DALL·E API works directly with NexLLM by changing only the base URL.

## Endpoints

| Endpoint         | Path                          | Description                            |
| ---------------- | ----------------------------- | -------------------------------------- |
| Image Generation | `POST /v1/images/generations` | Generate new images from a text prompt |
| Image Editing    | `POST /v1/images/edits`       | Edit or modify an existing image       |

## Image Generation Parameters

<ParamField body="model" type="string" required>
  The image generation model to use. Example: `dall-e-3`, `dall-e-2`. For Imagen models on Vertex AI, ensure your API key is assigned to a group that includes them (see the note below).
</ParamField>

<ParamField body="prompt" type="string" required>
  A text description of the image you want to generate. More detailed prompts generally produce better results. Maximum length varies by model.
</ParamField>

<ParamField body="n" type="integer">
  The number of images to generate. Defaults to `1`. `dall-e-3` supports only `n=1`; `dall-e-2` supports up to `10`.
</ParamField>

<ParamField body="size" type="string">
  The resolution of the generated image. Supported values depend on the model. Common options: `256x256`, `512x512`, `1024x1024`, `1792x1024`, `1024x1792`. Defaults to `1024x1024`.
</ParamField>

## Code Example

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxxxxxxxxxxxxxx",
    base_url="https://www.nexllm.ai/v1"
)

response = client.images.generate(
    model="dall-e-3",
    prompt="A futuristic cityscape at sunset",
    n=1,
    size="1024x1024"
)

print(response.data[0].url)
```

## Image Editing Example

To edit an existing image, send a `POST` request to `/v1/images/edits` with the original image file and a prompt describing the change you want:

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxxxxxxxxxxxxxx",
    base_url="https://www.nexllm.ai/v1"
)

with open("original.png", "rb") as image_file:
    response = client.images.edit(
        model="dall-e-2",
        image=image_file,
        prompt="Add a rainbow in the sky",
        n=1,
        size="1024x1024"
    )

print(response.data[0].url)
```

<Note>
  To access Imagen models (Google's image generation models on Vertex AI), your API key must be assigned to a channel group that includes them — for example, the `gemini-vertex` group. Check the [channel groups overview](/channel-groups/overview) to confirm which models are available under your key.
</Note>
