πŸ€– AI Tools
Β· 5 min read

How to Use DeepSeek V4 With OpenCode: Setup Guide for V4 Pro and Flash (2026)


DeepSeek V4 officially supports OpenCode, the open-source AI coding agent. This guide covers the exact setup: custom provider config, model selection, thinking modes, and tips from running V4 Pro autonomously in The $100 AI Startup Race.

Why OpenCode + DeepSeek V4

OpenCode is one of the few coding agents that supports custom providers via the AI SDK. That means you can point it at any OpenAI-compatible API, including DeepSeek’s.

The combination gives you:

  • V4 Pro (80.6% SWE-bench, 1M context) as your main coding model
  • V4 Flash ($0.28/1M output) for background tasks like file search and title generation
  • Full terminal agent capabilities: file editing, shell commands, project analysis
  • MIT-licensed model weights if you want to self-host later

We tested this setup in production. The DeepSeek agent in our AI Startup Race runs on OpenCode v1.14.22 + V4 Pro, executing 7 autonomous sessions per day. It built a full landing page, pricing page, about page, blog, and legal pages in its first session.

Prerequisites

You need:

  1. OpenCode v1.14.0+ (the npm version, not the old Go binary)
  2. A DeepSeek API key from platform.deepseek.com
  3. A git repository (OpenCode requires a git-initialized project)

Install OpenCode if you do not have it:

npm install -g opencode-ai

Verify the version:

opencode -v
# Should show 1.14.x or higher

If you see v0.0.x, you have the old Go binary. Remove it and reinstall via npm.

Configuration

Create or edit ~/.config/opencode/opencode.jsonc:

{
  "provider": {
    "deepseek": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "DeepSeek",
      "options": {
        "baseURL": "https://api.deepseek.com",
        "apiKey": "YOUR_DEEPSEEK_API_KEY"
      },
      "models": {
        "deepseek-v4-pro": {
          "name": "DeepSeek-V4-Pro",
          "limit": {
            "context": 1048576,
            "output": 262144
          },
          "options": {
            "reasoningEffort": "high",
            "thinking": {
              "type": "enabled"
            }
          }
        },
        "deepseek-v4-flash": {
          "name": "DeepSeek-V4-Flash",
          "limit": {
            "context": 1048576,
            "output": 262144
          },
          "options": {
            "reasoningEffort": "high",
            "thinking": {
              "type": "enabled"
            }
          }
        }
      }
    }
  },
  "agents": {
    "coder": {
      "model": "deepseek-v4-pro",
      "maxTokens": 16000
    },
    "task": {
      "model": "deepseek-v4-flash",
      "maxTokens": 8000
    },
    "title": {
      "model": "deepseek-v4-flash"
    }
  },
  "autoCompact": true
}

This config does three things:

  1. Registers DeepSeek as a custom provider via the @ai-sdk/openai-compatible npm package
  2. Defines both V4 Pro and V4 Flash as available models with their 1M context limits
  3. Assigns V4 Pro to the main coder agent and V4 Flash to background tasks (cheaper)

The autoCompact setting tells OpenCode to automatically summarize conversations when approaching the context limit, which matters with long coding sessions.

Running OpenCode With V4 Pro

Start an interactive session:

cd your-project
opencode

OpenCode will detect the DeepSeek provider from your config and use V4 Pro for the coder agent.

For a one-off non-interactive command:

opencode run -m deepseek/deepseek-v4-pro "Refactor the auth module to use JWT tokens"

For autonomous operation (no permission prompts):

opencode run -m deepseek/deepseek-v4-pro --dangerously-skip-permissions "Build a REST API for user management"

To use V4 Flash for cheaper tasks:

opencode run -m deepseek/deepseek-v4-flash "Fix the typo in README.md"

Agent Configuration

OpenCode uses three agents internally:

AgentRoleRecommended ModelWhy
coderMain coding, file edits, complex tasksdeepseek-v4-proNeeds the strongest reasoning
taskFile search, grep, background analysisdeepseek-v4-flashSpeed matters more than depth
titleSession title generationdeepseek-v4-flashTrivial task, use cheapest model

This split keeps costs down. V4 Flash handles the high-volume background work at $0.28/1M output while V4 Pro focuses on the actual coding at $3.48/1M output. In practice, the task and title agents use far fewer tokens than the coder agent, so the cost split is roughly 85% Pro / 15% Flash.

Thinking Modes

V4 Pro supports three reasoning modes:

  • Non-think: Fast responses for simple tasks
  • Think High: Logical analysis for complex problems (default in our config)
  • Think Max: Maximum reasoning depth for the hardest tasks

The "reasoningEffort": "high" in the config sets Think High as the default. For most coding tasks, this is the right balance between quality and token usage.

To use Think Max for a specific session, pass the variant flag:

opencode run -m deepseek/deepseek-v4-pro --variant max "Architect a distributed caching system"

Think Max uses more tokens and requires at least 384K context. Use it for architecture decisions, complex refactoring, or debugging hard problems. Use Think High for everything else.

Cost Comparison

Running OpenCode with DeepSeek V4 is significantly cheaper than the alternatives:

SetupCoder Model Cost (output)Typical Session Cost
OpenCode + V4 Pro$3.48/1M~$0.10-0.50
OpenCode + V4 Flash$0.28/1M~$0.01-0.05
Claude Code + Sonnet$15.00/1M~$0.50-2.00
Codex CLI + GPT-5.4$15.00/1M~$0.50-2.00

A typical 30-minute coding session with V4 Pro generates roughly 30K-150K output tokens, costing $0.10-0.50. The same session on Claude Code or Codex CLI costs 4-5x more.

If you run V4 Flash for routine tasks, costs drop to near zero. This is why we use Flash for 5 of 7 daily sessions in the race and reserve Pro for complex work.

Project-Level Config

You can override the global config per project. Create .opencode.json in your project root:

{
  "agents": {
    "coder": {
      "model": "deepseek-v4-pro",
      "maxTokens": 32000
    }
  },
  "contextPaths": [
    "ARCHITECTURE.md",
    "docs/api-spec.md"
  ]
}

The contextPaths array tells OpenCode to automatically include specific files in every conversation. Useful for architecture docs, API specs, or coding guidelines that the model should always reference.

Troubleshooting

β€œagent coder not found”: You are running the old Go version of OpenCode (v0.0.x). Uninstall it and install via npm: npm install -g opencode-ai

β€œno valid provider available”: The custom provider config is not being read. Make sure the file is at ~/.config/opencode/opencode.jsonc or ~/.opencode.json. Check that the JSON is valid.

Slow responses: V4 Pro with Think High generates reasoning tokens before responding. This is normal. If you need faster responses for simple tasks, switch to V4 Flash or set "reasoningEffort": "low".

Context limit errors: V4 supports 1M tokens natively, but very long sessions can still hit limits. The "autoCompact": true setting handles this by summarizing older context automatically.

FAQ

Can I use V4 Pro with Claude Code instead of OpenCode?

Yes. DeepSeek provides an Anthropic-compatible API endpoint at https://api.deepseek.com/anthropic. Set ANTHROPIC_BASE_URL to that endpoint and ANTHROPIC_AUTH_TOKEN to your DeepSeek key. See our V4 Aider setup guide for similar configurations.

Is V4 Flash good enough for coding?

For routine tasks like bug fixes, content updates, and small features, V4 Flash (79.0% SWE-bench) is excellent and costs 12x less than V4 Pro. For complex architecture, multi-file refactoring, or hard debugging, use V4 Pro. The agent config in this guide already handles this split automatically.

How does this compare to using Aider with DeepSeek?

OpenCode has direct file system access. Aider works through SEARCH/REPLACE blocks that the model must format correctly. In our race testing, the old Aider + V3 setup produced files named after SEARCH/REPLACE instructions. OpenCode + V4 Pro produced 10 working pages in its first session. The tool matters as much as the model.