Gemini
Generate images with Gemini
Generate images with Gemini models via CometAPI — supports 4K, multi-turn editing, up to 14 reference images, and Thinking.
POST
/
v1beta
/
models
/
{model}
:generateContent
import os
from google import genai
from google.genai import types
client = genai.Client(
http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
api_key=os.environ.get("COMETAPI_KEY"),
)
response = client.models.generate_content(
model="gemini-3.1-flash-lite-image",
contents="A Monarch butterfly anatomical sketch on textured parchment",
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
image_config=types.ImageConfig(aspect_ratio="1:1", image_size="1K"),
),
)
final_image = None
for part in response.parts:
if getattr(part, "thought", False):
continue
if part.text:
print(part.text)
elif image := part.as_image():
final_image = image
if final_image:
final_image.save("output.png")
{
"candidates": [
{
"content": {
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"thought": true,
"thoughtSignature": "<string>"
}
]
},
"finishReason": "STOP",
"index": 123,
"safetyRatings": [
{
"category": "<string>",
"probability": "<string>"
}
]
}
],
"usageMetadata": {
"promptTokenCount": 123,
"candidatesTokenCount": 123,
"totalTokenCount": 123,
"thoughtsTokenCount": 123
}
}For step-by-step examples, see Use Gemini image models.
Gemini image generation options can change as Google updates image models and
generateContent. Check the Gemini image generation documentation for the latest complete parameter list and provider-specific behavior.gemini-2.5-flash-image is scheduled for shutdown by the provider on 2026-10-02. For new projects, use gemini-3.1-flash-image-preview or gemini-3-pro-image-preview. See Google’s deprecation schedule for details.Gemini image responses can include intermediate image parts where
thought is true. These are not the final output. When saving generated images, skip thought: true parts and use the last image part where inlineData exists and thought is not true.Path Parameters
The Gemini image model to use. See the Models page for current options.
Body
application/json
Last modified on July 3, 2026
⌘I
import os
from google import genai
from google.genai import types
client = genai.Client(
http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"},
api_key=os.environ.get("COMETAPI_KEY"),
)
response = client.models.generate_content(
model="gemini-3.1-flash-lite-image",
contents="A Monarch butterfly anatomical sketch on textured parchment",
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
image_config=types.ImageConfig(aspect_ratio="1:1", image_size="1K"),
),
)
final_image = None
for part in response.parts:
if getattr(part, "thought", False):
continue
if part.text:
print(part.text)
elif image := part.as_image():
final_image = image
if final_image:
final_image.save("output.png")
{
"candidates": [
{
"content": {
"role": "<string>",
"parts": [
{
"text": "<string>",
"inlineData": {
"mimeType": "<string>",
"data": "<string>"
},
"thought": true,
"thoughtSignature": "<string>"
}
]
},
"finishReason": "STOP",
"index": 123,
"safetyRatings": [
{
"category": "<string>",
"probability": "<string>"
}
]
}
],
"usageMetadata": {
"promptTokenCount": 123,
"candidatesTokenCount": 123,
"totalTokenCount": 123,
"thoughtsTokenCount": 123
}
}