コンテンツ生成
CometAPI を通じて Gemini ネイティブ API 形式を使用し、テキスト生成、マルチモーダル入力、推論、関数呼び出し、Google Search グラウンディング、JSON モード、ストリーミングを利用できます。
x-goog-api-key と Authorization: Bearer ヘッダーの両方をサポートしています。クイックスタート
CometAPI で任意の Gemini SDK または HTTP クライアントを使用するには、base URL と API key を置き換えてください。動画入力を送信する
GeminigenerateContent は、content part として動画を受け付けます。動画の保存場所に応じて入力形式を選択してください。
inlineData.mimeType や fileData.fileUri のような Gemini の camelCase フィールド名を使用してください。URL メディアを file_data.file_uri として送信しないでください。fileData.fileUri を使って公開 MP4 URL を送信します。
inlineData または fileData.fileUri を使って、メディアを generateContent リクエスト自体に含めて送信してください。
思考(reasoning)を設定する
Gemini モデルは、レスポンスを生成する前に内部的な推論を実行できます。制御方法はモデル世代によって異なります。- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel を使用します。使用可能なレベル: MINIMAL、LOW、MEDIUM、HIGH。特定の Gemini 3 バリアントが必要でない限り、デフォルトの例示モデルとして gemini-3-flash-preview を使用してください。レスポンスをストリーミングする
モデルがコンテンツを生成する際に Server-Sent Events を受信するには、オペレーターとしてstreamGenerateContent?alt=sse を使用します。各 SSE イベントには、JSON の GenerateContentResponse オブジェクトを含む data: 行が含まれます。
システム指示を設定する
会話全体を通してモデルの振る舞いを導くには、systemInstruction を使用します:
JSON 出力をリクエストする
構造化された JSON 出力を強制するには、responseMimeType を設定します。必要に応じて、厳密なスキーマ検証のために responseSchema を指定することもできます:
Google Search でグラウンディングする
リアルタイムの Web 検索を有効にするには、googleSearch ツールを追加します:
groundingMetadata が含まれます。
レスポンス例
CometAPI の Gemini エンドポイントからの典型的なレスポンス:usageMetadata 内の thoughtsTokenCount フィールドは、thinking 出力がレスポンスに含まれていない場合でも、モデルが内部推論に使用したトークン数を示します。OpenAI 互換エンドポイントとの比較
承認
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.
パスパラメータ
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 ボディ
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.
レスポンス
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.