大模型网摘deepseek.wang

Tutorials · 2026-11-04

Controlling deepseek-flash Thinking Mode in Python: the Thinking Switch and reasoning_effort

deepseek-flash (now served by DeepSeek-V4.1-Flash-1017) has a default behavior that is easy to miss: thinking mode is on by default. The official description: "Supports both non-thinking and thinking (default) modes." A plain call therefore reasons before answering — usually better quality, at the price of higher latency and more output tokens. This tutorial collects the official switching mechanism and a checklist for when to toggle it off.

The parameters, straight from the official example

The curl example in the official Quick Start includes these two fields in the request body:

{
  "model": "deepseek-flash",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ],
  "thinking": {"type": "enabled"},
  "reasoning_effort": "high",
  "stream": false
}

In Python with the OpenAI SDK, the same keys ride along as extra body parameters:

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["DEEPSEEK_API_KEY"],
    base_url="https://api.deepseek.com",
)
resp = client.chat.completions.create(
    model="deepseek-flash",
    messages=[{"role": "user", "content": "Explain the von Neumann architecture in three sentences"}],
    extra_body={
        "thinking": {"type": "enabled"},
        "reasoning_effort": "high",
    },
)
print(resp.choices[0].message.content)

Set the thinking type to "disabled" for non-thinking mode. The official docs include a dedicated Thinking Mode page on the switching details; the accepted values of reasoning_effort should be taken from the official docs — the public example shows "high", and we will not guess at other tiers.

When to turn thinking off

Three cases where non-thinking mode makes sense: format-shaped tasks — rewriting, summarizing, classifying, extracting; the gain from reasoning is limited; FIM completion — the official feature table marks FIM Completion (Beta) as non-thinking mode only, so code completion has no choice; high-frequency short calls — chat small talk, request routing, keyword extraction; at dozens of calls per second, reasoning latency wrecks the experience. For a prompting-side treatment of the same question, see our guide on whether simple tasks need deep thinking.

When to keep it on

Multi-step reasoning, math, debugging, agent planning — DeepSeek's own Harness coding agent runs on these models — all have error costs far above a few seconds of latency. Keep thinking on and raise reasoning_effort when needed. The 1017 build was specifically tuned for agentic coding (see our tech-report explainer), and thinking mode is the channel through which that training pays off.

The cost math: the switch only moves token counts

The official price table lists no separate line item for thinking — billing still follows total input/output tokens. The difference: with thinking on, tokens consumed by the reasoning process count as output at $0.60 per 1M off-peak ($1.20 peak); with it off, the same task typically produces far fewer output tokens. For batch jobs, schedule thinking-off requests outside peak hours (01:00–04:00 and 06:00–10:00 UTC, Mon–Fri) and stack context caching for extra savings. Need a key first? Start with the Python quickstart.

One-line takeaway: thinking mode is deepseek-flash's default weapon, not its default tax — flip the switch per task, not globally.