Gemini コンテンツ生成
CometAPI を通じて Gemini ネイティブ API 形式を使用し、テキスト生成、マルチモーダル(Multimodal)入力、thinking/reasoning、関数呼び出し(Function Calling)、Google Search グラウンディング、JSON モード、ストリーミング(Streaming)を利用できます。
CometAPI は Gemini ネイティブ API 形式をサポートしており、thinking 制御、Google Search グラウンディング、ネイティブ画像生成モダリティなど、Gemini 固有の機能に完全にアクセスできます。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 と Authorization: Bearer ヘッダーの両方をサポートしています。クイックスタート
CometAPI で Gemini SDK または HTTP クライアントを使用するには、ベース URL と API キーを置き換えます。| Setting | Google Default | CometAPI |
|---|---|---|
| ベース URL | generativelanguage.googleapis.com | api.cometapi.com |
| API キー | $GEMINI_API_KEY | $COMETAPI_KEY |
thinking(reasoning)を設定する
Gemini モデルは、レスポンスを生成する前に内部で推論(Inference)を行うことがあります。制御方法はモデル世代によって異なります。- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel を使用します。利用可能なレベルは MINIMAL、LOW、MEDIUM、HIGH です。特別に別の Gemini 3 バリアントが必要でない限り、デフォルトの例示モデルとして gemini-3-flash-preview を使用してください。レスポンスをストリーミングする
モデルがコンテンツを生成する際に Server-Sent Events を受け取るには、operator としてstreamGenerateContent?alt=sse を使用します。各 SSE イベントには、JSON の GenerateContentResponse オブジェクトを含む data: 行が含まれます。
システム指示を設定する
会話全体を通してモデルの振る舞いを誘導するには、systemInstruction を使用します。
JSON 出力をリクエストする
構造化された JSON 出力を強制するには、responseMimeType を設定します。厳密なスキーマ検証のために、必要に応じて responseSchema も指定できます。
Google Search でグラウンディングする
リアルタイムのウェブ検索を有効にするには、googleSearch ツールを追加します。
groundingMetadata が含まれます。
レスポンス例
CometAPI の Gemini エンドポイントからの典型的なレスポンス:usageMetadata 内の thoughtsTokenCount フィールドは、思考出力がレスポンスに含まれていない場合でも、モデルが内部推論に費やしたトークン数を示します。OpenAI 互換エンドポイントとの比較
| 機能 | Gemini Native (/v1beta/models/...) | OpenAI-Compatible (/v1/chat/completions) |
|---|---|---|
| 思考制御 | thinkingConfig と thinkingLevel / thinkingBudget | 利用不可 |
| Google Search グラウンディング | tools: [\{"google_search": \{\}\}] | 利用不可 |
| Google Maps グラウンディング | tools: [\{"googleMaps": \{\}\}] | 利用不可 |
| 画像生成モダリティ | responseModalities: ["IMAGE"] | 利用不可 |
| 認証ヘッダー | x-goog-api-key または Bearer | Bearer のみ |
| レスポンス形式 | Gemini ネイティブ(candidates, parts) | OpenAI 形式(choices, message) |
承認
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer <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 ボディ
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.