Inhalte generieren
Verwende das native Gemini-API-Format über CometAPI für Textgenerierung, multimodale Eingaben, Reasoning, Function Calling, Google Search Grounding, JSON-Modus und Streaming.
x-goog-api-key- als auch Authorization: Bearer-Header werden zur Authentifizierung unterstützt.Schnellstart
Um ein beliebiges Gemini SDK oder einen HTTP-Client mit CometAPI zu verwenden, ersetze die Base URL und den API-Schlüssel:Video-Eingabe senden
GeminigenerateContent akzeptiert Videos als content-Part. Wählen Sie die Eingabeform basierend darauf, wo das Video gespeichert ist:
inlineData.mimeType und fileData.fileUri. Senden Sie URL-Medien nicht als file_data.file_uri.fileData.fileUri:
generateContent-Anfrage mit inlineData oder fileData.fileUri.
Thinking konfigurieren (reasoning)
Gemini-Modelle können internes reasoning durchführen, bevor sie eine Antwort generieren. Die Steuerungsmethode hängt von der Modellgeneration ab.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel, um die reasoning-Tiefe zu steuern. Verfügbare Stufen: MINIMAL, LOW, MEDIUM, HIGH.Verwende gemini-3-flash-preview als Standard-Beispielmodell, es sei denn, du benötigst ausdrücklich eine andere Gemini-3-Variante.Responses streamen
Um Server-Sent Events zu empfangen, während das Modell Inhalte generiert, verwendestreamGenerateContent?alt=sse als Operator. Jedes SSE-Ereignis enthält eine data:-Zeile mit einem JSON-Objekt vom Typ GenerateContentResponse.
Systemanweisungen festlegen
Um das Verhalten des Modells über die gesamte Konversation hinweg zu steuern, verwendesystemInstruction:
JSON-Ausgabe anfordern
Um strukturierte JSON-Ausgabe zu erzwingen, setzeresponseMimeType. Optional kannst du ein responseSchema für eine strikte Schemavalidierung angeben:
Mit Google Search grounden
Um Websuche in Echtzeit zu aktivieren, füge eingoogleSearch-Tool hinzu:
groundingMetadata mit Quell-URLs und Konfidenzwerten.
Antwortbeispiel
Eine typische Antwort vom Gemini-Endpunkt von CometAPI:thoughtsTokenCount in usageMetadata zeigt, wie viele Tokens das Modell für internes Reasoning aufgewendet hat, selbst wenn die Thinking-Ausgabe nicht in der Antwort enthalten ist.Vergleich mit OpenAI-kompatiblem Endpunkt
Autorisierungen
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.
Pfadparameter
Gemini model ID. Example: gemini-3-flash-preview, gemini-2.5-pro. See the Models page for current options.
The operation to perform. Use generateContent for synchronous responses, or streamGenerateContent?alt=sse for Server-Sent Events streaming.
generateContent, streamGenerateContent?alt=sse Body
Conversation content. Each entry has an optional role (user or model) and a parts array.
System instructions that guide the model's behavior across the entire conversation. Text only.
Tools the model may use to generate responses. Supports function declarations, Google Search, Google Maps, and code execution.
Configuration for tool usage, such as function calling mode.
Safety filter settings. Override default thresholds for specific harm categories.
Configuration for model generation behavior including temperature, output length, and response format.
The name of cached content to use as context. Format: cachedContents/{id}. See the Gemini context caching documentation for details.
Antwort
Successful response. For streaming requests, the response is a stream of SSE events, each containing a GenerateContentResponse JSON object prefixed with data:.
The generated response candidates.
Feedback on the prompt, including safety blocking information.
Token usage statistics for the request.
The model version that generated this response.
The timestamp when this response was created (ISO 8601 format).
Unique identifier for this response.