Gemini Generating Content
Używaj natywnego formatu API Gemini przez CometAPI do generowania tekstu, wejścia multimodalnego, myślenia/rozumowania, function calling, osadzania Google Search, trybu JSON i streamingu.
CometAPI obsługuje natywny format API Gemini, dając Ci pełny dostęp do funkcji specyficznych dla Gemini, takich jak kontrola myślenia, osadzanie Google Search, natywne modalności generowania obrazów i nie tylko. Użyj tego endpointu, gdy potrzebujesz możliwości niedostępnych przez endpoint czatu zgodny z OpenAI.Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
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:| Setting | Google Default | CometAPI |
|---|---|---|
| Bazowy URL | Domyślny Google | CometAPI |
| Klucz API | $GEMINI_API_KEY | $COMETAPI_KEY |
Konfigurowanie myślenia (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 konkretnie potrzebujesz innego wariantu Gemini 3.Streamuj odpowiedzi
Aby odbierać 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.
Ustaw instrukcje systemowe
Aby kierować zachowaniem modelu w całej rozmowie, użyjsystemInstruction:
Żądanie wyjścia JSON
Aby wymusić ustrukturyzowane wyjście JSON, ustawresponseMimeType. Opcjonalnie podaj responseSchema do ścisłej walidacji schematu:
Uziemianie za pomocą 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 przeznaczył na wewnętrzne rozumowanie, nawet jeśli wynik myślenia nie jest uwzględniony w odpowiedzi.Porównanie z endpointem kompatybilnym z OpenAI
| Funkcja | Gemini Native (/v1beta/models/...) | OpenAI-Compatible (/v1/chat/completions) |
|---|---|---|
| Kontrola myślenia | thinkingConfig z thinkingLevel / thinkingBudget | Niedostępne |
| Uziemianie przez Google Search | tools: [\{"google_search": \{\}\}] | Niedostępne |
| Uziemianie przez Google Maps | tools: [\{"googleMaps": \{\}\}] | Niedostępne |
| Modalność generowania obrazów | responseModalities: ["IMAGE"] | Niedostępne |
| Nagłówek uwierzytelniania | x-goog-api-key lub Bearer | Tylko Bearer |
| Format odpowiedzi | Natywny Gemini (candidates, parts) | Format OpenAI (choices, message) |
Autoryzacje
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer <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ść
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.