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

# Image Generation

> Generate images from text prompts with Venice's native image API or the OpenAI-compatible images endpoint, with style controls and binary or base64 output.

Image generation on Venice is synchronous. Send a prompt to `/image/generate` and receive your image in the same response, either as base64 inside JSON or as raw binary when `return_binary` is `true`.

## Endpoints

| Endpoint                   | Purpose                                | When to use                                           |
| -------------------------- | -------------------------------------- | ----------------------------------------------------- |
| `POST /image/generate`     | Native Venice image generation API     | Use this for full feature support                     |
| `GET /image/styles`        | List available style presets           | Use this before sending `style_preset`                |
| `POST /images/generations` | OpenAI-compatible image generation API | Use this when migrating existing OpenAI image clients |

## Step 1: Send a generation request

Sizing is model-specific. Some models accept explicit `width` and `height`; some expose `aspect_ratio`; and resolution-tier models expose `aspect_ratio` plus `resolution` values such as `1K`, `2K`, or `4K`.

**Pixel-based sizing example:**

```bash theme={"system"}
POST https://api.venice.ai/api/v1/image/generate
Authorization: Bearer $VENICE_API_KEY
Content-Type: application/json

{
  "model": "venice-sd35",
  "prompt": "A cinematic photo of a gondola passing through a narrow Venice canal at blue hour, warm window lights reflecting on the water",
  "negative_prompt": "blurry, low quality, distorted anatomy, text, watermark",
  "width": 1024,
  "height": 1024,
  "format": "webp"
}
```

**Aspect-ratio sizing example:**

```bash theme={"system"}
POST https://api.venice.ai/api/v1/image/generate
Authorization: Bearer $VENICE_API_KEY
Content-Type: application/json

{
  "model": "qwen-image-2",
  "prompt": "A cinematic photo of a gondola passing through a narrow Venice canal at blue hour",
  "aspect_ratio": "16:9",
  "format": "webp"
}
```

**Resolution-tier sizing example:**

```bash theme={"system"}
POST https://api.venice.ai/api/v1/image/generate
Authorization: Bearer $VENICE_API_KEY
Content-Type: application/json

{
  "model": "gpt-image-2",
  "prompt": "A cinematic wide shot of a gondola passing through a narrow Venice canal at blue hour",
  "aspect_ratio": "16:9",
  "resolution": "4K",
  "format": "png"
}
```

The same pattern applies to other resolution-tier models:

```json theme={"system"}
{
  "model": "nano-banana-pro",
  "prompt": "A serene canal in Venice at sunset",
  "aspect_ratio": "16:9",
  "resolution": "2K"
}
```

Use [Image Models](/models/image) or the [Models API](/api-reference/endpoint/models/list) to confirm which sizing fields each model accepts.

**Response (200):**

```json theme={"system"}
{
  "id": "generate-image-1234567890",
  "images": [
    "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoQABAAPm..."
  ],
  "timing": {
    "inferenceDuration": 1840,
    "inferencePreprocessingTime": 22,
    "inferenceQueueTime": 31,
    "total": 1893
  }
}
```

The `images` array contains base64-encoded image data. Decode the first item to save or display it. `timing.total` is the full request duration in milliseconds.

## Step 2: Decode and save the image

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

  response = requests.post(
      "https://api.venice.ai/api/v1/image/generate",
      headers={
          "Authorization": f"Bearer {os.environ['VENICE_API_KEY']}",
          "Content-Type": "application/json",
      },
      json={
          "model": "venice-sd35",
          "prompt": "A cinematic photo of a gondola passing through a narrow Venice canal at blue hour, warm window lights reflecting on the water",
          "width": 1024,
          "height": 1024,
          "format": "webp",
      },
  )

  data = response.json()
  image_bytes = base64.b64decode(data["images"][0])

  with open("output.webp", "wb") as f:
      f.write(image_bytes)

  print(f"Saved image from request {data['id']}")
  ```

  ```javascript Node.js theme={"system"}
  import fs from "fs";

  const response = await fetch("https://api.venice.ai/api/v1/image/generate", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.VENICE_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "venice-sd35",
      prompt: "A cinematic photo of a gondola passing through a narrow Venice canal at blue hour, warm window lights reflecting on the water",
      width: 1024,
      height: 1024,
      format: "webp",
    }),
  });

  const data = await response.json();
  const imageBuffer = Buffer.from(data.images[0], "base64");
  fs.writeFileSync("output.webp", imageBuffer);

  console.log(`Saved image from request ${data.id}`);
  ```
</CodeGroup>

## Step 3: Return binary instead of JSON (optional)

If you want the response body to be the image file itself, set `return_binary: true`. This is useful when you want to stream or save the image directly without base64 decoding.

```bash theme={"system"}
curl https://api.venice.ai/api/v1/image/generate \
  -H "Authorization: Bearer $VENICE_API_KEY" \
  -H "Content-Type: application/json" \
  -o output.png \
  -d '{
    "model": "qwen-image-2",
    "prompt": "Minimalist poster of a moonlit Venetian bridge in deep blue tones",
    "format": "png",
    "return_binary": true
  }'
```

When `return_binary` is `true`, the response body is raw `image/jpeg`, `image/png`, or `image/webp` data based on the `format` you requested.

<Note>
  `variants` is only supported when `return_binary` is `false`.
</Note>

***

## Step 4: List available image styles (optional)

If you want to use `style_preset`, first fetch the available styles from `/image/styles`:

```bash theme={"system"}
curl https://api.venice.ai/api/v1/image/styles \
  -H "Authorization: Bearer $VENICE_API_KEY"
```

**Response (200):**

```json theme={"system"}
[
  "3D Model",
  "Analog Film",
  "Anime",
  "Cinematic",
  "Digital Art"
]
```

Then pass one of those values into your generation request:

```json theme={"system"}
{
  "model": "qwen-image-2",
  "prompt": "A futuristic Venice skyline at sunrise",
  "style_preset": "Cinematic"
}
```

Use the styles endpoint when you want exact preset names instead of guessing them.

***

## Request Parameters

| Parameter           | Type    | Required    | Default         | Description                                                                                                                   |
| ------------------- | ------- | ----------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `model`             | string  | Yes         | -               | Model ID to use for generation                                                                                                |
| `prompt`            | string  | Yes         | -               | What to generate                                                                                                              |
| `negative_prompt`   | string  | No          | -               | What to avoid in the image                                                                                                    |
| `width`             | integer | No          | `1024`          | Output width in pixels for pixel-based models such as `venice-sd35` and `qwen-image`                                          |
| `height`            | integer | No          | `1024`          | Output height in pixels for pixel-based models such as `venice-sd35` and `qwen-image`                                         |
| `format`            | string  | No          | `webp`          | Output format: `jpeg`, `png`, or `webp`                                                                                       |
| `variants`          | integer | No          | `1`             | Number of images to generate (`1`-`4`), only when `return_binary` is `false`                                                  |
| `return_binary`     | boolean | No          | `false`         | Return raw image bytes instead of base64 JSON                                                                                 |
| `safe_mode`         | boolean | No          | `true`          | Blur adult content when enabled                                                                                               |
| `seed`              | integer | No          | random          | Reuse the same seed for more consistent iterations                                                                            |
| `cfg_scale`         | number  | No          | model-dependent | Higher values push the model to follow the prompt more closely                                                                |
| `style_preset`      | string  | No          | -               | Apply a preset style from [Image Styles](/api-reference/endpoint/image/styles)                                                |
| `aspect_ratio`      | string  | Conditional | -               | Used by models that support ratio-based sizing, such as `qwen-image-2`, `gpt-image-2`, `nano-banana-2`, and `nano-banana-pro` |
| `resolution`        | string  | Conditional | -               | Used by models that support resolution tiers such as `1K`, `2K`, or `4K`                                                      |
| `enable_web_search` | boolean | Conditional | `false`         | Allows supported models to use current web information; adds extra cost                                                       |

Validation is model-specific. Check [Image Models](/models/image) and the [Models API](/api-reference/endpoint/models/list) before relying on a parameter across multiple models.

***

## Model-specific options

### High-resolution generation

Some image models support `aspect_ratio` without a selectable `resolution` tier. For example, `qwen-image-2` accepts aspect ratio and maps it to model-specific output dimensions:

```json theme={"system"}
{
  "model": "qwen-image-2",
  "prompt": "Editorial product photo of a luxury watch on black marble, dramatic studio lighting",
  "aspect_ratio": "16:9"
}
```

Other image models support `aspect_ratio` plus a `resolution` tier. For example, `gpt-image-2`, `nano-banana-2`, and `nano-banana-pro` support `1K`, `2K`, and `4K`:

```json theme={"system"}
{
  "model": "gpt-image-2",
  "prompt": "Editorial product photo of a luxury watch on black marble, dramatic studio lighting",
  "aspect_ratio": "16:9",
  "resolution": "4K"
}
```

```json theme={"system"}
{
  "model": "nano-banana-2",
  "prompt": "Editorial product photo of a luxury watch on black marble, dramatic studio lighting",
  "aspect_ratio": "16:9",
  "resolution": "2K"
}
```

Use [Image Models](/models/image) to see which models support higher resolutions and how they are priced.

### Style presets

If the selected model supports it, `style_preset` lets you steer the output without rewriting your whole prompt. You can fetch valid preset names from [Image Styles](/api-reference/endpoint/image/styles):

```json theme={"system"}
{
  "model": "qwen-image-2",
  "prompt": "A futuristic Venice skyline at sunrise",
  "style_preset": "3D Model"
}
```

See [Image Styles](/api-reference/endpoint/image/styles) for the current style list.

***

## OpenAI-compatible endpoint

If you're already using OpenAI image SDKs or existing DALL-E integrations, Venice also supports `POST /images/generations`. It offers a simpler request format, but fewer features than the native Venice endpoint.

**Request:**

```json theme={"system"}
{
  "model": "qwen-image-2",
  "prompt": "A clean isometric illustration of an AI control room",
  "size": "1024x1024",
  "response_format": "b64_json"
}
```

Use the OpenAI-compatible route for faster migrations. Use `/image/generate` when you need Venice-specific options such as `cfg_scale`, `style_preset`, `variants`, or binary responses.

***

## Prompting tips

1. Start with the subject, then add medium, lighting, composition, and mood.
2. Put must-avoid details in `negative_prompt` instead of overloading the main prompt.
3. Reuse `seed` when iterating so you can compare prompt changes without fully changing the composition.
4. Keep sizing model-aware. Some models use `width`/`height`, some use `aspect_ratio`, and resolution-tier models use `aspect_ratio` plus `resolution`.
5. Use `variants` during exploration, then switch back to a single output once you've locked in the direction.

***

## Errors

| Status | Meaning                                                      | Action                                                                  |
| ------ | ------------------------------------------------------------ | ----------------------------------------------------------------------- |
| `400`  | Invalid request parameters                                   | Check field names, types, and model-specific constraints                |
| `401`  | Authentication failed or model requires a higher access tier | Check your API key and model access                                     |
| `402`  | Insufficient balance                                         | Add credits at [venice.ai/settings/api](https://venice.ai/settings/api) |
| `415`  | Invalid content type                                         | Send JSON with `Content-Type: application/json`                         |
| `429`  | Rate limit exceeded or model overloaded                      | Retry with backoff; check `Retry-After` header                          |
| `500`  | Inference processing failed                                  | Retry the request                                                       |
| `503`  | Model at capacity                                            | Retry after a short delay                                               |

<Note>
  When Safe Venice is enabled, inspect response headers such as `x-venice-is-blurred` and `x-venice-is-content-violation` if you need to detect moderation outcomes programmatically.
</Note>

***

## Available Models

See [Image Models](/models/image) for the current model list, pricing, and feature support.
