API documentation

Gemini Images

Generate images with Gemini image models through chat completions.

Gemini image models work as chat models that can return images. Use /v1/chat/completions for both generation and editing, not /v1/images/generations and not /v1/images/edits. Supported ids include google/gemini-3.1-flash-image-preview and google/gemini-3-pro-image; use the exact model id from the catalog or /v1/models.

Request

Gemini image request
curl https://api.aigate.shop/v1/chat/completions \  -H "Authorization: Bearer sk-your-api-key" \  -H "Content-Type: application/json" \  -d '{    "model": "google/gemini-3.1-flash-image-preview",    "messages": [      {        "role": "user",        "content": "Generate an image of a small yellow banana-shaped robot on a white desk, studio lighting"      }    ],    "modalities": ["image", "text"]  }'

Image config

For aspect ratio and output size, send image_config at the top level of the request. aspect_ratio controls the aspect ratio, and image_size controls output size/quality such as 1K, 2K, or 4K when the selected model supports it.

Thunder Client JSON body
{  "model": "google/gemini-3-pro-image",  "messages": [    {      "role": "user",      "content": "Generate a sharp futuristic product render of a matte black AI gateway device on a white desk, studio lighting"    }  ],  "modalities": ["image", "text"],  "image_config": {    "aspect_ratio": "16:9",    "image_size": "2K"  }}

Response

Gemini image response
{  "id": "gate-1779703910",  "object": "chat.completion",  "created": 1779703910,  "model": "google/gemini-3.1-flash-image-preview",  "choices": [    {      "index": 0,      "message": {        "role": "assistant",        "content": null,        "images": [          {            "type": "image_url",            "image_url": {              "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."            }          }        ]      },      "finish_reason": "stop"    }  ]}

Edit an existing image

For editing, pass the source image as image_url inside messages. The text in the same message describes what to change. The model returns a new image as base64 inside a data URL.

Gemini image edit request
curl https://api.aigate.shop/v1/chat/completions \  -H "Authorization: Bearer sk-your-api-key" \  -H "Content-Type: application/json" \  -d '{    "model": "google/gemini-3.1-flash-image-preview",    "messages": [      {        "role": "user",        "content": [          {            "type": "text",            "text": "Edit this image: add a small orange cat sitting on the table. Keep the original lighting and style. Return the edited image."          },          {            "type": "image_url",            "image_url": {              "url": "https://picsum.photos/seed/aigate-edit-test/800/600"            }          }        ]      }    ],    "modalities": ["image", "text"]  }'
Gemini image edit response
{  "id": "gate-1779703910",  "object": "chat.completion",  "created": 1779703910,  "model": "google/gemini-3.1-flash-image-preview",  "choices": [    {      "index": 0,      "message": {        "role": "assistant",        "content": null,        "images": [          {            "type": "image_url",            "image_url": {              "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."            }          }        ]      },      "finish_reason": "stop"    }  ]}

Where to read the image

txt
choices[0].message.images[0].image_url.url
The response is a base64 data URL
image_url.url usually looks like data:image/png;base64,... . To save a file, take the part after the comma and decode base64. content can be null for image output.

Request fields

FieldRequiredMeaning
modelyesExact model id from the catalog.
messagesyesPut the prompt in a user message.
messages.content[].image_urledits/input imageSource image for editing or image input.
modalitiesyes["image", "text"]
image_confignoGemini image settings: aspect_ratio (for example 1:1 or 16:9) and image_size (for example 1K, 2K, or 4K when supported by the model).

Save a data URL

ts
import { writeFileSync } from "node:fs";const url = response.choices[0].message.images[0].image_url.url;if (url.startsWith("data:image/")) {  const [, base64] = url.split(",");  writeFileSync("gemini-image.png", Buffer.from(base64, "base64"));}

SillyImages

For the SillyImages SillyTavern extension, choose the Gemini API type. Put the base URL without /v1 in the endpoint field: https://api.aigate.shop. The extension sends generation to /v1beta/models/{model}:generateContent and loads models from /v1/models by itself.

SillyImages settings
API type: Gemini (nano-banana)Endpoint URL: https://api.aigate.shopAPI key: sk-your-api-keyModel: google/gemini-3-pro-imageAspect ratio: 16:9Image size: 2K

The compatible route accepts the Google contents/generationConfig shape and returns candidates/content/parts/inlineData so the extension can read the image directly.

Google-compatible request
curl https://api.aigate.shop/v1beta/models/google/gemini-3-pro-image:generateContent \  -H "Authorization: Bearer sk-your-api-key" \  -H "Content-Type: application/json" \  -d '{    "contents": [      {        "role": "user",        "parts": [          {            "text": "Generate a cinematic 16:9 image of a tiny banana-shaped robot in a rainy neon street"          }        ]      }    ],    "generationConfig": {      "responseModalities": ["TEXT", "IMAGE"],      "imageConfig": {        "aspectRatio": "16:9",        "imageSize": "2K"      }    }  }'
Google-compatible response
{  "candidates": [    {      "content": {        "role": "model",        "parts": [          {            "inlineData": {              "mimeType": "image/png",              "data": "iVBORw0KGgoAAAANSUhEUgAA..."            }          }        ]      },      "finishReason": "STOP",      "index": 0    }  ],  "usageMetadata": {    "promptTokenCount": 18,    "candidatesTokenCount": 1290,    "totalTokenCount": 1308  }}

Common mistakes

  • Do not send Gemini image models to /v1/images/generations or /v1/images/edits.
  • Do not forget modalities: ["image", "text"].
  • For size and aspect ratio, use image_config at the top level of the request.
  • Do not read only message.content.
  • Check the exact model id in /v1/models or the catalog.