Skip to main content
POST
CometAPI を介して Gemini ネイティブのリクエスト形式を使用し、テキストを生成し、動画入力を送信し、思考またはツールを設定します。例では gemini-3.8-flash を使用します。
Google の GenerateContent API リファレンス を参照して、フィールド定義とモデル固有のオプションを確認してください。このページでは、CometAPI のベース URL、認証、リクエスト例を紹介します。
認証には、x-goog-api-key ヘッダーと Authorization: Bearer ヘッダーの両方がサポートされています。

クイックスタート

Google Gen AI SDK または HTTP クライアントを CometAPI と使用するには、ベース URL と API キーを設定します。 ネイティブ API の例については、 GenerateContent テキスト生成ガイド を参照してください。ベース URL を変更する際も、generateContent のリクエスト形式を維持してください。

動画入力を送信

動画をコンテンツパートとして送信します。動画の保存場所に応じて入力形式を選択してください。
REST および curl リクエストでは、inlineData.mimeTypefileData.fileUri などの camelCase フィールド名を使用します。
この例ではインライン MP4 データを送信します。<base64-encoded-mp4> を動画の base64 コンテンツに置き換えてください:
この例では、花が開く公開 MP4 を分析します:

思考を設定 (推論)

推論の深さを調整するには、thinkingConfig.thinkingLevel を使用します。以下の例では、LOWMEDIUM を使用します。
この例では、思考レベルを LOW に設定します。
thinkingBudget は、Gemini 2.5 を含む互換モデル向けの数値コントロールです。Gemini 3 の例では thinkingLevel を使用し、両方のコントロールを送信しないでください。Google の 思考ガイド でモデル固有の値を確認してください。

レスポンスをストリーミング

Server-Sent Events を受信するには、streamGenerateContent?alt=sse を使用します。各 data: 行には JSON の GenerateContentResponse オブジェクトが含まれます。

システム指示を設定

レスポンスを導くには、systemInstruction を使用します。この例では、追加テキストなしで1つの数式をリクエストします。

JSON 出力をリクエスト

responseMimeTypeapplication/json に設定し、responseSchema を指定します。この例では、名前と数値の距離を持つ惑星の配列をリクエストします。

Google 検索でグラウンディング

検索グラウンディングをリクエストするには、googleSearch ツールを追加します。この例では、UEFA EURO 2024 決勝の結果を問い合わせます。
検索を使用する場合は、候補の groundingMetadata で検索クエリ、ソース URL、ソースとレスポンステキストの間のリンクを確認します。

会話コンテンツを保持

複数ターンの会話では、先行する usermodel のコンテンツを contents で送信します。SDK のチャット例では、この履歴が維持されます。 関数呼び出しでは、各 functionResponse に対して、対応する functionCall と返された name を含む id を 1 つ返します。先行するモデルコンテンツは、thoughtSignature フィールドを含めて変更せずにそのまま渡してください。署名は不透明なため、表示されたテキストから再構築しないでください。

レスポンスの例

テキストレスポンスには、生成されたコンテンツとトークン(Token)使用量が含まれます。この簡略化した例では、オプションのフィールドを省略しています。
thoughtsTokenCount レスポンスに思考の要約が含まれていない場合でも、内部の思考トークン(Token)が報告されます。各コンテンツ部分を確認してください。レスポンスにはテキスト、要約、または関数呼び出しを含めることができます。

リクエスト形式を比較

Gemini のリクエストおよびレスポンスフィールドにはネイティブエンドポイントを選択してください。OpenAI 互換形式については、 チャット補完 を参照してください。

承認

x-goog-api-key
string
header
必須

Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.

パスパラメータ

model
string
デフォルト:gemini-3.8-flash
必須

Gemini model ID. These examples use gemini-3.8-flash. See the Models page for available model IDs.

operator
enum<string>
デフォルト:generateContent
必須

Operation to perform. Use generateContent for a JSON response. For Server-Sent Events, select streamGenerateContent and set the separate alt query parameter to sse.

利用可能なオプション:
generateContent,
streamGenerateContent

クエリパラメータ

alt
enum<string>

Set to sse when the operator is streamGenerateContent. Omit this parameter for generateContent.

利用可能なオプション:
sse

ボディ

application/json
contents
object[]

Conversation content. Each entry has an optional role (user or model) and a parts array. For tool results, preserve the complete preceding model content, including any thoughtSignature fields.

systemInstruction
object

System instructions that guide the model's behavior across the entire conversation. Text only.

tools
object[]

Tools available to the model during generation. Use googleSearch for search grounding.

toolConfig
object

Configuration for tool usage, such as function calling mode.

safetySettings
object[]

Safety filter settings. Override default thresholds for specific harm categories.

generationConfig
object

Configuration for model generation behavior including temperature, output length, and response format.

cachedContent
string

The name of cached content to use as context. Format: cachedContents/{id}. See the Gemini context caching documentation for details.

レスポンス

200 - application/json

Successful response. For streaming requests, the response is a stream of SSE events, each containing a GenerateContentResponse JSON object prefixed with data:.

candidates
object[]

The generated response candidates.

promptFeedback
object

Feedback on the prompt, including safety blocking information.

usageMetadata
object

Token usage statistics for the request.

modelVersion
string

The model version that generated this response.

createTime
string

The timestamp when this response was created (ISO 8601 format).

responseId
string

Unique identifier for this response.

最終更新日 2026年9月8日