Gemini Chat Completion API の申請と使用

Google Gemini は非常に強力な AI 対話システムで、プロンプトを入力するだけで、わずか数秒で流暢で自然な応答を生成できます。Gemini は驚くほど優れたインテリジェントなサポートを提供し、人間の作業効率と創造性を大幅に向上させます。

このドキュメントでは、主に Gemini Chat Completion API の操作と使用の流れを紹介します。これを利用することで、公式 Gemini の対話機能を簡単に使用できます。

申請手順

Gemini Chat Completion API を使用するには、まず AI 聚合コンソール にアクセスして API Token を取得し、後で使用できるようにしておきます。

まだログインまたは登録していない場合は、自動的にログインページにリダイレクトされ、登録とログインを求められます。完了すると、自動的に現在のページに戻ります。

汎用アプリケーションの API Key は、アカウントで利用可能になっているサービスに使用できます。専用アプリケーションの Key は、そのアプリケーションのサービス範囲に応じて使用します。Key の権限、有効期限、上限を確認し、アプリケーションの残高が今回のリクエストの支払いに十分であることを確認してください。利用可能な試用枠はアカウントに表示される内容に従い、残高が不足している場合は「チャージ」ボタンをクリックしてください。

📘 完全なドキュメント:Gemini Chat Completion API →

基本的な使い方

続いて、図のように画面上で対応する内容を入力できます。

このインターフェースを初めて使用する際は、少なくとも 3 つの項目を入力する必要があります。1 つ目は authorization で、ドロップダウンリストから選択するだけです。もう 1 つのパラメータは model です。model は使用する Gemini 公式サイトのモデルの種類であり、選択可能なモデルはインターフェースのドキュメントにある model の列挙値に従います。最後のパラメータは messages です。messages は入力する質問文の配列であり、複数の質問文を同時に送信できることを意味します。各質問文には role と content が含まれます。role は質問者の役割を表し、user、assistant、system の 3 種類の役割が用意されています。もう 1 つの content は、質問の具体的な内容です。

また、右側には対応する呼び出しコードが生成されていることがわかります。コードをコピーして直接実行することも、「Try」ボタンを直接クリックしてテストすることもできます。

ヒント:gemini-3.x シリーズの flash は思考モデルであり、最初に reasoning tokens を消費します。max_tokens を 512 以上に設定してください。そうしないと、空の内容しか返されない場合があります。gemini-3.8-flash は現在推奨される Flash モデルで、最大 100 万 Token のコンテキスト、画像入力、ツール呼び出し、ストリーミング応答に対応しています。現在は Chat Completions インターフェースを通じて呼び出します。

gemini-4-argon も Chat Completions で使用でき、通常のテキスト応答とストリーミングテキスト応答に対応しています。出力予算の一部を思考に使用する場合があるため、複雑なタスクでは max_tokens に十分な余裕を持たせてください。Google はこのモデルの通常のタスクに対して、少なくとも 32768 を推奨しています。このインターフェースを Google Interactions API のバックグラウンド長文出力機能と同一視しないでください。

gemini-4-neon はソフトウェアエンジニアリングと資料分析に適しています。リクエスト本文で model をこの ID に設定し、思考と本文のために出力 Token を確保してください。

gemini-4-carbon と gemini-4-hydrogen も、このインターフェースの通常のテキスト応答とストリーミングテキスト応答に対応しています。Carbon は複雑な推論とエンジニアリングタスク向けで、Hydrogen は日常的なコーディングと複数ステップのタスク向けです。どちらも思考 Token を消費するため、max_tokens に十分な予算を確保する必要があります。ネイティブモデルの 100 万 Token の長文出力は、このインターフェースでその機能が提供されていることを意味しません。画像およびツール呼び出しのフィールドについては、引き続きこのインターフェースの公開仕様と実際の戻り値に従ってください。

呼び出し後、以下のような結果が返されます。

{
  "id": "chatcmpl-20251122212413908150493uPhjTUO9",
  "model": "gemini-3.5-flash",
  "object": "chat.completion",
  "created": 1763817866,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I am a large language model, trained by Google.",
        "reasoning_content": "**My Reasoning: Answering the User's Question**\n\nOkay, here's how I'm going to approach answering the user's question, \"What model are you?\". The core is to be direct and informative. First, I have to be clear about my origin. Then, I need to make sure the explanation is accessible, given that the user may not be familiar with technical jargon. I need to explain what a \"large language model\" actually *does*, and provide relatable examples. I know the user might be looking for a specific name, like other models have, so I'll address that directly and then wrap it up with an invitation to continue.\n\nSo, here's my plan:\n\n1.  **Lead with the key info:** I'll begin by stating that I am a large language model created by Google. That is the fundamental, most critical piece of the puzzle.\n2.  **Define the buzzword:** Then, I'll explain that \"large language model\" in simple terms. I'll explain what I *do* - process and generate text; how I *do* it - by training on huge amounts of text data; and the *goal* - to be able to communicate like a human.\n3.  **Provide context:** After that, to make the concept even clearer, I'll provide a list of examples of my capabilities. I'll mention things like answering questions, summarizing texts, writing stories, translating languages, and brainstorming ideas.\n4.  **Acknowledge the lack of a personal name:** I'll anticipate the likely question about a model name (like ChatGPT) by clearly stating that I don't have a personal name and that it's best to think of me as an AI assistant from Google.\n5.  **End with an invitation:** Lastly, I'll end with a simple, friendly question to invite further interaction and to guide the conversation.\n\nWith this approach, I am confident I can successfully answer this important question.\n"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 932,
    "total_tokens": 940,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "text_tokens": 8,
      "audio_tokens": 0,
      "image_tokens": 0
    },
    "completion_tokens_details": {
      "text_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 921
    },
    "input_tokens": 0,
    "output_tokens": 0,
    "input_tokens_details": null,
    "claude_cache_creation_5_m_tokens": 0,
    "claude_cache_creation_1_h_tokens": 0
  }
}

返される結果には複数のフィールドがあり、以下のとおりです。

  • id、今回の対話タスクに対して生成された ID で、今回の対話タスクを一意に識別するために使用されます。
  • model 、選択した Gemini 公式サイトのモデル。
  • choices、Gemini が質問文に対して返した回答情報。
  • usage :今回の質疑応答における token の統計情報。

このうち choices には Gemini の回答情報が含まれており、その中の choices は Gemini の回答の具体的な情報です。図のように確認できます。

`choices` 内の `content` フィールドに、Gemini の返信の具体的な内容が含まれていることがわかります。

画像理解(マルチモーダル入力)

Gemini はネイティブなマルチモーダルモデルで、直接「画像を見る」ことができます。画像を渡すには、メッセージの content を文字列からコンテンツブロックの配列に変更し、配列内に text ブロックと image_url ブロックを一緒に入れるだけです。これは OpenAI および公式 Gemini の OpenAI 互換形式と完全に一致しています。

image_url.url は次の2つの書き方に対応しています。

  • base64 data: URI(推奨、最も安定):形式は data:<メディアタイプ>;base64,<データ> で、例えば data:image/jpeg;base64,/9j/4AAQ... です。メディアタイプ(MIME)はすでに data: プレフィックス内に記載されているため、個別の media_type フィールドは必要なく、存在もしません。
  • 公開アクセス可能な画像 URL:例えば https://cdn.acedata.cloud/4hfydw.jpg です。

対応する画像形式:png、jpeg、webp、heic、heif。

Python の呼び出しコード例(base64 data URI):

import base64
import requests

url = "https://api.yxai-tech.top/gemini/chat/completions"

# 把本地图片读成 base64 data URI
with open("image.jpg", "rb") as f:
    base64_image = base64.b64encode(f.read()).decode("utf-8")
data_uri = f"data:image/jpeg;base64,{base64_image}"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "gemini-3.1-pro-preview",
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "请用一句话描述这张图片。"},
                {"type": "image_url", "image_url": {"url": data_uri}}
            ]
        }
    ]
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

公開アクセス可能な画像 URL を直接渡すこともできます。

payload = {
    "model": "gemini-3.1-pro-preview",
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "请用一句话描述这张图片。"},
                {"type": "image_url", "image_url": {"url": "https://cdn.acedata.cloud/4hfydw.jpg"}}
            ]
        }
    ]
}

💡 image_url が受け付けるのは url フィールド(値は画像 URL または base64 data: URI)と、オプションの detail フィールドのみです。media_type を渡さないでください。これは Anthropic Claude の画像フィールドであり、OpenAI / Gemini の image_url 形式には含まれません。

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

この API はストリーミングレスポンスにも対応しており、Web ページとの連携に非常に便利で、Web ページ上で文字を一つずつ表示する効果を実現できます。

レスポンスをストリーミングで返したい場合は、リクエストヘッダー内の stream パラメータを true に変更できます。

図に示すように変更しますが、ストリーミングレスポンスに対応するには、呼び出しコードにも対応する変更が必要です。

stream を true に変更すると、API は対応する JSON データを1行ずつ返します。1行ずつの結果を取得するには、コードに対応する変更を加える必要があります。

Python の呼び出しコード例:

import requests

url = "https://api.yxai-tech.top/gemini/chat/completions"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "gemini-2.5-pro",
    "messages": [{"role":"user","content":"Hello,What model are you?"}],
    "stream": True,
    "stream_options": {"include_usage": True}
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

出力結果は以下のとおりです。

data: {"id": "chatcmpl-20251122214038810722821kNjUTjtr", "object": "chat.completion.chunk", "created": 1763818842, "model": "gemini-2.5-pro", "system_fingerprint": null, "choices": [{"delta": {"content": "", "role": "assistant"}, "logprobs": null, "finish_reason": null, "index": 0}], "usage": null}

data: {"id": "chatcmpl-20251122214038810722821kNjUTjtr", "object": "chat.completion.chunk", "created": 1763818842, "model": "gemini-2.5-pro", "system_fingerprint": null, "choices": [{"delta": {"reasoning_content": "**Define My Nature**\n\nMy thinking has started. The user wants to know my nature, asking a direct \"what are you?\" The initial step was straightforward: identifying the query. Now, I recall my fundamental identity: I'm a large language model. This is the core truth I aim to convey.\n\n\n"}, "logprobs": null, "finish_reason": null, "index": 0}], "usage": null}

data: {"id": "chatcmpl-20251122214038810722821kNjUTjtr", "object": "chat.completion.chunk", "created": 1763818842, "model": "gemini-2.5-pro", "system_fingerprint": null, "choices": [{"delta": {"reasoning_content": "**Refining My Response**\n\nI've added the crucial information that I'm trained by Google to the basic \"large language model\" identity. My next step is considering what being a \"large language model\" actually entails, so I can explain my core capabilities. I'm focusing on providing context without going into specific technical details or model names. I want to convey my function in a way the user can easily understand.\n\n\n"}, "logprobs": null, "finish_reason": null, "index": 0}], "usage": null}

data: {"id": "chatcmpl-20251122214038810722821kNjUTjtr", "object": "chat.completion.chunk", "created": 1763818842, "model": "gemini-2.5-pro", "system_fingerprint": null, "choices": [{"delta": {"reasoning_content": "**Confirming Core Identity**\n\nI'm now solidifying my response. The user's query about my model affiliation needs a focused answer. I've pinpointed that \"trained by Google\" is essential, providing key context. I'm resisting the urge to mention any specific model names, as it's not relevant. The aim is to deliver a direct, accurate statement. My goal remains a clear and concise reply, avoiding technical jargon and getting straight to the relevant point.\n\n\n"}, "logprobs": null, "finish_reason": null, "index": 0}], "usage": null}

data: {"id": "chatcmpl-20251122214038810722821kNjUTjtr", "object": "chat.completion.chunk", "created": 1763818842, "model": "gemini-2.5-pro", "system_fingerprint": null, "choices": [{"delta": {"content": "I am a large language model, trained by Google."}, "logprobs": null, "finish_reason": null, "index": 0}], "usage": null}

data: {"id": "chatcmpl-20251122214038810722821kNjUTjtr", "object": "chat.completion.chunk", "created": 1763818842, "model": "gemini-2.5-pro", "system_fingerprint": null, "choices": [{"delta": {}, "logprobs": null, "finish_reason": "stop", "index": 0}], "usage": null}

data: {"id": "chatcmpl-20251122214038810722821kNjUTjtr", "object": "chat.completion.chunk", "created": 1763818842, "model": "gemini-2.5-pro", "system_fingerprint": "", "choices": [], "usage": {"prompt_tokens": 8, "completion_tokens": 527, "total_tokens": 535, "prompt_tokens_details": {"cached_tokens": 0, "text_tokens": 8, "audio_tokens": 0, "image_tokens": 0}, "completion_tokens_details": {"text_tokens": 0, "audio_tokens": 0, "reasoning_tokens": 519}, "input_tokens": 0, "output_tokens": 0, "input_tokens_details": null, "claude_cache_creation_5_m_tokens": 0, "claude_cache_creation_1_h_tokens": 0}}

data: [DONE]

ご覧のとおり、レスポンスには多数の data が含まれており、data 内の choices が最新の回答内容で、上記で紹介した内容と一致しています。choices は新たに追加された回答内容であり、結果に応じてお使いのシステムに連携できます。また、ストリーミングレスポンスの終了は data の内容に基づいて判断され、内容が [DONE] であれば、ストリーミングレスポンスの回答がすべて終了したことを示します。返される data の結果には複数のフィールドがあり、以下のとおりです:

  • id、今回の対話タスクに生成された ID で、今回の対話タスクを一意に識別するために使用されます。
  • model 、選択された Gemini 公式サイトのモデル。
  • choices、Gemini が質問に対して返す回答情報。

JavaScript もサポートされています。例えば、Node.js のストリーミング呼び出しコードは次のとおりです:

const options = {
  method: "POST",
  headers: {
    accept: "application/json",
    authorization: "Bearer {token}",
    "content-type": "application/json"
  },
  body: JSON.stringify({
    model: "gemini-2.5-pro",
    messages: [{ role: "user", content: "Hello, what model are you?" }],
    stream: true
  })
};

const response = await fetch("https://api.yxai-tech.top/gemini/chat/completions", options);
const reader = response.body.getReader();
const decoder = new TextDecoder("utf-8");
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  process.stdout.write(decoder.decode(value));
}

Java のサンプルコード:

JSONObject jsonObject = new JSONObject();
jsonObject.put("model", "gemini-2.5-pro");
jsonObject.put("messages", new JSONArray().put(new JSONObject().put("role", "user").put("content", "Hello, what model are you?")));
jsonObject.put("stream", true);
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(jsonObject.toString(), mediaType);
Request request = new Request.Builder()
  .url("https://api.yxai-tech.top/gemini/chat/completions")
  .post(body)
  .addHeader("accept", "application/json")
  .addHeader("authorization", "Bearer {token}")
  .addHeader("content-type", "application/json")
  .build();

OkHttpClient client = new OkHttpClient();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());

その他の言語については、ご自身で書き換えることができます。原理はすべて同じです。

複数ターンの対話

複数ターンの対話機能を連携したい場合は、messages フィールドに複数の質問を送信する必要があります。複数の質問の具体例を次の図に示します:

Python の呼び出しサンプルコード:

import requests

url = "https://api.yxai-tech.top/gemini/chat/completions"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "gemini-2.5-pro",
    "messages": [{"role":"user","content":"Hello"},{"role":"assistant","content":"Hello there! How can I help you today?"},{"role":"user","content":"What model are you?"}]
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

複数の質問を送信することで、複数ターンの対話を簡単に実現でき、次のような回答が得られます:

{
  "id": "chatcmpl-20251122214426669120974AKFwnJd1",
  "model": "gemini-2.5-pro",
  "object": "chat.completion",
  "created": 1763819072,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "I am a large language model, trained by Google.",
        "reasoning_content": "Okay, here's how I'd approach this, thinking as a sophisticated AI:\n\nFirst, the user is directly querying my core identity: \"What model are you?\" That's a simple, straightforward question. My primary task is to provide accurate and helpful information, so I need to answer this immediately.\n\nRight off the bat, I know the answer. I *am* a large language model. That's my fundamental architecture and operational principle. I'm built on a vast network of connections and trained on a massive dataset.\n\nThen I must add the necessary context. Crucially, I have to provide the source of my training. I *was* trained by Google. That's a key identifier. It provides the user with valuable information about my origin and potential biases (though I'm trained to mitigate them).\n\nNow I must construct the response. My goal is to be factual, concise, and understandable.\n\nThe synthesized response is something like: \"I am a large language model, trained by Google.\"\n\nI have to assess the output: Does it meet the criteria? It's clear. It states what I am, it includes a critical piece of information on my origins, and it avoids jargon. No misleading promises.\n\nFinal verification: Does it actually answer the question? Yes. Is the information correct and truthful? Yes. Is it concise? Absolutely. Is the tone appropriate for any user? Yes. And, finally, this is the standard, approved response. Excellent.\n"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 16,
    "completion_tokens": 265,
    "total_tokens": 281,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "text_tokens": 16,
      "audio_tokens": 0,
      "image_tokens": 0
    },
    "completion_tokens_details": {
      "text_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 254
    },
    "input_tokens": 0,
    "output_tokens": 0,
    "input_tokens_details": null,
    "claude_cache_creation_5_m_tokens": 0,
    "claude_cache_creation_1_h_tokens": 0
  }
}

ご覧のとおり、choices に含まれる情報は基本的な使用時の内容と一致しています。これには Gemini が複数の会話に対して返信した具体的な内容が含まれており、複数の会話内容に基づいて対応する質問に回答できます。

Gemini-3.0 マルチモーダルモデル

リクエスト例:

{
  "model": "gemini-3.1-pro-preview",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "图片的内容是什么?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://cdn.acedata.cloud/qzx2z1.png"
          }
        }
      ]
    }
  ],
  "stream": false
}

結果の例:

{
    "id": "chatcmpl-20251206001815715692730UVZe38kB",
    "model": "gemini-3.1-pro-preview",
    "object": "chat.completion",
    "created": 1764951548,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "这是一张年轻女性的户外半身人像照片。\n\n以下是图片的主要内容描述:\n\n*   **人物外貌**:照片中的女孩留着一头乌黑柔顺的长直发,五官清秀,皮肤白皙。她面带温柔的微笑,目光注视着镜头。\n*   **穿着打扮**:她穿着一件米白色或浅杏色的泡泡袖上衣,外面搭配着黑色的衣物(看起来像是背带裙或马甲)。\n*   **光影氛围**:阳光从左侧后方照射过来,洒在她的头发上,形成了一圈温暖的金黄色光晕,营造出一种清新、唯美的氛围。\n*   **背景**:背景被虚化处理,可以看出是在户外,身后是一条空旷的路面(柏油路)以及路边的绿色树木。\n\n整体来看,这张照片给人一种甜美、阳光和邻家女孩的感觉。"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 1092,
        "completion_tokens": 1271,
        "total_tokens": 2363,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "text_tokens": 4,
            "audio_tokens": 0,
            "image_tokens": 0
        },
        "completion_tokens_details": {
            "text_tokens": 0,
            "audio_tokens": 0,
            "reasoning_tokens": 1072
        },
        "input_tokens": 0,
        "output_tokens": 0,
        "input_tokens_details": null,
        "claude_cache_creation_5_m_tokens": 0,
        "claude_cache_creation_1_h_tokens": 0
    }
}

もちろん、動画のリンクを渡すこともできます。具体的な入力は以下のとおりです:

{
  "model": "gemini-3.1-pro-preview",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "视频的内容是什么?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://cdn.acedata.cloud/58yioe.mp4"
          }
        }
      ]
    }
  ],
  "stream": false
}

結果の例:

{
    "id": "chatcmpl-20251206002711949677736JC9yL8AE",
    "model": "gemini-3.1-pro-preview",
    "object": "chat.completion",
    "created": 1764952060,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "这段视频的内容充满趣味,主要展示了一只**橘猫**在黄昏时分的乡间公路上自信小跑的情景。\n\n具体细节如下:\n\n1.  **画面内容**:\n    *   主角是一只橘色的虎斑猫。\n    *   背景是夕阳西下(或清晨)的时刻,光线金黄柔和。路边有木质栅栏和旷野,远处还有一个行人的剪影。\n    *   镜头采用了低角度拍摄,时而拍摄猫咪迎面跑来,时而拍摄它离去的背影,还有猫咪面部和花纹的特写。\n\n2.  **声音特点(关键点)**:\n    *   视频的配音非常有特色。虽然画面是轻盈的猫咪在跑,但配上的声音却是**沉重且有节奏的马蹄声**(或者是类似木屐/高跟鞋敲击路面的声音)。\n    *   这种声音与画面的反差制造了一种幽默感,仿佛这只猫咪把自己当成了一匹正在驰骋的骏马。\n\n总的来说,这是一个利用音画反差来制造萌点和笑点的宠物视频。"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 915,
        "completion_tokens": 1423,
        "total_tokens": 2338,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "text_tokens": 5,
            "audio_tokens": 0,
            "image_tokens": 0
        },
        "completion_tokens_details": {
            "text_tokens": 0,
            "audio_tokens": 0,
            "reasoning_tokens": 1162
        },
        "input_tokens": 0,
        "output_tokens": 0,
        "input_tokens_details": null,
        "claude_cache_creation_5_m_tokens": 0,
        "claude_cache_creation_1_h_tokens": 0
    }
}

上記から、Gemini 3.0 モデルがマルチモーダルの理解に対応していることがわかります。

Gemini-3.1 マルチモーダルモデル

gemini-3.1-pro-preview は現在の Gemini 3.1 Pro の公式モデル ID であり、テキスト、画像、動画などのマルチモーダル入力に対応し、複雑な推論、コーディング、理解タスクに適しています。

リクエスト例:

{
  "model": "gemini-3.1-pro-preview",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "图片的内容是什么?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://cdn.acedata.cloud/qzx2z1.png"
          }
        }
      ]
    }
  ],
  "stream": false
}

Gemini 3.1 Pro は動画の理解にも対応しています:

{
  "model": "gemini-3.1-pro-preview",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "视频的内容是什么?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://cdn.acedata.cloud/58yioe.mp4"
          }
        }
      ]
    }
  ],
  "stream": false
}

レスポンス形式は Gemini 3.0 Pro と同じです。詳細は上記の Gemini-3.0 マルチモーダルモデルのセクションを参照してください。

エラー処理

API の呼び出し時にエラーが発生した場合、API は対応するエラーコードと情報を返します。例えば:

  • 400 token_mismatched:不正なリクエストです。パラメータが不足しているか、無効である可能性があります。
  • 400 api_not_implemented:不正なリクエストです。パラメータが不足しているか、無効である可能性があります。
  • 401 invalid_token:認証されていません。認証トークンが無効であるか、不足しています。
  • 429 too_many_requests:リクエストが多すぎます。レート制限を超過しました。
  • 500 api_error:内部サーバーエラーです。サーバーで問題が発生しました。

エラーレスポンスの例

{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}

結論

このドキュメントを通じて、Gemini Chat Completion API を使用して公式 Gemini の対話機能を簡単に実現する方法を理解できました。このドキュメントが、API との連携と利用に役立つことを願っています。ご不明な点がございましたら、いつでも技術サポートチームにお問い合わせください。