# Gemini 思考设置:thinkingLevel、thinkingBudget 与 reasoning_effort Source: https://ofox.io/zh/docs/develop/models/gemini/thinking 本页说明 Gemini 模型的思考默认值与调节方式。模型 ID 与接口地址见 [Gemini 系列概览](https://ofox.io/zh/docs/develop/models/gemini)。 **要点**:除 Flash-Lite 外,Gemini 模型默认开启思考,复杂问题可能耗时 1 分钟以上。对速度敏感的场景请降低思考量。 Gemini 模型在回答前会先进行思考。思考消耗的 token 计入输出并按输出单价计费,数量见 `usageMetadata.thoughtsTokenCount`(OpenAI 兼容接口为 `usage.completion_tokens_details.reasoning_tokens`)。 | 模型 | 默认 | 调节方式 | |---|---|---| | Gemini 3.x(Flash-Lite 除外) | 开启思考 | `thinkingLevel`,如 `"low"`;也接受 `thinkingBudget`(思考 token 上限) | | Flash-Lite 系列(3.5、3.1) | 不思考 | 传入 `thinkingLevel` 或 `thinkingBudget` 后开启 | 实测在同一道数学题上,`thinkingLevel: "low"` 可将 Gemini 3.5 Flash 的思考 token 从约 6000 降至约 4600,耗时也相应缩短。`thinkingBudget: 0` 可关闭 3.5 Flash、3 Flash Preview 的思考;3.1 Pro Preview、3.8 Flash 传入后仍会思考,无法完全关闭。 **Python(google-genai)** ```python filename="gemini_thinking.py" import os from google import genai from google.genai import types client = genai.Client( api_key=os.environ["OFOX_API_KEY"], http_options={"api_version": "v1beta", "base_url": "https://api.ofox.io/gemini"}, ) resp = client.models.generate_content( model="google/gemini-3.8-flash", contents="找出所有小于 50 的正整数 n,使 n² + n + 41 不是质数。", config=types.GenerateContentConfig( thinking_config=types.ThinkingConfig(thinking_level="low"), ), ) print(resp.text) print("思考 token:", resp.usage_metadata.thoughts_token_count or 0) ``` **cURL** ```bash filename="Terminal" curl "https://api.ofox.io/gemini/v1beta/models/google/gemini-3.8-flash:generateContent" \ -H "x-goog-api-key: $OFOX_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "contents": [{"parts": [{"text": "找出所有小于 50 的正整数 n,使 n² + n + 41 不是质数。"}]}], "generationConfig": { "thinkingConfig": {"thinkingLevel": "low"} } }' ``` **Python(OpenAI SDK)** ```python filename="gemini_thinking_openai.py" import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"]) resp = client.chat.completions.create( model="google/gemini-3.8-flash", reasoning_effort="low", messages=[{"role": "user", "content": "找出所有小于 50 的正整数 n,使 n² + n + 41 不是质数。"}], ) print(resp.choices[0].message.content) details = resp.usage.completion_tokens_details print("思考 token:", details.reasoning_tokens if details else 0) ``` - `thinkingLevel: "low"` 时,模型对简单问题可能不进行思考,`thoughtsTokenCount` 不出现。 - 需要查看思考过程时,在 `thinkingConfig` 中加入 `"includeThoughts": true`,`parts` 中带有 `"thought": true` 的条目为思考摘要,其余为回答。 - 思考 token 计入 `maxOutputTokens`。上限设置过小时,回答会在中途截断,见[常见报错](https://ofox.io/zh/docs/develop/models/gemini#errors)。 - `thinkingConfig` 位于 `generationConfig` 内。