POST
/
v1
/
chat
/
completions
Chat Image Generation
curl --request POST \
  --url https://api.example.com/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "max_tokens": 123,
  "temperature": 123,
  "stream": true
}
'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {}
  ],
  "usage": {}
}
Official documentation: https://ai.google.dev/gemini-api/docs/image-generation
Generate and edit images using Gemini image generation models through the standard OpenAI Chat Completions API format.

Overview

This endpoint allows you to use Gemini’s image generation capabilities through the familiar OpenAI chat completions format. You can generate new images from text prompts or edit existing images by providing them as base64-encoded data.

Authentication

All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY

Request Parameters

model
string
required
The Gemini image model ID. For example: gemini-2.0-flash-exp-image-generation.
messages
array
required
A list of messages comprising the conversation. Supports multimodal content including text and images.For image editing, include an image_url object with base64-encoded image data:
{"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
max_tokens
integer
Maximum number of tokens to generate. Recommended: 4096.
temperature
number
default:"1"
Sampling temperature between 0 and 2.
stream
boolean
default:"false"
Whether to stream responses.

Request Example

curl -X POST https://www.anyfast.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "max_tokens": 4096,
    "model": "gemini-2.0-flash-exp-image-generation",
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "text", "text": "Change the theme color to red"},
          {"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64_IMAGE>"}}
        ]
      }
    ]
  }'

Response Example

{
  "id": "chatcmpl-gemini-img-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gemini-2.0-flash-exp-image-generation",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here is the edited image with the red theme applied."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 500,
    "completion_tokens": 200,
    "total_tokens": 700
  }
}

Response Fields

id
string
Unique identifier for the completion.
object
string
Object type, which is chat.completion.
created
integer
Unix timestamp of when the completion was created.
model
string
The model used.
choices
array
List of completion choices. The response may contain generated image data.
usage
object
Usage statistics for the request.

Available Models

  • gemini-2.0-flash-exp-image-generation