> ## Documentation Index
> Fetch the complete documentation index at: https://edenai-docs-github-copilot-integration.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generation

> Generate and edit images with the OpenAI-compatible /v3/images endpoints.

export const TechArticleSchema = ({title, description, path, articleSection, about, proficiencyLevel = "Beginner", dependencies, keywords = [], datePublished, dateModified, image, inLanguage = "en"}) => {
  const baseUrl = "https://www.edenai.co/docs";
  const canonicalUrl = `${baseUrl}/${path}`.replace(/\/+$/, "");
  const ogParams = new URLSearchParams({
    division: articleSection || "",
    title: title || "",
    description: description || ""
  });
  const resolvedImage = image || `https://edenai.mintlify.app/_mintlify/api/og?${ogParams.toString()}`;
  const data = {
    "@context": "https://schema.org",
    "@type": "TechArticle",
    "@id": `${canonicalUrl}#techarticle`,
    mainEntityOfPage: {
      "@type": "WebPage",
      "@id": canonicalUrl
    },
    headline: title,
    name: title,
    description: description,
    url: canonicalUrl,
    inLanguage: inLanguage,
    isPartOf: {
      "@type": "WebSite",
      name: "Eden AI Documentation",
      url: baseUrl
    },
    author: [{
      "@type": "Organization",
      name: "Eden AI",
      url: "https://www.edenai.co/"
    }],
    publisher: {
      "@type": "Organization",
      name: "Eden AI",
      url: "https://www.edenai.co/",
      logo: {
        "@type": "ImageObject",
        url: "https://www.edenai.co/assets/logo.png"
      }
    }
  };
  if (articleSection) data.articleSection = articleSection;
  if (about) data.about = {
    "@type": "Thing",
    name: about
  };
  if (proficiencyLevel) data.proficiencyLevel = proficiencyLevel;
  if (dependencies) data.dependencies = dependencies;
  if (keywords && keywords.length) data.keywords = keywords;
  if (datePublished) data.datePublished = datePublished;
  if (dateModified) data.dateModified = dateModified;
  data.image = Array.isArray(resolvedImage) ? resolvedImage : [resolvedImage];
  const json = JSON.stringify(data);
  const schemaId = `techarticle-${canonicalUrl}`;
  React.useEffect(() => {
    if (typeof document === "undefined") return;
    document.querySelectorAll(`script[data-schema-id="${schemaId}"]`).forEach(n => n.remove());
    const script = document.createElement("script");
    script.type = "application/ld+json";
    script.dataset.schemaId = schemaId;
    script.textContent = json;
    document.head.appendChild(script);
    return () => script.remove();
  }, [json, schemaId]);
  return null;
};

<TechArticleSchema title={"Image Generation"} description={"Generate and edit images with the OpenAI-compatible /v3/images endpoints."} path="v3/llms/image-generation" articleSection="LLMs" about={"LLM API"} proficiencyLevel="Intermediate" keywords={["Eden AI", "AI API", "image generation", "image editing", "OpenAI compatible", "gpt-image", "gemini image"]} datePublished="2026-05-06T00:00:00Z" dateModified="2026-06-11T00:00:00Z" />

Generate and edit images through Eden AI's OpenAI-compatible image endpoints. Point any OpenAI client at `https://api.edenai.run/v3` and the images API works as a drop-in replacement.

## Overview

Image models are served by dedicated image endpoints — **not** the chat completions endpoint:

| Method | Path                     | Purpose                                              |
| ------ | ------------------------ | ---------------------------------------------------- |
| `POST` | `/v3/images/generations` | Generate one or more images from a text prompt       |
| `POST` | `/v3/images/edits`       | Edit an existing image with a prompt (optional mask) |
| `GET`  | `/v3/images/models`      | List the image models available in your region       |

Both endpoints return the standard OpenAI image shape — `data: [{ url \| b64_json }]` — plus Eden's `cost` (USD) and `provider` fields.

<Warning>
  Image models are only available on `/v3/images/*`. Sending one to `/v3/chat/completions` returns `400 — Model(s) do not support /chat/completions`.
</Warning>

<Info>
  This is different from [Expert Model image generation](/v3/expert-models/features/image/generation), which wraps Eden's feature API for providers like DALL-E and Stable Diffusion. Use the `/v3/images` endpoints when you want an OpenAI-compatible, drop-in image surface.
</Info>

## Models

The image surface spans many providers. A few common model strings:

| Provider  | Model string                                                                                           |
| --------- | ------------------------------------------------------------------------------------------------------ |
| Google    | `google/gemini-2.5-flash-image`, `google/gemini-3-pro-image-preview`, `google/imagen-4.0-generate-001` |
| OpenAI    | `openai/gpt-image-1`, `openai/gpt-image-1-mini`                                                        |
| Stability | `stabilityai/sd3.5-large`                                                                              |
| Amazon    | `amazon/amazon.nova-canvas-v1:0`                                                                       |

Call `GET /v3/images/models` for the full, region-aware list (image models also appear in `GET /v3/models`, so the OpenAI SDK's `client.models.list()` returns them too).

## Generating images

<CodeGroup>
  ```python Python theme={null}
  import requests

  url = "https://api.edenai.run/v3/images/generations"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
  }

  payload = {
      "model": "google/gemini-2.5-flash-image",
      "prompt": "A nano banana dish in a fancy restaurant, cinematic lighting",
      "size": "1024x1024",
      "n": 1,
  }

  response = requests.post(url, headers=headers, json=payload)
  result = response.json()

  # Each item carries either a hosted `url` or an inline base64 `b64_json`
  image = result["data"][0]
  print(image["url"] or image["b64_json"][:60])
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.edenai.run/v3/images/generations \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "google/gemini-2.5-flash-image",
      "prompt": "A nano banana dish in a fancy restaurant, cinematic lighting",
      "size": "1024x1024",
      "n": 1
    }'
  ```
</CodeGroup>

Because the surface is OpenAI-compatible, the official OpenAI SDK works unchanged — just set `base_url`:

<CodeGroup>
  ```python OpenAI SDK theme={null}
  from openai import OpenAI

  client = OpenAI(base_url="https://api.edenai.run/v3", api_key="YOUR_API_KEY")

  result = client.images.generate(
      model="google/gemini-2.5-flash-image",
      prompt="A nano banana dish in a fancy restaurant, cinematic lighting",
      size="1024x1024",
      n=1,
  )
  print(result.data[0].url or result.data[0].b64_json[:60])
  ```
</CodeGroup>

### Request parameters

| Field             | Required | Description                                                                                  |
| ----------------- | -------- | -------------------------------------------------------------------------------------------- |
| `model`           | yes      | `provider/model`, e.g. `google/gemini-2.5-flash-image`                                       |
| `prompt`          | yes      | Text description of the image to generate (1–32,000 chars)                                   |
| `n`               | no       | Number of images to generate (1–10)                                                          |
| `size`            | no       | Output resolution, e.g. `1024x1024`, `1536x1024`, `auto`. Allowed values depend on the model |
| `quality`         | no       | `standard`, `hd`, `auto` — accepted values depend on the model                               |
| `response_format` | no       | `url` or `b64_json`, forwarded to providers that honor it                                    |

Unknown fields are forwarded to the provider unchanged.

## Response format

```json theme={null}
{
  "created": 1779792103,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUg...",
      "url": null,
      "revised_prompt": null
    }
  ],
  "output_format": "png",
  "size": "1024x1024",
  "usage": {
    "total_tokens": 291,
    "input_tokens": 19,
    "output_tokens": 272
  },
  "cost": 0.010975,
  "provider": "google"
}
```

### Saving the image to disk

<CodeGroup>
  ```python Python theme={null}
  import base64

  # Assuming `result` is the response from POST /v3/images/generations above
  image = result["data"][0]

  if image["b64_json"]:
      with open("output.png", "wb") as f:
          f.write(base64.b64decode(image["b64_json"]))
  else:
      # The provider returned a hosted URL instead of inline base64
      import requests
      with open("output.png", "wb") as f:
          f.write(requests.get(image["url"]).content)
  ```
</CodeGroup>

<Note>
  Some providers return a hosted `url` instead of inline `b64_json`. Download the image if you want to keep it, since those URLs can expire.
</Note>

## Editing images

`POST /v3/images/edits` takes the same fields as generations plus an `images` array. Each entry sets exactly one of `file_id` (returned by Eden's `/v3/upload/...` endpoints) or `image_url` (an `https://` URL or a `data:image/...;base64,...` URL). An optional `mask` (same shape) marks the regions to edit.

The endpoint dispatches on `Content-Type`: send `application/json` for the `images[]` form below, or `multipart/form-data` for the classic OpenAI SDK file-upload form.

<CodeGroup>
  ```python Python theme={null}
  import requests

  url = "https://api.edenai.run/v3/images/edits"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
  }

  payload = {
      "model": "google/gemini-2.5-flash-image",
      "prompt": "Add a small red hat",
      "images": [
          {"image_url": "https://example.com/photo.png"}
      ],
      "size": "1024x1024",
  }

  response = requests.post(url, headers=headers, json=payload)
  result = response.json()
  print(result["data"][0]["b64_json"][:60])
  ```
</CodeGroup>

<Info>
  `image_url` with an `https://` URL works for providers that accept remote URLs (e.g. Gemini). For `openai/gpt-image-*`, pass a `data:` URL or upload the file via `/v3/upload/...` and reference it by `file_id` instead — those models do not accept remote URLs.
</Info>

## Listing image models

```bash cURL theme={null}
curl https://api.edenai.run/v3/images/models \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Limitations

* **No streaming.** `stream: true` is forwarded to the provider but the partial-image pipeline is not wired up.
* **No `@edenai` router or `fallbacks`.** Specify a single explicit `provider/model`.
* **`/v3/images/variations` is not implemented.**

## Next Steps

<CardGroup cols={2}>
  <Card title="Expert Image Generation" icon="palette" href="/v3/expert-models/features/image/generation">
    Use Eden's feature API for DALL-E, Stable Diffusion, and more
  </Card>

  <Card title="Chat Completions" icon="comment-dots" href="/v3/llms/chat-completions">
    Standard text chat completions reference
  </Card>
</CardGroup>
