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

# OpenAI Image generation

***

## Request

<CodeGroup>
  ```shellscript cURL theme={null}
  curl --location 'https://api.znapai.com/images/generations' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer $ZnapAI_API_KEY' \
  --header 'spend-logs-metadata: {"user_id": "user-123", "project_id": "proj_abc", "env": "production"}' \
  --data '{
      "model": "gpt-image-2",
      "prompt": "Japanese negative film aesthetic, rooftop summer scene, soft natural sunlight, slight overexposure highlights, low contrast, muted faded colors, subtle grain  subject standing or sitting on rooftop edge area, body relaxed, slight wind moving hair and clothes, looking toward camera with calm distant gaze, not posing  open sky, empty space, minimal elements, imperfect composition, quiet isolated mood, nostalgic and reflective, “memory-like realism” --2:3",
      "n": 1,
      "size": "1024x1024",
      "quality": "low"
    }'
  ```

  ```python OpenAI SDK (Python) theme={null}
  from openai import OpenAI
  client = OpenAI(
      api_key = "$ZnapAI_API_KEY",
      base_url = "https://api.znapai.com/"
  )

  img = client.images.generate(
      model="gpt-image-2",
      prompt="Japanese negative film aesthetic, rooftop summer scene, soft natural sunlight, slight overexposure highlights, low contrast, muted faded colors, subtle grain  subject standing or sitting on rooftop edge area, body relaxed, slight wind moving hair and clothes, looking toward camera with calm distant gaze, not posing  open sky, empty space, minimal elements, imperfect composition, quiet isolated mood, nostalgic and reflective, “memory-like realism” --2:3",
      n=1,
      size="1024x1024",
      quality="low"
  )

  with open("output.png", "wb") as f:
      f.write(image_bytes)
  ```

  ```typescript OpenAI SDK (JS) theme={null}
  import OpenAI from "openai";
  import { writeFile } from "fs/promises";

  const client = new OpenAI({
      apiKey: "$ZnapAI_API_KEY",
      baseURL: "https://api.znapai.com/"
  });

  const img = await client.images.generate({
      model: "gpt-image-2",
      prompt: "Japanese negative film aesthetic, rooftop summer scene, soft natural sunlight, slight overexposure highlights, low contrast, muted faded colors, subtle grain  subject standing or sitting on rooftop edge area, body relaxed, slight wind moving hair and clothes, looking toward camera with calm distant gaze, not posing  open sky, empty space, minimal elements, imperfect composition, quiet isolated mood, nostalgic and reflective, “memory-like realism” --2:3",
      n: 1,
      size: "1024x1024",
      quality: "low"
  });

  const imageBuffer = Buffer.from(img.data[0].b64_json, "base64");
  await writeFile("output.png", imageBuffer);
  ```
</CodeGroup>

## Response

```json theme={null}
{
    "created": 1771066765,
    "background": null,
    "data": [
        {
            "b64_json": "iVBORw0KGgoAAAA....",
            "revised_prompt": null,
            "url": null
        }
    ],
    "output_format": "png",
    "quality": "low",
    "size": "1024x1024",
    "usage": {
        "total_tokens": 4576,
        "input_tokens": 10,
        "input_tokens_details": {
            "image_tokens": 0,
            "text_tokens": 10
        },
        "output_tokens": 4566,
        "output_tokens_details": {
            "image_tokens": 4160,
            "text_tokens": 406
        }
    }
}
```

## Image from base64 data

<img src="https://mintcdn.com/znapai/bfneBgsrIC5SHCWi/images/openai-image.png?fit=max&auto=format&n=bfneBgsrIC5SHCWi&q=85&s=80ed4b00e2612cd511941b01713f22ba" alt="Screenshot 2026 01 12 At 5 57 44 PM" width="1024" height="1024" data-path="images/openai-image.png" />

***

# Image generation with additional parameters for supported gemini models

## Request

<CodeGroup>
  ```shellscript cURL theme={null}
  curl --location 'https://api.znapai.com/images/generations' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer $ZnapAI_API_KEY' \
  --header 'spend-logs-metadata: {"user_id": "user-123", "project_id": "proj_abc", "env": "production"}' \
  --data '{
      "model": "gemini-3-pro-image",
      "prompt": "A panda eating bamboo",
      "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "1K"
      }
    }'
  ```
</CodeGroup>

## Response

<Frame />

<Frame>
  <img src="https://mintcdn.com/znapai/5C3BYr3NWe1rr-zX/images/gemini3-image-1.png?fit=max&auto=format&n=5C3BYr3NWe1rr-zX&q=85&s=aac4bf23058942a08fff8c1675ef510c" alt="Gemini3 Image" width="1408" height="768" data-path="images/gemini3-image-1.png" />
</Frame>

***

## Parameters

<ParamField path="spend-logs-metadata" type="header" required={false}>
  An optional header used for spend logging metadata, containing JSON properties like `user_id`, `project_id`, and `env`.
</ParamField>

<ParamField path="model" type="string" required>
  Name of the model to use (for example: gpt-image-2). To see the complete list of supported image generation models, visit: [https://znapai.com/models/image\_generation](https://znapai.com/models/image_generation)
</ParamField>

<ParamField path="prompt" type="string" required>
  A text description of the desired image(s). The maximum length is 32,000 characters for the GPT image models, 1,000 characters for `dall-e-2` and 4,000 characters for `dall-e-3`.
</ParamField>

<ParamField path="n" type="integer" default={1}>
  The number of images to generate. Must be between 1 and 10.
</ParamField>

<ParamField path="size" type="string" default="1024x1024">
  Output image dimensions. Supports arbitrary `WIDTHxHEIGHT` where both edges are multiples of 16, aspect ratio between 1:3 and 3:1, max edge 3840.

  Standard values: `1024x1024`, `1536x1024`, `1024x1536`, `auto`.

  Supported values depend on the selected model. See the [OpenAI image generation guide](https://developers.openai.com/api/docs/guides/image-generation) for the latest model-specific ranges.
</ParamField>

<ParamField path="quality" type="string" default="auto">
  Image quality level. Higher quality increases cost and latency.

  Allowed values: `low`, `medium`, `high`, `auto`
</ParamField>

<ParamField path="background" type="string" default="auto">
  Background behavior for the generated image.

  Allowed values: `opaque`, `auto`

  <Warning>`transparent` is not supported on gpt-image-2.</Warning>
</ParamField>

<ParamField path="output_compression" type="integer">
  Compression level (0–100). Only applies when `output_format` is `jpeg`.
</ParamField>

<ParamField path="stream" type="boolean" default={false}>
  Stream partial images as they are generated. Use with `--no-buffer` in curl.
</ParamField>

<ParamField path="partial_images" type="integer">
  Number of partial images to emit during streaming. Value between `0` and `3`. Only used when `stream` is `true`.
</ParamField>

<ParamField path="moderation" type="string" default="auto">
  Content moderation strictness.

  Allowed values: `auto`, `low`
</ParamField>

<ParamField path="imageConfig" type="object">
  Optional configuration parameters for supported Gemini image models.

  <Expandable title="imageConfig" defaultOpen="True">
    <ResponseField name="aspectRatio" type="string">
      The aspect ratio of the generated image (e.g. `16:9`, `1:1`, `4:3`).
    </ResponseField>

    <ResponseField name="imageSize" type="string">
      The resolution level of the image (e.g. `1K`, `2K`, `4K`).
    </ResponseField>
  </Expandable>
</ParamField>

***

## Params to Avoid

| Param                       | Reason                                                                         |
| --------------------------- | ------------------------------------------------------------------------------ |
| `response_format: "url"`    | ZnapAI image endpoint only returns `b64_json`                                  |
| `background: "transparent"` | Not supported by OpenAI/Gemini image generation models                         |
| `output_format: "webp"`     | WebP output format is not supported                                            |
| `style`                     | Vivid or natural style configurations are DALL-E 3 exclusive and not supported |
| `spend-logs-metadata`       | This metadata must be passed as an HTTP header, not in the JSON request body   |
