Generate content
Gunakan format API native Gemini melalui CometAPI untuk pembuatan teks, input multimodal, reasoning, function calling, Google Search grounding, mode JSON, dan streaming.
x-goog-api-key dan Authorization: Bearer keduanya didukung untuk autentikasi.Quick start
Untuk menggunakan SDK Gemini atau klien HTTP apa pun dengan CometAPI, ganti base URL dan API key:Kirim input video
GeminigenerateContent menerima video sebagai bagian konten. Pilih bentuk input berdasarkan tempat video disimpan:
inlineData.mimeType dan fileData.fileUri. Jangan kirim media URL sebagai file_data.file_uri.fileData.fileUri:
generateContent itu sendiri menggunakan inlineData atau fileData.fileUri.
Konfigurasikan 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.
Atur instruksi sistem
Untuk memandu perilaku model di seluruh percakapan, gunakansystemInstruction:
Minta output JSON
Untuk memaksa output JSON terstruktur, setelresponseMimeType. 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 keyakinan.
Contoh response
Response umum dari endpoint Gemini CometAPI:thoughtsTokenCount dalam usageMetadata menunjukkan berapa banyak token yang digunakan model untuk penalaran internal, bahkan ketika output pemikiran tidak disertakan dalam response.Perbandingan dengan endpoint kompatibel OpenAI
Otorisasi
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_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
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.
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.