Skip to content

[Bug] DeepSeek V4 fails with 'reasoning_content must be passed back' error in multi-turn conversations #24124

@LieGeee

Description

@LieGeee

Bug Description

When using DeepSeek V4 with OpenCode, multi-turn conversations fail with the error:

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

Steps to Reproduce

  1. Configure DeepSeek V4 in opencode.json:
"deepseek": {
  "npm": "@ai-sdk/openai-compatible",
  "name": "DeepSeek",
  "options": {
    "baseURL": "https://api.deepseek.com",
    "apiKey": "sk-xxx"
  },
  "models": {
    "deepseek-reasoner": {
      "name": "DeepSeek-V4",
      "limit": {
        "context": 1048576,
        "output": 262144
      }
    }
  }
}
  1. Start a conversation with DeepSeek V4
  2. Send a second message in the same conversation
  3. Error occurs

Expected Behavior

Multi-turn conversations should work seamlessly, with reasoning_content properly preserved between turns.

Actual Behavior

The conversation fails because @ai-sdk/openai-compatible doesn't preserve reasoning_content from DeepSeek's thinking mode responses.

Environment

  • OpenCode version: Latest
  • DeepSeek model: deepseek-reasoner (V4)
  • SDK: @ai-sdk/openai-compatible

Root Cause

DeepSeek V4 enables thinking mode by default and returns reasoning_content in responses. The OpenAI-compatible SDK doesn't handle this field, causing it to be lost between conversation turns.

Workaround

Switch to Anthropic API format, which natively supports reasoning modes:

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

This configuration:

  • Uses @ai-sdk/anthropic instead of @ai-sdk/openai-compatible
  • Points to DeepSeek's Anthropic-compatible endpoint
  • Properly preserves reasoning_content across conversation turns
  • Allows explicit thinking mode configuration

Alternative Solutions

Community members have also suggested using transformRequestBody hooks to manually preserve reasoning_content, but the Anthropic API approach is cleaner and officially supported.

References

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions