Skip to content

[Solution] How to enable DeepSeek V4 thinking mode in OpenCode using Anthropic API #24122

Description

@LieGeee

Problem

When using DeepSeek V4 with thinking mode enabled in OpenCode, you may encounter this error:

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

This happens because:

  1. DeepSeek V4 returns reasoning_content (thinking process) in addition to content (final answer)
  2. In multi-turn conversations with tool calls, reasoning_content must be passed back to the API
  3. The @ai-sdk/openai-compatible package doesn't preserve and pass back reasoning_content

Solution

Use DeepSeek's Anthropic-compatible API instead of the OpenAI-compatible one. The @ai-sdk/anthropic package natively supports reasoning mode (Claude extended thinking).

Configuration

Edit ~/.config/opencode/opencode.json:

"deepseekv4": {
  "npm": "@ai-sdk/anthropic",
  "name": "DeepSeek",
  "options": {
    "baseURL": "https://api.deepseek.com/anthropic",
    "apiKey": "your-deepseek-api-key"
  },
  "models": {
    "deepseek-v4-pro": {
      "name": "DeepSeek-V4-Pro",
      "limit": {
        "context": 1048576,
        "output": 262144
      },
      "options": {
        "thinking": {
          "type": "enabled",
          "budgetTokens": 8192
        }
      }
    }
  }
}

Key Changes

  1. npm: Change from @ai-sdk/openai-compatible to @ai-sdk/anthropic
  2. baseURL: Change from https://api.deepseek.com to https://api.deepseek.com/anthropic
  3. thinking.type: Set to "enabled" to activate thinking mode

Why This Works

  • DeepSeek provides two API formats: OpenAI-compatible and Anthropic-compatible
  • The Anthropic SDK has native support for reasoning mode (used by Claude's extended thinking)
  • By switching to the Anthropic API format, OpenCode can properly handle reasoning_content without code changes

Usage

After restarting OpenCode, DeepSeek V4 will work with thinking mode enabled. You'll see the reasoning process in the model's responses.

References

Tested Environment

  • OpenCode version: Latest (as of 2026-04-24)
  • DeepSeek API: v4-pro
  • OS: Windows 11

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions