Gemini が考えています

Gemini 3 および 2.5 シリーズのモデルは、推論と多段階計画の能力を大幅に向上させる内部の「思考プロセス」を使用します。これにより、コーディング、高度な数学、データ分析などの複雑なタスクに非常に効果的です。

このガイドでは、Gemini API を使用して Gemini の思考機能を操作する方法について説明します。

思考を伴うコンテンツを生成する

思考モデルでリクエストを開始する手順は、他のコンテンツ生成リクエストと同様です。主な違いは、model フィールドで思考サポート付きモデルのいずれかを指定することです。

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.steps[-1].content[0].text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3-flash-preview",
    input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.steps.at(-1).content[0].text);

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3-flash-preview",
    "input": "Explain the concept of Occam'\''s Razor and provide a simple example."
  }'

思考の要約

思考の要約は、モデルの内部推論プロセスに関する分析情報を提供します。デフォルトでは、最終出力のみが返されます。thinking_summaries を使用して思考の要約を有効にできます。

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is the sum of the first 50 prime numbers?",
    generation_config={
        "thinking_summaries": "auto"
    }
)

for step in interaction.steps:
    if step.type == "thought":
        print("Thought summary:")
        for content_block in step.summary:
            if content_block.type == "text":
                print(content_block.text)
        print()
    elif step.type == "model_output":
        for content_block in step.content:
            if content_block.type == "text":
                print("Answer:")
                print(content_block.text)
                print()

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3-flash-preview",
    input: "What is the sum of the first 50 prime numbers?",
    generationConfig: {
        thinkingSummaries: "auto"
    }
});

for (const step of interaction.steps) {
    if (step.type === "thought") {
        console.log("Thought summary:");
        for (const contentBlock of step.summary) {
            if (contentBlock.type === "text") console.log(contentBlock.text);
        }
    } else if (step.type === "model_output") {
        for (const contentBlock of step.content) {
            if (contentBlock.type === "text") {
                console.log("Answer:");
                console.log(contentBlock.text);
            }
        }
    }
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3-flash-preview",
    "input": "What is the sum of the first 50 prime numbers?",
    "generationConfig": {
      "thinkingSummaries": "auto"
    }
  }'

思考を伴うストリーミング

ストリーミングを使用して、生成中に思考の増分要約を受け取ります。これにより、生成された増分要約がローリングで返されます。

Python

from google import genai

client = genai.Client()

prompt = """
Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.
Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?
"""

thoughts = ""
answer = ""

stream = client.interactions.create(
    model="gemini-3-flash-preview",
    input=prompt,
    generation_config={
        "thinking_summaries": "auto"
    },
    stream=True
)

thoughts = ""
answer = ""

for event in stream:
    if event.event_type == "step.delta":
        if event.delta.type == "thought":
            if not thoughts:
                print("Thinking...")
            summary_text = getattr(event.delta, 'text', '')
            print(f"[Thought] {summary_text}", end="")
            thoughts += summary_text
        elif event.delta.type == "text" and event.delta.text:
            if not answer:
                print("\nAnswer:")
            print(event.delta.text, end="")
            answer += event.delta.text

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const prompt = `Alice, Bob, and Carol each live in a different house on the same
street: red, green, and blue. Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?`;

let thoughts = "";
let answer = "";

const stream = await client.interactions.create({
    model: "gemini-3-flash-preview",
    input: prompt,
    generationConfig: {
        thinkingSummaries: "auto"
    },
    stream: true
});

for await (const event of stream) {
    if (event.type === "step.delta") {
        if (event.delta.type === "thought") {
            if (!thoughts) console.log("Thinking...");
            process.stdout.write(`[Thought] ${event.delta.text || ""}`);
            thoughts += event.delta.text || "";
        } else if (event.delta.type === "text" && event.delta.text) {
            if (!answer) console.log("\nAnswer:");
            process.stdout.write(event.delta.text);
            answer += event.delta.text;
        }
    }
}

思考を制御する

Gemini モデルはデフォルトで動的思考を行い、リクエストの複雑さに基づいて推論の労力を自動的に調整します。ただし、構成パラメータを使用してこの動作を制御できます。

思考レベル(Gemini 3)

Gemini 3 モデル以降で推奨される thinking_level パラメータを使用すると、推論の動作を制御できます。

思考レベル Gemini 3.1 Pro Gemini 3 Pro(非推奨 Gemini 3 Flash 説明
minimal サポート対象外 サポート対象外 サポート対象 ほとんどのクエリで「思考なし」の設定と一致します。複雑なコーディング タスクに対して、モデルの思考が最小限になる可能性があります。チャットや高スループット アプリケーションのレイテンシを最小限に抑えます。なお、minimal は思考がオフになることを保証するものではありません。
low サポート対象 サポート対象 サポート対象 レイテンシと費用を最小限に抑えます。指示の実行、チャット、高スループット アプリケーションに最適です。
medium サポート対象 サポート対象外 サポート対象 ほとんどのタスクでバランスの取れた思考。
high サポートされている(デフォルト、動的) サポートされている(デフォルト、動的) サポートされている(デフォルト、動的) 推論の深さを最大化します。最初の(思考モード以外の)出力トークンに到達するまでに時間がかかることがありますが、出力はより慎重に推論されます。

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Provide a list of 3 famous physicists and their key contributions",
    generation_config={
        "thinking_level": "low"
    }
)
print(interaction.steps[-1].content[0].text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: "gemini-3-flash-preview",
    input: "Provide a list of 3 famous physicists and their key contributions",
    generationConfig: {
        thinkingLevel: "low"
    }
});
console.log(interaction.steps.at(-1).content[0].text);

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-3-flash-preview",
    "input": "Provide a list of 3 famous physicists and their key contributions",
    "generation_config": {
      "thinking_level": "low"
    }
  }'

Gemini 3 Pro では思考を無効にできません。Gemini 3 Flash も思考の完全オフをサポートしていませんが、minimal 設定は、モデルが思考しない可能性が高いことを意味します(ただし、思考する可能性はあります)。

思考シグネチャ

Gemini API はステートレスであるため、モデルはすべての API リクエストを個別に処理し、マルチターンのやり取りで以前のターンの思考コンテキストにアクセスできません。

マルチターン インタラクションで思考コンテキストを維持できるようにするために、Gemini は思考シグネチャを返します。これは、モデルの内部思考プロセスを暗号化したものです。

  • Gemini 2.5 モデルは、思考が有効になっていて、リクエストに関数呼び出し(具体的には関数宣言)が含まれている場合に、思考シグネチャを返します。
  • Gemini 3 モデルは、すべてのタイプのパーツの思考シグネチャを返すことがあります。すべてのシグネチャを常に受け取ったとおりに渡すことをおすすめしますが、関数呼び出しシグネチャの場合は必須です。詳しくは、思考署名をご覧ください。
  • シグネチャは、レスポンスの他の部分(関数呼び出しやテキストなど)からモデルによって返されます。その後のやり取りで、すべての部分を含むレスポンス全体を返します
  • シグネチャを含むパートを連結しないでください。
  • シグネチャ付きのパートとシグネチャなしのパートを結合しないでください。

料金

思考が有効になっている場合、レスポンスの料金は出力トークンと思考トークンの合計です。生成された思考トークンの合計数は、total_thought_tokens フィールドから取得できます。

Python

# ...
print("Thoughts tokens:", interaction.usage.total_thought_tokens)
print("Output tokens:", interaction.usage.total_output_tokens)

JavaScript

// ...
console.log(`Thoughts tokens: ${interaction.usage.totalThoughtTokens}`);
console.log(`Output tokens: ${interaction.usage.totalOutputTokens}`);

思考モデルは、最終的なレスポンスの質を高めるために完全な思考を生成し、思考プロセスに関する分析情報を提供するために要約を出力します。料金は、API から出力されるのが要約のみであっても、モデルが生成する必要がある思考トークンの総数に基づいて計算されます。

トークンの詳細については、トークン数のカウントをご覧ください。

ベスト プラクティス

このセクションでは、思考モデルを効率的に使用するためのガイダンスについて説明します。

デバッグとステアリング

  • 推論を確認する: 思考モデルから期待どおりのレスポンスが得られない場合は、Gemini の思考の要約を慎重に分析すると役立ちます。タスクをどのように分解して結論に達したかを確認し、その情報を使用して正しい結果が得られるように修正できます。

  • 推論でガイダンスを提供する: 特に長い出力を希望する場合は、プロンプトでガイダンスを指定して、モデルが使用する思考の量を制限することをおすすめします。これにより、レスポンス用にトークン出力をより多く予約できます。

タスクの複雑さ

  • 簡単なタスク(思考モードをオフにできる): 複雑な推論を必要としない簡単なリクエストの場合、思考モードは必要ありません。例:
    • 「DeepMind はどこで設立されましたか?」
    • 「このメールは会議を依頼しているのか、それとも情報を提供しているだけなのか?」
  • 中程度のタスク(デフォルト/ある程度の思考): 多くの一般的なリクエストは、段階的な処理や深い理解によってメリットが得られます。例:
    • 光合成と成長を例える。
    • 電気自動車とハイブリッド車を比較対照します。
  • 難しいタスク(最大思考能力): 非常に複雑な課題には、高い思考予算を設定することをおすすめします。このようなタスクでは、モデルが完全な推論と計画の能力を発揮する必要があります。例:
    • AIME 2025 の問題 1 を解きます。すべての整数底 b > 9 の合計を求めます。
    • ユーザー認証を含む、リアルタイムの株式市場データを可視化するウェブ アプリケーションの Python コードを記述します。できるだけ効率的にします。

サポートされているモデル

モデル デフォルトの思考 サポートされているレベル
gemini-3.1-pro-preview オン(高) 低、中、高
gemini-3-flash-preview オン(高) 最小、低、中、高
gemini-3-pro-preview オン(高) 低、高
gemini-2.5-pro オン 予算: 128 ~ 32768
gemini-2.5-flash オン 予算: 0 ~ 24576
gemini-2.5-flash-lite オフ 予算: 0 ~ 24576

思考モデルは、Gemini のすべてのツールと機能で動作します。これにより、モデルは外部システムとやり取りしたり、コードを実行したり、リアルタイム情報にアクセスして、その結果を推論に組み込むことができます。

次のステップ