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

# Image Generation

### Supported models

Only the following models support generating and editing images in chat:

* `gemini-nano-banana-2.1`
* `gemini-3.1-flash-lite-image`
* `gemini-3.1-flash-image`
* `gemini-3-pro-image`
* `gemini-2.5-flash-image`
* `gpt-4o-image`
* `gpt-5-all`
* `midjourney-chat`

> [!NOTE]
>
> This guide covers the basics. For Gemini-specific instructions, see the [Gemini image generation guide](https://docs.geekai.co/en/docs/image/google/nano-banana.md).

### Generate an image

Send an image generation request just like a regular text chat request:

```bash curl theme={null}
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gemini-nano-banana-2.1",
    "messages": [
        {
            "role": "user",
            "content": "Draw a cute kitten playing in the grass."
        }
    ]
}'
```

```bash python theme={null}
# Install the OpenAI SDK first: `pip3 install openai`

from openai import OpenAI

client = OpenAI(api_key="$GEEKAI_API_KEY", base_url="https://geekai.co/api/v1")

response = client.chat.completions.create(
    model="gemini-nano-banana-2.1",
    messages=[
        {
            "role": "user",
            "content": "Draw a cute kitten playing in the grass."
        },
    ]
)

print(response.choices[0].message.content)
```

```bash javascript theme={null}
// Install the OpenAI SDK first: `npm install openai`

import OpenAI from "openai";

const openai = new OpenAI({
    baseURL: 'https://geekai.co/api/v1',
    apiKey: '$GEEKAI_API_KEY'
});

async function main() {
    const completion = await openai.chat.completions.create({
        messages: [{ role: "user", content: "Draw a cute kitten playing in the grass." }],
        model: "gemini-nano-banana-2.1",
    });

    console.log(completion.choices[0].message.content);
}

main();
```

```bash go theme={null}
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	requestBody := map[string]interface{}{
		"model": "gemini-nano-banana-2.1",
		"messages": []interface{}{
            map[string]interface{}{
                "role": "user",
                "content": "Draw a cute kitten playing in the grass.",
            },
        }
	}

	jsonData, err := json.Marshal(requestBody)
	if err != nil {
		panic(err)
	}

	client := &http.Client{}
	req, err := http.NewRequest("POST", "https://geekai.co/api/v1/chat/completions", bytes.NewBuffer(jsonData))
	if err != nil {
		panic(err)
	}

	req.Header.Set("Authorization", "Bearer $GEEKAI_API_KEY")
	req.Header.Set("Content-Type", "application/json")

	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(body))
}
```

`gpt-4o-image`, `gpt-5-all`, and `midjourney-chat` support streaming output. Gemini models do not stream image output, but they support [background mode](https://docs.geekai.co/en/docs/chat/background.md).

The `image.url` field contains the generated image URL. Display the image from that URL, or pass `content` directly to a component that renders Markdown:

```json theme={null}
{
    "id": "1061a101-5fe0-44bd-9281-6fb6565dbd0a",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Here is a cute kitten playing in the grass: \n![](https://static.geekai.co/image/2025/09/22/81e1cc5fc52a70c738f99b9037957bb4.png)\n",
                "image": {
                    "url": "https://static.geekai.co/image/2025/09/22/81e1cc5fc52a70c738f99b9037957bb4.png"
                }
            },
            "finish_reason": "stop"
        }
    ],
    "model": "gemini-nano-banana-2.1",
    "object": "chat.completion",
    "usage": {
        ...
    }
}
```

### Edit an image

To generate an image from another image or edit an existing image, include it in an [image chat request](https://docs.geekai.co/en/docs/chat/image.md):

```bash curl theme={null}
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gemini-nano-banana-2.1",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Replace the Chinese text in the image with GeekAI in English. Keep the font style and size unchanged."
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://static.geekai.co/icon/geekai-logo-main-tr.png"
            }
          }
        ]
      }
    ]
}'
```

```bash python theme={null}
# Install the OpenAI SDK first: `pip3 install openai`

from openai import OpenAI

client = OpenAI(api_key="$GEEKAI_API_KEY", base_url="https://geekai.co/api/v1")

response = client.chat.completions.create(
    model="gemini-nano-banana-2.1",
    messages=[
        {"role": "user", "content": [
            {"type": "text", "text": "Replace the Chinese text in the image with GeekAI in English. Keep the font style and size unchanged."},
            {"type": "image_url", "image_url": {"url": "https://static.geekai.co/icon/geekai-logo-main-tr.png"}}
        ]}
    ]
)

print(response.choices[0].message.content)
```

```bash javascript theme={null}
// Install the OpenAI SDK first: `npm install openai`

import OpenAI from "openai";

const openai = new OpenAI({
    baseURL: 'https://geekai.co/api/v1',
    apiKey: '$GEEKAI_API_KEY'
});

async function main() {
    const completion = await openai.chat.completions.create({
        messages: [{ role: "user", content: [
            { "type": "text", "text": "Replace the Chinese text in the image with GeekAI in English. Keep the font style and size unchanged." },
            { "type": "image_url", "image_url": { "url": "https://static.geekai.co/icon/geekai-logo-main-tr.png" } }
        ]}],
        model: "gemini-nano-banana-2.1",
    });

    console.log(completion.choices[0].message.content);
}

main();
```

```bash go theme={null}
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	requestBody := map[string]interface{}{
		"model": "gemini-nano-banana-2.1",
		"messages": []interface{}{
            map[string]interface{}{
                "role": "user",
                "content": []interface{}{
                    map[string]interface{}{
                        "type": "text",
                        "text": "Replace the Chinese text in the image with GeekAI in English. Keep the font style and size unchanged.",
                    },
                    map[string]interface{}{
                        "type": "image_url",
                        "image_url": map[string]string{
                            "url": "https://static.geekai.co/icon/geekai-logo-main-tr.png",
                        },
                    },
                },
            },
        }
	}

	jsonData, err := json.Marshal(requestBody)
	if err != nil {
		panic(err)
	}

	client := &http.Client{}
	req, err := http.NewRequest("POST", "https://geekai.co/api/v1/chat/completions", bytes.NewBuffer(jsonData))
	if err != nil {
		panic(err)
	}

	req.Header.Set("Authorization", "Bearer $GEEKAI_API_KEY")
	req.Header.Set("Content-Type", "application/json")

	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(body))
}
```

The `url` property of `image_url` accepts a valid image URL or Base64-encoded image data.

### If Gemini does not return an image

If a Gemini image generation model does not return an image, try the following:

1. **Set a system prompt:** Explicitly instruct the model to draw, for example: `You are an AI image generator. Draw the image the user requests.`.
2. **Set the request parameter:** Set `image_generation` to `true` to require image generation.

```bash theme={null}
curl --location --request POST 'https://geekai.co/api/v1/chat/completions' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gemini-nano-banana-2.1",
    "messages": [
        {
            "role": "system",
            "content": "You are an AI image generator. Draw the image the user requests."
        },
        {
            "role": "user",
            "content": "A cute kitten playing in the grass"
        }
    ],
    "image_generation": true
}'
```

### Use the Responses API

OpenAI's Responses API offers an image generation tool for generating and editing images in chat. It supports models beyond `gpt-4o` and offers more parameters. See [image generation with the Responses API](https://docs.geekai.co/en/docs/response/image_generation.md).


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