Gemini Generating Content
Gunakan format API native Gemini melalui CometAPI untuk generasi teks, input multimodal, thinking/reasoning, function calling, grounding Google Search, mode JSON, dan streaming.
CometAPI mendukung format API native Gemini, memberi Anda akses penuh ke fitur khusus Gemini seperti kontrol thinking, grounding Google Search, modality generasi gambar native, dan lainnya. Gunakan endpoint ini saat Anda memerlukan kapabilitas yang tidak tersedia melalui endpoint chat yang kompatibel dengan 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 maupun Authorization: Bearer didukung untuk autentikasi.Mulai cepat
Untuk menggunakan SDK Gemini atau klien HTTP apa pun dengan CometAPI, ganti base URL dan API key:| Setting | Default Google | CometAPI |
|---|---|---|
| Base URL | generativelanguage.googleapis.com | api.cometapi.com |
| API Key | $GEMINI_API_KEY | $COMETAPI_KEY |
Konfigurasi thinking (reasoning)
Model Gemini dapat melakukan reasoning internal sebelum menghasilkan respons. Metode kontrolnya bergantung pada generasi model.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel untuk mengontrol kedalaman reasoning. Level yang tersedia: MINIMAL, LOW, MEDIUM, HIGH.Gunakan gemini-3-flash-preview sebagai model contoh default kecuali Anda secara khusus memerlukan varian Gemini 3 yang berbeda.Stream respons
Untuk menerima Server-Sent Events saat model menghasilkan konten, gunakanstreamGenerateContent?alt=sse sebagai operator. Setiap event SSE berisi baris data: dengan objek JSON GenerateContentResponse.
Tetapkan instruksi sistem
Untuk memandu perilaku model di seluruh percakapan, gunakansystemInstruction:
Output JSON permintaan
Untuk memaksa output JSON terstruktur, aturresponseMimeType. Secara opsional, berikan responseSchema untuk validasi skema yang ketat:
Grounding dengan Google Search
Untuk mengaktifkan pencarian web real-time, tambahkan toolgoogleSearch:
groundingMetadata dengan URL sumber dan skor kepercayaan.
Contoh respons
Respons yang umum dari endpoint Gemini milik CometAPI:thoughtsTokenCount dalam usageMetadata menunjukkan berapa banyak token yang dihabiskan model untuk penalaran internal, bahkan ketika output pemikiran tidak disertakan dalam respons.Bandingkan dengan endpoint yang kompatibel dengan OpenAI
| Fitur | Gemini Native (/v1beta/models/...) | OpenAI-Compatible (/v1/chat/completions) |
|---|---|---|
| Kontrol thinking | thinkingConfig with thinkingLevel / thinkingBudget | Tidak tersedia |
| Grounding Google Search | tools: [\{"google_search": \{\}\}] | Tidak tersedia |
| Grounding Google Maps | tools: [\{"googleMaps": \{\}\}] | Tidak tersedia |
| Modalitas pembuatan gambar | responseModalities: ["IMAGE"] | Tidak tersedia |
| Header auth | x-goog-api-key atau Bearer | Hanya Bearer |
| Format respons | Native Gemini (candidates, parts) | Format OpenAI (choices, message) |
Otorisasi
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer <key>) is also supported.
Parameter Path
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
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.
Respons
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.