Gemini 3 開發人員指南

Gemini 3 是我們迄今最強大的模型系列,以最先進的推理技術為基礎建構而成。這項模型擅長代理式工作流程、自主編碼和複雜的多模態工作,能將任何想法化為現實。本指南將介紹 Gemini 3 模型系列的主要功能,以及如何充分運用這些功能。

歡迎瀏覽 Gemini 3 系列應用程式,瞭解這個模型如何處理進階推理、自主程式設計和複雜的多模態工作。

只要編寫幾行程式碼,即可開始使用:

Python

from google import genai

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents="Find the race condition in this multi-threaded C++ snippet: [code here]",
)

print(response.text)

JavaScript

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

const ai = new GoogleGenAI({});

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: "Find the race condition in this multi-threaded C++ snippet: [code here]",
  });

  console.log(response.text);
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "Find the race condition in this multi-threaded C++ snippet: [code here]"}]
    }]
  }'

認識 Gemini 3 系列

Gemini 3 Pro 是新系列的第一個模型,最適合需要廣泛世界知識和跨模態進階推理的複雜任務。

Gemini 3 Flash 是我們最新的 3 系列模型,具備 Pro 級智慧,但速度和價格與 Flash 相同。

Nano Banana Pro (又稱 Gemini 3 Pro Image) 是我們迄今品質最優的圖像生成模型。

所有 Gemini 3 模型目前皆為預先發布版。

模型 ID 背景期間 (進入 / 離開) 知識截點 定價 (輸入 / 輸出)*
gemini-3-pro-preview 100 萬次 / 6.4 萬次 2025 年 1 月 $2 美元 / $12 美元 (少於 20 萬個權杖)
$4 美元 / $18 美元 (超過 20 萬個權杖)
gemini-3-flash-preview 100 萬次 / 6.4 萬次 2025 年 1 月 $0.50 / $3
gemini-3-pro-image-preview 65,000 / 32,000 2025 年 1 月 $2 美元 (文字輸入) / $0.134 美元 (圖片輸出)**

* 除非另有註明,否則價格以每 100 萬個權杖為單位。 ** 圖片價格會因解析度而異。詳情請參閱定價頁面

如需詳細的限制、定價和其他資訊,請參閱模型頁面

Gemini 3 的新 API 功能

Gemini 3 推出全新參數,讓開發人員進一步掌控延遲時間、成本和多模態準確度。

思考程度

Gemini 3 系列模型預設會使用動態思考功能,根據提示進行推理。您可以使用 thinking_level 參數,控制模型產生回覆前內部推理過程的最大深度。Gemini 3 會將這些層級視為相對思考配額,而非嚴格的權杖保證。

如未指定 thinking_level,Gemini 3 會預設為 high。如果不需要複雜的推理,您可以將模型的思考層級限制為 low,以加快回應速度並縮短延遲時間。

Gemini 3 Pro 和 Flash 的思考程度:

Gemini 3 Pro 和 Flash 皆支援下列思考層級:

  • low:盡量減少延遲時間和費用。最適合簡單的指令遵循、聊天或高總處理量應用程式
  • high (預設,動態):盡可能深入推理。模型可能需要較長時間才能產生第一個權杖,但輸出內容會經過更仔細的推論。

Gemini 3 Flash 的思考層次

除了上述層級,Gemini 3 Flash 也支援下列 Gemini 3 Pro 目前不支援的思考層級:

  • minimal:適用於大多數查詢的「不思考」設定。模型可能會以極簡思維處理複雜的程式碼工作。盡量減少聊天或高處理量應用程式的延遲。

  • medium:平衡思考,適合大多數任務。

Python

from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents="How does AI work?",
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(thinking_level="low")
    ),
)

print(response.text)

JavaScript

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

const ai = new GoogleGenAI({});

const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: "How does AI work?",
    config: {
      thinkingConfig: {
        thinkingLevel: "low",
      }
    },
  });

console.log(response.text);

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "How does AI work?"}]
    }],
    "generationConfig": {
      "thinkingConfig": {
        "thinkingLevel": "low"
      }
    }
  }'

媒體解析度

Gemini 3 透過 media_resolution 參數,精細控管多模態視覺處理作業。解析度越高,模型就越能辨識細小文字或細節,但也會增加權杖用量和延遲時間。media_resolution 參數會決定每個輸入圖片或影片影格可分配到的詞元數量上限。

現在可以為個別媒體部分或全域設定解析度 (透過 generation_config,全域不適用於超高解析度)。解析度可設為 media_resolution_lowmedia_resolution_mediummedia_resolution_highmedia_resolution_ultra_high。如未指定,模型會根據媒體類型使用最佳預設值。

建議設定

媒體類型 建議設定 最多權杖 使用指南
圖片 media_resolution_high 1120 建議用於大多數圖片分析工作,確保最高品質。
PDF media_resolution_medium 560 最適合用於瞭解文件內容,品質通常會在 medium 達到飽和。增加至 high 很少能改善標準文件的 OCR 結果。
影片 (一般) media_resolution_low (或 media_resolution_medium) 70 (每格) 注意:如果是影片,系統會將 lowmedium 設定視為相同 (70 個權杖),以盡量運用情境資訊。這足以應付大多數的動作辨識和描述工作。
影片 (文字內容較多) media_resolution_high 280 (每格) 只有在用途涉及讀取密集文字 (OCR) 或影片影格中的細節時,才需要此功能。

Python

from google import genai
from google.genai import types
import base64

# The media_resolution parameter is currently only available in the v1alpha API version.
client = genai.Client(http_options={'api_version': 'v1alpha'})

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents=[
        types.Content(
            parts=[
                types.Part(text="What is in this image?"),
                types.Part(
                    inline_data=types.Blob(
                        mime_type="image/jpeg",
                        data=base64.b64decode("..."),
                    ),
                    media_resolution={"level": "media_resolution_high"}
                )
            ]
        )
    ]
)

print(response.text)

JavaScript

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

// The media_resolution parameter is currently only available in the v1alpha API version.
const ai = new GoogleGenAI({ apiVersion: "v1alpha" });

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: [
      {
        parts: [
          { text: "What is in this image?" },
          {
            inlineData: {
              mimeType: "image/jpeg",
              data: "...",
            },
            mediaResolution: {
              level: "media_resolution_high"
            }
          }
        ]
      }
    ]
  });

  console.log(response.text);
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1alpha/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [
        { "text": "What is in this image?" },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "..."
          },
          "mediaResolution": {
            "level": "media_resolution_high"
          }
        }
      ]
    }]
  }'

溫度

對於 Gemini 3,我們強烈建議將溫度參數維持預設值 1.0

先前的模型通常會調整溫度,以控制創意與決定性,但 Gemini 3 的推理能力已針對預設設定進行最佳化。變更溫度 (設為低於 1.0) 可能會導致意料之外的行為,例如迴圈或效能降低,尤其是在複雜的數學或推理工作。

思想簽名

Gemini 3 會使用思維簽章,在 API 呼叫之間維持推理情境。這些簽章是模型內部思考過程的加密表示法。為確保模型維持推理能力,您必須在要求中將這些簽章傳回模型,且簽章內容必須與收到的完全一致:

  • 函式呼叫 (嚴格):API 會對「目前回合」強制執行嚴格驗證。如果缺少簽章,系統會顯示 400 錯誤。

  • 文字/對話:系統不會嚴格執行驗證,但如果省略簽章,模型的推理能力和回覆品質就會下降。

  • 圖像生成/編輯 (嚴格):API 會對所有模型部分 (包括 thoughtSignature) 進行嚴格驗證。如果缺少簽章,系統會顯示 400 錯誤。

函式呼叫 (嚴格驗證)

Gemini 生成 functionCall 時,會依據 thoughtSignature 在下一個回合中正確處理工具的輸出內容。「目前回合」包含自上次標準「使用者」text訊息以來,發生的所有「模型」functionCall和「使用者」functionResponse步驟。

  • 單一函式呼叫:functionCall 部分包含簽章。你必須歸還。
  • 平行函式呼叫:清單中只有第一個 functionCall 部分會包含簽章。請務必依原樣退回零件。
  • 多步驟 (循序):如果模型呼叫工具、收到結果,並呼叫另一個工具 (在同一回合內),兩個函式呼叫都會有簽章。您必須退回記錄中所有累積的簽章。

文字和串流

如果是標準即時通訊或文字生成,系統不保證會顯示簽名。

  • 非串流:回應的最終內容部分可能包含 thoughtSignature,但並非一律如此。如果退回其中一個,請務必寄回,以維持最佳成效。
  • 串流:如果系統產生簽章,簽章可能會出現在含有空白文字部分的最後一個區塊。確認串流剖析器會檢查簽章,即使文字欄位空白也一樣。

生成及編輯圖像

對於 gemini-3-pro-image-preview,思維簽章是進行對話式編輯的關鍵。要求模型修改圖片時,模型會根據前一輪的 thoughtSignature 瞭解原始圖片的構圖和邏輯。

  • 編輯:系統保證會在回覆內容的第一部分 (textinlineData) 後方加上簽名,以及在後續每個 inlineData 部分加上簽名。您必須傳回所有這些簽章,以免發生錯誤。

程式碼範例

多步驟函式呼叫 (循序)

使用者在同一輪對話中提出需要兩個步驟的問題 (查看航班 -> 預訂計程車)。

步驟 1:模型呼叫 Flight Tool。
模型會傳回簽章 <Sig_A>

// Model Response (Turn 1, Step 1)
  {
    "role": "model",
    "parts": [
      {
        "functionCall": { "name": "check_flight", "args": {...} },
        "thoughtSignature": "<Sig_A>" // SAVE THIS
      }
    ]
  }

步驟 2:使用者傳送航班結果
我們必須傳回 <Sig_A>,才能維持模型的思路。

// User Request (Turn 1, Step 2)
[
  { "role": "user", "parts": [{ "text": "Check flight AA100..." }] },
  { 
    "role": "model", 
    "parts": [
      { 
        "functionCall": { "name": "check_flight", "args": {...} }, 
        "thoughtSignature": "<Sig_A>" // REQUIRED
      } 
    ]
  },
  { "role": "user", "parts": [{ "functionResponse": { "name": "check_flight", "response": {...} } }] }
]

步驟 3:模型呼叫 Taxi Tool
模型透過 <Sig_A> 記住航班延誤,現在決定預約計程車。系統會產生簽章 <Sig_B>

// Model Response (Turn 1, Step 3)
{
  "role": "model",
  "parts": [
    {
      "functionCall": { "name": "book_taxi", "args": {...} },
      "thoughtSignature": "<Sig_B>" // SAVE THIS
    }
  ]
}

步驟 4:使用者傳送 Taxi Result
如要完成回合,您必須傳回整個鏈結:<Sig_A><Sig_B>

// User Request (Turn 1, Step 4)
[
  // ... previous history ...
  { 
    "role": "model", 
    "parts": [
       { "functionCall": { "name": "check_flight", ... }, "thoughtSignature": "<Sig_A>" } 
    ]
  },
  { "role": "user", "parts": [{ "functionResponse": {...} }] },
  { 
    "role": "model", 
    "parts": [
       { "functionCall": { "name": "book_taxi", ... }, "thoughtSignature": "<Sig_B>" } 
    ]
  },
  { "role": "user", "parts": [{ "functionResponse": {...} }] }
]

平行函式呼叫

使用者詢問:「Check the weather in Paris and London.」(查看巴黎和倫敦的天氣)。模型會在一個回覆中傳回兩個函式呼叫。

// User Request (Sending Parallel Results)
[
  {
    "role": "user",
    "parts": [
      { "text": "Check the weather in Paris and London." }
    ]
  },
  {
    "role": "model",
    "parts": [
      // 1. First Function Call has the signature
      {
        "functionCall": { "name": "check_weather", "args": { "city": "Paris" } },
        "thoughtSignature": "<Signature_A>" 
      },
      // 2. Subsequent parallel calls DO NOT have signatures
      {
        "functionCall": { "name": "check_weather", "args": { "city": "London" } }
      } 
    ]
  },
  {
    "role": "user",
    "parts": [
      // 3. Function Responses are grouped together in the next block
      {
        "functionResponse": { "name": "check_weather", "response": { "temp": "15C" } }
      },
      {
        "functionResponse": { "name": "check_weather", "response": { "temp": "12C" } }
      }
    ]
  }
]

文字/情境內推理 (無驗證)

使用者提出的問題需要根據情境推理,但不得使用外部工具。雖然系統不會嚴格驗證簽章,但加入簽章有助於模型保留後續問題的推理鏈。

// User Request (Follow-up question)
[
  { 
    "role": "user", 
    "parts": [{ "text": "What are the risks of this investment?" }] 
  },
  { 
    "role": "model", 
    "parts": [
      {
        "text": "I need to calculate the risk step-by-step. First, I'll look at volatility...",
        "thoughtSignature": "<Signature_C>" // Recommended to include
      }
    ]
  },
  { 
    "role": "user", 
    "parts": [{ "text": "Summarize that in one sentence." }] 
  }
]

生成及編輯圖像

生成圖像時,系統會嚴格驗證簽章。這些浮水印會顯示在第一部分 (文字或圖片) 和所有後續圖片部分。所有卡片都必須在下一回合歸還。

// Model Response (Turn 1)
{
  "role": "model",
  "parts": [
    // 1. First part ALWAYS has a signature (even if text)
    {
      "text": "I will generate a cyberpunk city...",
      "thoughtSignature": "<Signature_D>" 
    },
    // 2. ALL InlineData (Image) parts ALWAYS have signatures
    {
      "inlineData": { ... }, 
      "thoughtSignature": "<Signature_E>" 
    },
  ]
}

// User Request (Turn 2 - Requesting an Edit)
{
  "contents": [
    // History must include ALL signatures received
    {
      "role": "user",
      "parts": [{ "text": "Generate a cyberpunk city" }]
    },
    {
      "role": "model",
      "parts": [
         { "text": "...", "thoughtSignature": "<Signature_D>" },
         { "inlineData": "...", "thoughtSignature": "<Signature_E>" },
      ]
    },
    // New User Prompt
    {
      "role": "user",
      "parts": [{ "text": "Make it daytime." }]
    }
  ]
}

從其他機型遷移

如要從其他模型 (例如 Gemini 1.0 Pro) 轉移對話記錄,Gemini 2.5) 或插入非由 Gemini 3 生成的自訂函式呼叫,您將無法取得有效簽章。

如要在這些特定情境中略過嚴格驗證,請在欄位中填入這個特定虛擬字串:"thoughtSignature": "context_engineering_is_the_way_to_go"

使用工具產生結構化輸出內容

Gemini 3 模型可讓您結合結構化輸出與內建工具,包括以 Google 搜尋建立基準網址脈絡程式碼執行

Python

from google import genai
from google.genai import types
from pydantic import BaseModel, Field
from typing import List

class MatchResult(BaseModel):
    winner: str = Field(description="The name of the winner.")
    final_match_score: str = Field(description="The final match score.")
    scorers: List[str] = Field(description="The name of the scorer.")

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents="Search for all details for the latest Euro.",
    config={
        "tools": [
            {"google_search": {}},
            {"url_context": {}}
        ],
        "response_mime_type": "application/json",
        "response_json_schema": MatchResult.model_json_schema(),
    },  
)

result = MatchResult.model_validate_json(response.text)
print(result)

JavaScript

import { GoogleGenAI } from "@google/genai";
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";

const ai = new GoogleGenAI({});

const matchSchema = z.object({
  winner: z.string().describe("The name of the winner."),
  final_match_score: z.string().describe("The final score."),
  scorers: z.array(z.string()).describe("The name of the scorer.")
});

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: "Search for all details for the latest Euro.",
    config: {
      tools: [
        { googleSearch: {} },
        { urlContext: {} }
      ],
      responseMimeType: "application/json",
      responseJsonSchema: zodToJsonSchema(matchSchema),
    },
  });

  const match = matchSchema.parse(JSON.parse(response.text));
  console.log(match);
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "Search for all details for the latest Euro."}]
    }],
    "tools": [
      {"googleSearch": {}},
      {"urlContext": {}}
    ],
    "generationConfig": {
        "responseMimeType": "application/json",
        "responseJsonSchema": {
            "type": "object",
            "properties": {
                "winner": {"type": "string", "description": "The name of the winner."},
                "final_match_score": {"type": "string", "description": "The final score."},
                "scorers": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "The name of the scorer."
                }
            },
            "required": ["winner", "final_match_score", "scorers"]
        }
    }
  }'

圖像生成

Gemini 3 Pro Image 可讓你根據文字提示生成及編輯圖片。Gemini 會運用推理能力「思考」提示,並在生成高擬真度圖片前,先擷取天氣預報或股票圖表等即時資料,然後使用 Google 搜尋做為基礎。

全新和改良功能:

  • 4K 和文字算繪:生成清晰易讀的文字和圖表,解析度最高可達 2K 和 4K。
  • 以事實為依據生成:使用 google_search 工具驗證事實,並根據真實世界資訊生成圖像。
  • 對話式編輯:只要提出變更要求 (例如「把背景換成海灘」),即可多輪編輯圖像。「將背景設為日落」)。這個工作流程會使用思維簽章,保留回合之間的視覺情境。

如要進一步瞭解長寬比、編輯工作流程和設定選項,請參閱圖片生成指南

Python

from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents="Generate an infographic of the current weather in Tokyo.",
    config=types.GenerateContentConfig(
        tools=[{"google_search": {}}],
        image_config=types.ImageConfig(
            aspect_ratio="16:9",
            image_size="4K"
        )
    )
)

image_parts = [part for part in response.parts if part.inline_data]

if image_parts:
    image = image_parts[0].as_image()
    image.save('weather_tokyo.png')
    image.show()

JavaScript

import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";

const ai = new GoogleGenAI({});

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-image-preview",
    contents: "Generate a visualization of the current weather in Tokyo.",
    config: {
      tools: [{ googleSearch: {} }],
      imageConfig: {
        aspectRatio: "16:9",
        imageSize: "4K"
      }
    }
  });

  for (const part of response.candidates[0].content.parts) {
    if (part.inlineData) {
      const imageData = part.inlineData.data;
      const buffer = Buffer.from(imageData, "base64");
      fs.writeFileSync("weather_tokyo.png", buffer);
    }
  }
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "Generate a visualization of the current weather in Tokyo."}]
    }],
    "tools": [{"googleSearch": {}}],
    "generationConfig": {
        "imageConfig": {
          "aspectRatio": "16:9",
          "imageSize": "4K"
      }
    }
  }'

範例回應

東京天氣

多模態函式回應

多模態函式呼叫 可讓使用者取得含有多模態物件的函式回應, 進而更充分運用模型的函式呼叫功能。標準函式呼叫僅支援以文字為基礎的函式回應:

Python

from google import genai
from google.genai import types

import requests

client = genai.Client()

# This is a manual, two turn multimodal function calling workflow:

# 1. Define the function tool
get_image_declaration = types.FunctionDeclaration(
  name="get_image",
  description="Retrieves the image file reference for a specific order item.",
  parameters={
      "type": "object",
      "properties": {
          "item_name": {
              "type": "string",
              "description": "The name or description of the item ordered (e.g., 'instrument')."
          }
      },
      "required": ["item_name"],
  },
)
tool_config = types.Tool(function_declarations=[get_image_declaration])

# 2. Send a message that triggers the tool
prompt = "Show me the instrument I ordered last month."
response_1 = client.models.generate_content(
  model="gemini-3-flash-preview",
  contents=[prompt],
  config=types.GenerateContentConfig(
      tools=[tool_config],
  )
)

# 3. Handle the function call
function_call = response_1.function_calls[0]
requested_item = function_call.args["item_name"]
print(f"Model wants to call: {function_call.name}")

# Execute your tool (e.g., call an API)
# (This is a mock response for the example)
print(f"Calling external tool for: {requested_item}")

function_response_data = {
  "image_ref": {"$ref": "instrument.jpg"},
}
image_path = "https://goo.gle/instrument-img"
image_bytes = requests.get(image_path).content
function_response_multimodal_data = types.FunctionResponsePart(
  inline_data=types.FunctionResponseBlob(
    mime_type="image/jpeg",
    display_name="instrument.jpg",
    data=image_bytes,
  )
)

# 4. Send the tool's result back
# Append this turn's messages to history for a final response.
history = [
  types.Content(role="user", parts=[types.Part(text=prompt)]),
  response_1.candidates[0].content,
  types.Content(
    role="tool",
    parts=[
        types.Part.from_function_response(
          name=function_call.name,
          response=function_response_data,
          parts=[function_response_multimodal_data]
        )
    ],
  )
]

response_2 = client.models.generate_content(
  model="gemini-3-flash-preview",
  contents=history,
  config=types.GenerateContentConfig(
      tools=[tool_config],
      thinking_config=types.ThinkingConfig(include_thoughts=True)
  ),
)

print(f"\nFinal model response: {response_2.text}")

JavaScript

import { GoogleGenAI, Type } from '@google/genai';

const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

// This is a manual, two turn multimodal function calling workflow:
// 1. Define the function tool
const getImageDeclaration = {
  name: 'get_image',
  description: 'Retrieves the image file reference for a specific order item.',
  parameters: {
    type: Type.OBJECT,
    properties: {
      item_name: {
        type: Type.STRING,
        description: "The name or description of the item ordered (e.g., 'instrument').",
      },
    },
    required: ['item_name'],
  },
};

const toolConfig = {
  functionDeclarations: [getImageDeclaration],
};

// 2. Send a message that triggers the tool
const prompt = 'Show me the instrument I ordered last month.';
const response1 = await client.models.generateContent({
  model: 'gemini-3-flash-preview',
  contents: prompt,
  config: {
    tools: [toolConfig],
  },
});

// 3. Handle the function call
const functionCall = response1.functionCalls[0];
const requestedItem = functionCall.args.item_name;
console.log(`Model wants to call: ${functionCall.name}`);

// Execute your tool (e.g., call an API)
// (This is a mock response for the example)
console.log(`Calling external tool for: ${requestedItem}`);

const functionResponseData = {
  image_ref: { $ref: 'instrument.jpg' },
};

const imageUrl = "https://goo.gle/instrument-img";
const response = await fetch(imageUrl);
const imageArrayBuffer = await response.arrayBuffer();
const base64ImageData = Buffer.from(imageArrayBuffer).toString('base64');

const functionResponseMultimodalData = {
  inlineData: {
    mimeType: 'image/jpeg',
    displayName: 'instrument.jpg',
    data: base64ImageData,
  },
};

// 4. Send the tool's result back
// Append this turn's messages to history for a final response.
const history = [
  { role: 'user', parts: [{ text: prompt }] },
  response1.candidates[0].content,
  {
    role: 'tool',
    parts: [
      {
        functionResponse: {
          name: functionCall.name,
          response: functionResponseData,
          parts: [functionResponseMultimodalData],
        },
      },
    ],
  },
];

const response2 = await client.models.generateContent({
  model: 'gemini-3-flash-preview',
  contents: history,
  config: {
    tools: [toolConfig],
    thinkingConfig: { includeThoughts: true },
  },
});

console.log(`\nFinal model response: ${response2.text}`);

REST

IMG_URL="https://goo.gle/instrument-img"

MIME_TYPE=$(curl -sIL "$IMG_URL" | grep -i '^content-type:' | awk -F ': ' '{print $2}' | sed 's/\r$//' | head -n 1)
if [[ -z "$MIME_TYPE" || ! "$MIME_TYPE" == image/* ]]; then
  MIME_TYPE="image/jpeg"
fi

# Check for macOS
if [[ "$(uname)" == "Darwin" ]]; then
  IMAGE_B64=$(curl -sL "$IMG_URL" | base64 -b 0)
elif [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
  IMAGE_B64=$(curl -sL "$IMG_URL" | base64)
else
  IMAGE_B64=$(curl -sL "$IMG_URL" | base64 -w0)
fi

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [
      ...,
      {
        "role": "user",
        "parts": [
        {
            "functionResponse": {
              "name": "get_image",
              "response": {
                "image_ref": {
                  "$ref": "instrument.jpg"
                }
              },
              "parts": [
                {
                  "inlineData": {
                    "displayName": "instrument.jpg",
                    "mimeType":"'"$MIME_TYPE"'",
                    "data": "'"$IMAGE_B64"'"
                  }
                }
              ]
            }
          }
        ]
      }
    ]
  }'

從 Gemini 2.5 遷移

Gemini 3 是我們迄今最強大的模型系列,比 Gemini 2.5 更進一步。遷移時,請注意以下事項:

  • 思考型:如果你先前使用複雜的提示工程 (例如連鎖思考) 強迫 Gemini 2.5 推理,請試用 Gemini 3 和 thinking_level: "high",並簡化提示。
  • 溫度設定:如果現有程式碼明確設定溫度 (尤其是確定性輸出結果的低值),建議移除這個參數並使用 Gemini 3 的預設值 1.0,以免複雜工作發生潛在的迴圈問題或效能降低。
  • PDF 和文件理解:PDF 的預設 OCR 解析度已變更。如果您依賴特定行為來剖析密集文件,請測試新的 media_resolution_high 設定,確保準確度不受影響。
  • 符記用量:改用 Gemini 3 預設模型後,處理 PDF 檔案的符記用量可能會增加,但處理影片的符記用量會減少。如果預設解析度提高後,要求超出脈絡窗口,建議您明確降低媒體解析度。
  • 圖片分割:Gemini 3 Pro 或 Gemini 3 Flash 不支援圖片分割功能 (傳回物件的像素層級遮罩)。如果工作負載需要原生圖像分割功能,建議繼續使用 Gemini 2.5 Flash (關閉思考模式) 或 Gemini Robotics-ER 1.5
  • 工具支援:Gemini 3 模型目前不支援地圖基礎和電腦使用工具,因此不會遷移。此外,目前還無法將內建工具與函式呼叫功能搭配使用。

OpenAI 相容性

如果使用者採用 OpenAI 相容層,系統會自動將標準參數對應至 Gemini 的對等項目:

  • reasoning_effort (OAI) 對應至 thinking_level (Gemini)。請注意,reasoning_effort 在 Gemini 3 Flash 中會對應到 thinking_level「高」。

提示最佳做法

Gemini 3 是推理模型,因此提示方式有所不同。

  • 明確的指令:輸入提示時請簡潔扼要。Gemini 3 最適合直接且清楚的指令。如果使用冗長或過於複雜的提示工程技術,可能會導致過度分析。
  • 輸出內容詳細程度:Gemini 3 預設會提供較簡潔的答案,偏好直接且有效率地回答問題。如果您的用途需要更具對話感或「健談」的角色,您必須在提示中明確引導模型 (例如「請以健談的語氣回覆」)。「以親切健談的助理身分說明這件事」。
  • 脈絡管理:處理大型資料集 (例如整本書、程式碼集或長篇影片) 時,請將具體指令或問題放在提示結尾,也就是資料脈絡之後。在問題開頭使用「根據上述資訊...」等詞組,讓模型根據提供的資料進行推論。

如要進一步瞭解提示設計策略,請參閱提示工程指南

常見問題

  1. Gemini 3 的知識截止日期為何?Gemini 3 模型可存取的知識截止日期為 2025 年 1 月。如要取得最新資訊,請使用「搜尋基礎」工具。

  2. 脈絡窗口的限制為何?Gemini 3 模型支援 100 萬個詞元的輸入脈絡窗口,以及最多 6 萬 4 千個詞元的輸出。

  3. Gemini 3 是否提供免費方案?Gemini 3 Flash gemini-3-flash-preview 在 Gemini API 中提供免費方案。您可以在 Google AI Studio 中免費試用 Gemini 3 Pro 和 Flash,但目前 Gemini API 的 gemini-3-pro-preview 沒有免付費方案。

  4. 舊的 thinking_budget 程式碼是否仍可運作?可以,為了回溯相容性,系統仍支援 thinking_budget,但建議您遷移至 thinking_level,以獲得更可預測的成效。請勿在同一要求中使用這兩者。

  5. Gemini 3 是否支援 Batch API?可以,Gemini 3 支援 Batch API

  6. 是否支援脈絡快取?可以,Gemini 3 支援脈絡快取

  7. Gemini 3 支援哪些工具?Gemini 3 支援 Google 搜尋檔案搜尋程式碼執行網址脈絡。此外,這項功能也支援標準的函式呼叫,可搭配自訂工具使用 (但無法搭配內建工具)。請注意,目前不支援「Grounding with Google Maps」和「Computer Use」。

後續步驟

  • 開始使用 Gemini 3 食譜
  • 請參閱專屬的 Cookbook 指南,瞭解思考層級,以及如何從思考預算遷移至思考層級。