Gemini
Bilder mit Gemini generieren
Bilder mit Gemini-Modellen über CometAPI generieren — unterstützt 4K, mehrstufige Bearbeitung, bis zu 14 Referenzbilder und 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
}
}Für Schritt-für-Schritt-Beispiele siehe Gemini-Bildmodelle verwenden.
Die Optionen für die Gemini-Bildgenerierung können sich ändern, wenn Google Bildmodelle und
generateContent aktualisiert. Prüfen Sie die Gemini image generation documentation für die aktuelle vollständige Parameterliste und anbieterspezifisches Verhalten.gemini-2.5-flash-image ist laut Anbieter für die Abschaltung am 2026-10-02 vorgesehen. Für neue Projekte verwenden Sie gemini-3.1-flash-image-preview oder gemini-3-pro-image-preview. Details finden Sie im deprecation schedule von Google.Gemini-Bildantworten können Zwischenbildteile enthalten, bei denen
thought den Wert true hat. Diese sind nicht die endgültige Ausgabe. Wenn Sie generierte Bilder speichern, überspringen Sie Teile mit thought: true und verwenden Sie den letzten Bildteil, bei dem inlineData vorhanden ist und thought nicht true ist.Pfadparameter
The Gemini image model to use. See the Models page for current options.
Body
application/json
Zuletzt geändert am 3. Juli 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
}
}