DeepSeek V4 in OpenCode: Setup Guide

Run DeepSeek V4 in OpenCode. Configure the provider, set model IDs, and fix the thinking-mode bug where reasoning_content gets dropped and OpenCode errors out on turn 2-3.

August 17, 2026
DeepSeekOpenCodeV4Coding AgentAPIIntegrationThinking Mode

DeepSeek officially documents OpenCode as a supported integration for V4 models. Setup is one command — but a thinking-mode gotcha will break tool-heavy sessions on the default OpenAI-compatible provider unless you fix it first. This guide covers both.

Why OpenCode

OpenCode is an open-source, terminal-native coding agent that runs in your repo, reads AGENTS.md, and drives multi-turn tool use the same way Claude Code does — edit files, run commands, review diffs — all locally, with the model of your choice behind it. Because it's model-agnostic, it's a natural home for DeepSeek V4, and DeepSeek's documentation lists it as an officially supported integration alongside Claude Code and others.

Quick Setup

Use OpenCode 1.14.24 or newer — DeepSeek explicitly recommends the latest version to avoid compatibility issues.

  1. Install OpenCode
  2. Run opencode, type /connect, enter deepseek
  3. Paste your DeepSeek API key
  4. Select DeepSeek-V4-Pro

Model identifiers:

ModelIdentifier
V4 Pro (standard)deepseek-v4-pro
V4 Pro (1M context)deepseek-v4-pro[1m]
V4 Flashdeepseek-v4-flash

OpenCode's model picker also surfaces DeepSeek models through its built-in Model Hub; the identifiers above are the ones to use in config. V4 Pro supports 1M-token context in its [1m] variant (the standard model ships with a 262,144-token context window) — relevant if your agent loop needs to hold a large repository or long session history without churning cache.

The Thinking-Mode Bug

DeepSeek's thinking mode returns a reasoning_content field alongside content — the model's chain of thought. In multi-turn tool calls, that field must be passed back to the API unchanged. When it isn't, DeepSeek rejects the request with:

400: The reasoning_content in the thinking mode must be passed back to the API

OpenCode's default DeepSeek provider uses @ai-sdk/openai-compatible, which does not reliably preserve and replay reasoning_content across turns. Agentic sessions are nothing but turns, so this surfaces on the second or third tool call. The same class of bug affects V4 Flash.

The Anthropic SDK natively understands reasoning blocks — Claude extended thinking works the same way — so OpenCode stops dropping the field. Add a provider block in ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "deepseek-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "DeepSeek (Anthropic-compatible)",
      "options": {
        "baseURL": "https://api.deepseek.com/anthropic",
        "apiKey": "{env:DEEPSEEK_API_KEY}"
      },
      "models": {
        "deepseek-v4-pro[1m]": {
          "name": "DeepSeek V4 Pro (1M)",
          "limit": { "context": 1048576, "output": 262144 },
          "options": { "thinking": { "type": "enabled", "budgetTokens": 8192 } }
        },
        "deepseek-v4-flash": {
          "name": "DeepSeek V4 Flash"
        }
      }
    }
  }
}

Restart OpenCode and thinking mode works across turns. The budgetTokens line caps the reasoning budget; raise it for hard problems, lower it for routine work to save tokens and latency. If you prefer the native OpenAI-compatible API but still want thinking, the @ai-sdk/openai-compatible route requires passing reasoning_content back in every turn — the Anthropic endpoint removes that footgun entirely.

Fix 2: Disable Thinking on OpenAI-Compatible Endpoints

If you want to stay on DeepSeek's native OpenAI-compatible API, disable thinking for the model:

{
  "models": {
    "deepseek-v4-pro": {
      "options": {
        "extra_body": { "thinking": { "type": "disabled" } }
      }
    }
  }
}

This is stable on plain OpenAI-compatible providers, but the cost is explicit: you lose the visible reasoning that makes V4 Pro strong on hard problems. If you're disabling thinking for everyday work, V4 Flash deserves a hard look — it's the cheaper, faster model for routine agent tasks.

Pricing Note

DeepSeek moved from flat pricing to peak/off-peak rates on August 16, 2026. V4-Pro: $0.66 in / $1.98 out per 1M tokens off-peak; $1.32 in / $3.96 out at peak. Cache-hit input is dramatically cheaper ($0.022–$0.044). Peak hours are 01:00–04:00 and 06:00–10:00 UTC. Model a budget around cache hits and off-peak scheduling — for agent loops that repeatedly retrieve the same context, cache stability is the deciding cost factor. The same economics apply through the Anthropic-compatible endpoint, so Fix 1 doesn't change your cost model — it changes your reliability.

Performance Expectations

Independent runs show V4 Pro is harness-sensitive: it scored 98+ under DeepSeek's own setup but 91–96 under OpenCode's default system prompt (modeltest, Aug 14). If OpenCode with V4 Pro feels a notch below the frontier, the harness is the likely culprit, not the model. Two things to try before switching models: use a reasoning-heavy system prompt tuned for the task, and consider the Code-style agent pattern — collapsing multi-round-trip sequences into single programmatic calls reduces the number of turns where harness overhead can bite. See the DeepSeek Harness blog for the full picture.

Troubleshooting

  • "Reasoning_content must be passed back" error — you're on the OpenAI-compatible provider with thinking enabled. Apply Fix 1 (Anthropic-compatible endpoint), or disable thinking with Fix 2.
  • Model not listed in the picker — after /connect deepseek, verify the model IDs in your config match the provider's catalog (deepseek-v4-pro, deepseek-v4-pro[1m], deepseek-v4-flash). Custom model blocks you've added with a models key override the picker list — check opencode.json.
  • 401 unauthorized on first turn — the API key env var isn't reaching the process. Confirm DEEPSEEK_API_KEY is exported in the shell that launches opencode, not just written to a file.
  • V4 Flash feels wrong for the task — Flash is the fast/cheap tier; hard problems are V4 Pro's job. With thinking disabled, use Flash for routine agent turns and switch to Pro (thinking on) for anything requiring visible reasoning.
  • After a config change, nothing updates — restart OpenCode. Provider blocks and model options are read at startup.

OpenCode stores session state locally, and AGENTS.md files in your repo are picked up automatically — so rules tuned with the agentic prompt maintenance guidance apply to V4 sessions the same way they do to any other model.