İçerik oluştur
Metin üretimi, multimodal girdi, reasoning, function calling, Google Search grounding, JSON modu ve streaming için CometAPI üzerinden Gemini yerel API biçimini kullanın.
x-goog-api-key hem de Authorization: Bearer başlıkları desteklenir.Hızlı başlangıç
CometAPI ile herhangi bir Gemini SDK’sını veya HTTP istemcisini kullanmak için base URL’yi ve API anahtarını değiştirin:Video girdisi gönderme
GeminigenerateContent, videoyu bir içerik parçası olarak kabul eder. Videonun nerede depolandığına göre giriş şeklini seçin:
inlineData.mimeType ve fileData.fileUri gibi camelCase alan adlarını kullanın. URL medyasını file_data.file_uri olarak göndermeyin.fileData.fileUri ile genel bir MP4 URL’si gönderir:
inlineData veya fileData.fileUri ile doğrudan generateContent isteğinin içinde gönderin.
Thinking’i yapılandırma (reasoning)
Gemini modelleri, bir yanıt üretmeden önce dahili reasoning gerçekleştirebilir. Kontrol yöntemi, model nesline bağlıdır.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel kullanır. Kullanılabilir seviyeler: MINIMAL, LOW, MEDIUM, HIGH.Özellikle farklı bir Gemini 3 varyantına ihtiyacınız yoksa varsayılan örnek model olarak gemini-3-flash-preview kullanın.Yanıtları stream etme
Model içerik üretirken Server-Sent Events almak için operatör olarakstreamGenerateContent?alt=sse kullanın. Her SSE olayı, JSON GenerateContentResponse nesnesi içeren bir data: satırı barındırır.
System instructions ayarlama
Tüm konuşma boyunca modelin davranışını yönlendirmek içinsystemInstruction kullanın:
JSON çıktı isteme
Yapılandırılmış JSON çıktısını zorlamak içinresponseMimeType ayarlayın. Katı şema doğrulaması için isteğe bağlı olarak responseSchema sağlayabilirsiniz:
Google Search ile Grounding ekleme
Gerçek zamanlı web aramasını etkinleştirmek için birgoogleSearch aracı ekleyin:
groundingMetadata içerir.
Yanıt örneği
CometAPI’nin Gemini endpoint’inden tipik bir yanıt:usageMetadata içindeki thoughtsTokenCount alanı, düşünme çıktısı yanıta dahil edilmese bile modelin dahili akıl yürütme için kaç token harcadığını gösterir.OpenAI-compatible endpoint ile karşılaştırma
Yetkilendirmeler
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.
Yol Parametreleri
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 Gövde
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.
Yanıt
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.