Generowanie treści
Używaj natywnego formatu API Gemini przez CometAPI do generowania tekstu, wejścia multimodalnego, rozumowania, Function Calling, osadzania w Google Search, trybu JSON i Streaming.
x-goog-api-key, jak i Authorization: Bearer.Szybki start
Aby używać dowolnego SDK Gemini lub klienta HTTP z CometAPI, zamień bazowy URL i klucz API:Wysyłanie wejścia wideo
GeminigenerateContent akceptuje wideo jako część content. Wybierz format wejścia w zależności od tego, gdzie przechowywane jest wideo:
inlineData.mimeType i fileData.fileUri. Nie wysyłaj mediów URL jako file_data.file_uri.fileData.fileUri:
generateContent, używając inlineData lub fileData.fileUri.
Konfigurowanie thinking (reasoning)
Modele Gemini mogą wykonywać wewnętrzne rozumowanie przed wygenerowaniem odpowiedzi. Metoda sterowania zależy od generacji modelu.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel do kontrolowania głębokości rozumowania. Dostępne poziomy: MINIMAL, LOW, MEDIUM, HIGH.Używaj gemini-3-flash-preview jako domyślnego przykładowego modelu, chyba że potrzebujesz konkretnego innego wariantu Gemini 3.Stream odpowiedzi
Aby otrzymywać Server-Sent Events podczas generowania treści przez model, użyjstreamGenerateContent?alt=sse jako operatora. Każde zdarzenie SSE zawiera linię data: z obiektem JSON GenerateContentResponse.
Ustawianie instrukcji systemowych
Aby kierować zachowaniem modelu w całej rozmowie, użyjsystemInstruction:
Żądanie wyjścia JSON
Aby wymusić uporządkowane wyjście JSON, ustawresponseMimeType. Opcjonalnie podaj responseSchema do ścisłej walidacji względem schematu:
Ground z Google Search
Aby włączyć wyszukiwanie w sieci w czasie rzeczywistym, dodaj narzędziegoogleSearch:
groundingMetadata z adresami URL źródeł i ocenami pewności.
Przykład odpowiedzi
Typowa odpowiedź z endpointu Gemini w CometAPI:thoughtsTokenCount w usageMetadata pokazuje, ile tokenów model zużył na wewnętrzne rozumowanie, nawet jeśli wynik myślenia nie jest uwzględniony w odpowiedzi.Porównanie z endpointem kompatybilnym z OpenAI
Autoryzacje
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.
Parametry ścieżki
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 Treść
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.
Odpowiedź
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.