DeepSeek with OpenCode: Setup and Your First Coding Task

Last reviewed: November 15, 2026.

To use DeepSeek AI with OpenCode, install OpenCode, open it in your project, run /connect, choose DeepSeek, and enter your DeepSeek API key. Then run /models and select a DeepSeek model. OpenCode handles the coding workflow while DeepSeek supplies the model responses.

This walkthrough uses OpenCode V2 and the built-in direct DeepSeek provider. The example model is deepseek/deepseek-flash, listed in the OpenCode DeepSeek catalog. You will connect the provider, save a default, and complete a small coding exercise with a measurable result.

ItemWhat to use
ProviderDeepSeek
CredentialA DeepSeek Platform API key
Example OpenCode model referencedeepseek/deepseek-flash
Connect inside OpenCode/connect
Select a model inside OpenCode/models
Project configurationopencode.jsonc
Direct-route billingYour DeepSeek API account

What you need before starting

You need an internet connection, a local project folder, and a DeepSeek API key. Your DeepSeek API account must have sufficient available balance for the requests. Python 3 is needed only for the optional practice exercise below; Git is useful for reviewing changes.

DeepSeek Platform API keys dashboard showing the Create new API key button for OpenCode integration.

OpenCode supports several access routes. Choose one deliberately because the provider you connect determines the credential and billing arrangement.

RouteAccount or credentialWhen it fits
Direct DeepSeekDeepSeek API key and API balanceYou want the built-in connection to DeepSeek’s API; this is the main walkthrough.
OpenCode ConsoleOpenCode Console access and applicable credits or free-model eligibilityYou want models offered through OpenCode’s managed service.
OpenCode GoOpenCode Go subscription and credentialYou want the models and usage included in a Go plan.
OpenRouterOpenRouter API key and applicable balance or allowanceYou want a gateway route with its own model catalog and provider choices.

Both OpenCode Console and OpenCode Go are optional. Connecting a direct DeepSeek key does not require either plan. You also do not need an MCP server to select a model provider.

1. Install OpenCode and check its version

Use the official installation page for current packages and platform downloads. The commands below follow its V2 instructions.

macOS and Linux

Choose one installation method. The shell installer is:

Official OpenCode V2 installation instructions showing curl, npm, bun, Homebrew, and paru commands.
curl -fsSL https://opencode.ai/v2/install | bash

If you prefer npm and already have Node.js and npm available:

npm install -g @opencode/cli

Confirm which executable your terminal runs:

opencode --version
opencode --help

Windows

The current installation page provides standalone Windows CLI downloads and states that Windows package managers are unsupported. Download the archive for your architecture, extract it, and open PowerShell in the folder containing opencode.exe.

.\opencode.exe --version
.\opencode.exe "C:\path\to\your-project"

Replace the example project path with your own. After adding the executable’s folder to PATH, you can use opencode from a project terminal.

If you already have OpenCode 1

Follow the V1-to-V2 migration guide. Both versions use the opencode command. The guide calls for removing a package-managed V1 installation before installing V2; the V2 shell installer replaces the older binary.

V2 can normalize supported V1 configuration, so an older file does not automatically need a complete rewrite. New examples in this article use native V2 fields. For an existing V2 installation, the documented update command is opencode upgrade.

2. Connect your DeepSeek account

Open a terminal in the project you intend to work on. For the practice task later in this guide, you can create an empty folder first:

mkdir deepseek-opencode-demo
cd deepseek-opencode-demo
opencode

Inside OpenCode’s input area, type this slash command:

/connect
OpenCode DeepSeek provider connection menu showing Add account and existing connected accounts.
  1. Find and select DeepSeek.
  2. Enter the key created in your DeepSeek Platform account when prompted.
  3. Complete the connection, then open the model picker with /models.
  4. Select the direct DeepSeek entry corresponding to deepseek/deepseek-flash.
OpenCode model picker showing DeepSeek V4.1 Flash 1017 selected under the DeepSeek provider, with DeepSeek V4 Pro also available.

The connection flow is documented by DeepSeek’s OpenCode integration guide. That page still illustrates an earlier Flash label; use the current picker and catalog when choosing the model.

Where commands go: opencode and opencode auth list run in your operating system’s terminal. Commands beginning with /, such as /connect and /models, go inside OpenCode.

Confirm the selected provider and model

Check the active model in the interface before your first task. DeepSeek currently documents deepseek-flash as the API name serving DeepSeek V4.1 Flash 1017, and also offers deepseek-v4-pro. OpenCode prefixes the provider ID, producing references such as deepseek/deepseek-flash. See the current DeepSeek model table.

The OpenCode model picker reflects what is enabled and available in the current project. A saved credential alone does not prove that a model request succeeded. Verify the selected route and complete a small task before relying on the setup.

3. Save DeepSeek as the default model

Create opencode.jsonc in your project root, or merge this setting into an existing configuration:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "deepseek/deepseek-flash"
}
OpenCode JSONC configuration setting DeepSeek Flash as the default model

The normal built-in connection does not need a custom provider definition or an API key written into this file. OpenCode accepts JSON and JSONC; the configuration guide explains the supported locations and merge order.

For a default across projects, use the global configuration directory reported by opencode debug paths config. Project and managed settings can affect the effective result. A model already selected in a session also takes precedence over a newly configured default.

After a configuration change, use opencode reload in a terminal and check /models in the session. Selecting a model interactively changes that session; it does not rewrite your saved default.

Optional: use an environment variable

Skip this subsection if you connected successfully with /connect. For a setup that reads its key from the environment, V2 supports this configuration. Merge it with any other project settings you want to retain:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "deepseek/deepseek-flash",
  "providers": {
    "deepseek": {
      "settings": {
        "apiKey": "{env:DEEPSEEK_API_KEY}"
      }
    }
  }
}

Set the variable before starting a private server. In Bash:

export DEEPSEEK_API_KEY="replace_with_your_deepseek_key"
opencode --standalone

In PowerShell:

$env:DEEPSEEK_API_KEY = "replace_with_your_deepseek_key"
opencode --standalone

An already-running shared server may not receive a variable newly exported in another terminal. The provider environment guide explains this server-side requirement. It also notes that a saved account takes precedence over an environment connection for the same integration, so check the active account when switching credentials.

4. Complete a small coding task you can verify

Use the demo folder from the connection step, or another disposable project. This exercise contains one intentional boundary bug: orders totaling 5,000 cents ($50) or more should receive free shipping, but the starting function excludes exactly 5,000 cents.

Create the files in your text editor. Keep OpenCode open, and use a second terminal in the same demo folder for the test and Git commands below.

Create shipping.py:

def shipping_fee(subtotal_cents):
    return 0 if subtotal_cents > 5000 else 499

Create test_shipping.py beside it:

import unittest
from shipping import shipping_fee


class ShippingFeeTests(unittest.TestCase):
    def test_below_threshold(self):
        self.assertEqual(shipping_fee(4999), 499)

    def test_at_threshold(self):
        self.assertEqual(shipping_fee(5000), 0)

    def test_above_threshold(self):
        self.assertEqual(shipping_fee(5001), 0)


if __name__ == "__main__":
    unittest.main()

Run the baseline check in that folder:

python -m unittest -v
Python unit tests showing the shipping threshold test failing before the DeepSeek-assisted fix

Use python3 instead if that is your Python 3 command. The starting code should fail the test for exactly 5,000 cents. The other two tests should pass.

Optional: if Git is installed, establish a comparison baseline before the agent makes changes. Run these commands only in the disposable demo folder; staging the starting files lets you inspect the later edit with git diff.

git init
git add shipping.py test_shipping.py

Ask before edits and shell commands

For this exercise, merge the following permission rules into opencode.jsonc. This complete example also keeps DeepSeek as the default:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "deepseek/deepseek-flash",
  "permissions": [
    {
      "action": "edit",
      "resource": "*",
      "effect": "ask"
    },
    {
      "action": "shell",
      "resource": "*",
      "effect": "ask"
    }
  ]
}

Reload the configuration before continuing. In V2, ask requests a decision, allow permits the action, and deny blocks it. Rules are ordered, with the last matching rule taking effect; agent-specific rules can also apply. See the permissions reference.

Start with Plan

Inside OpenCode, run /agents and choose Plan. Then submit:

Read shipping.py and test_shipping.py.
Explain why the boundary test fails and propose the smallest fix.
Do not edit either file yet.
The shipping policy is free shipping for orders of 5,000 cents or more.

The terminal interface also lets you attach specific files with @. Selecting the two files is useful if your project contains many similarly named modules.

Plan is designed to explore without editing ordinary project files, but it can write OpenCode plan files and its shell access remains permission-controlled. The agent documentation describes those boundaries.

Switch to Build and apply the fix

Run /agents again and choose Build. Check that the selected model is still the intended DeepSeek entry, then submit:

Apply the smallest fix to shipping.py so all three existing tests pass.
Keep the test expectations unchanged.
Do not install dependencies or modify unrelated files.
Run python -m unittest -v, then summarize the change and test result.
Do not stage, commit, or push changes.

Review the requested edit and test command when OpenCode asks for permission. If your system uses python3, use that command in the prompt.

OpenCode permission prompt showing a proposed fix to the Python shipping threshold condition before approving the file edit.

Check the result yourself

The expected change is the inclusive comparison:

def shipping_fee(subtotal_cents):
    return 0 if subtotal_cents >= 5000 else 499

Run the tests again in your own terminal. All three should pass. If you staged the starting files earlier, inspect the unstaged difference:

Python unittest output showing all three shipping tests passing after the DeepSeek-assisted code fix.
git diff -- shipping.py test_shipping.py
Git diff comparing the original and corrected Python shipping threshold after a DeepSeek-assisted fix.

Success means the intended DeepSeek route answered, OpenCode made the narrow change, the unchanged tests all pass, and no unrelated modifications appeared. A message saying “fixed” is only the starting point for that check.

5. Add project guidance with AGENTS.md

For ongoing work, place an AGENTS.md file at the project root. OpenCode’s instructions guide recommends recording useful project conventions and verification commands. For this example:

# Project instructions

- Use only the Python standard library.
- Keep monetary values as integer cents.
- Run python -m unittest -v after changing shipping behavior.
- Keep each fix focused on the requested behavior.
- Explain any test that could not be run.

In a larger repository, include the relevant build command, test command, formatting rules, and directories that require special care. Keep these instructions accurate as the project changes. They guide the model; permissions control whether its actions are allowed.

You can also submit a focused task directly from your terminal:

opencode run --model deepseek/deepseek-flash "Explain the boundary cases in shipping.py."

The CLI command reference documents model and agent selection, session continuation, and other run options. For a first edit, the interactive interface makes it easier to inspect proposed actions.

Is DeepSeek with OpenCode free?

OpenCode is open-source software, while model access depends on the route you choose. Direct requests using your DeepSeek API key are billed through your DeepSeek account.

At the review date, the OpenCode Console model documentation lists DeepSeek V4.1 Flash Free as a limited-time offer. That is a separate OpenCode-provided route. Check its current availability and terms in the model picker; the offer does not make the direct deepseek/deepseek-flash connection free.

Official OpenCode documentation listing DeepSeek V4.1 Flash Free as a limited-time free model.

OpenCode Go is another optional route with subscription usage limits. Use its current plan documentation to assess that option rather than assuming a Go allowance applies to a direct DeepSeek key.

What affects the cost of a coding task?

A coding agent may make several model calls while it reads files, proposes changes, runs checks, and interprets their results. Your request can also carry conversation history and tool output, so task cost is more than the price of the first prompt.

DeepSeek’s official pricing table distinguishes input, output, cache behavior, and applicable timing-based rates. Review actual account usage when comparing models or workflows.

Official DeepSeek API pricing table comparing Flash and V4 Pro input, output, cache hit, and cache miss token rates.
  • Give the agent a specific file, behavior, and acceptance condition.
  • Start with a small change before requesting a repository-wide rewrite.
  • Inspect repeated tool failures instead of letting an unproductive loop continue.
  • Compare the cost of a completed, verified task rather than a single answer.

Troubleshoot DeepSeek in OpenCode

Identify the stage that failed: launching OpenCode, authenticating, selecting the model, running tools, or validating the code. Each stage needs a different check.

ProblemWhat to check
opencode is not foundConfirm installation and PATH. On Windows, try the extracted executable directly; reopen the terminal after changing PATH.
DeepSeek or its model is missingConnect the provider in the intended project, then inspect /models. Check enablement, configuration, and catalog access.
401Check the active DeepSeek account and key. Reconnect the intended credential rather than substituting a gateway key.
402Check the direct DeepSeek API balance. Credits held in OpenRouter or OpenCode Console do not fund this route.
400 or 422Read the request-format or parameter error. Review custom provider settings and model compatibility.
429Reduce concurrent work and pace requests. Check the selected provider’s current limits.
500 or 503Allow time for a transient provider failure to clear, then retry in a controlled way.
The model answers but does not editCheck the active agent, permission decisions, and tool errors. Select Build when you want an implementation.
An environment key is not detectedCheck the server’s environment and active saved account. Try the documented standalone setup.
The configured default seems ignoredCheck the current session’s selected model and higher-priority configuration.
Official DeepSeek API error codes table showing authentication failures, insufficient balance, rate limits, and server errors.

DeepSeek defines its HTTP errors in the error-code reference. Its rate-limit guide documents account-level concurrency limits; creating another key does not create a separate account allowance.

Check the local service before changing API settings

V2 normally uses a shared background server. If the interface is stuck or configuration does not appear to take effect, begin with:

opencode service status

The troubleshooting guide documents restarting an unhealthy service with opencode service restart. Save active work first because multiple local clients can use that server.

Useful inspection commands include:

opencode auth list
opencode models
opencode debug paths config

These show connection entries, available models, and configuration locations. They do not prove that a paid model request or coding task succeeded. Check the help for your installed version before using flags copied from older tutorials.

Errors involving reasoning_content or tool calls

Check your OpenCode version and any custom provider package or compatibility overrides. Current OpenCode documents handling for DeepSeek-style reasoning fields. Start from the built-in provider and its defaults before adding workarounds from an older issue. See model compatibility.

Where your code and credentials go

With the direct hosted setup, OpenCode runs the local workflow and sends the selected prompt and relevant project context to DeepSeek. A locally running terminal does not make the model inference local. Review the data terms for the provider and route you actually use.

OpenCode V2 stores saved provider credentials in the server’s SQLite database. Manage them through /connect or the authentication commands described in credential storage. Keep real keys out of project files, prompts, screenshots, and version control.

OpenCode’s privacy policy distinguishes its local software from hosted services. Local session data and snapshots also deserve care: a snapshot can include file contents. Submit only the project context appropriate for your chosen service.

Frequently asked questions

Do I need an MCP server to connect DeepSeek?

No. DeepSeek is a model provider in this setup. MCP servers supply additional tools or resources and are configured separately. Start with the built-in provider connection before adding integrations.

Can I use DeepSeek R1 or V3?

Use an available entry from the catalog for your chosen provider. The current direct DeepSeek API documents Flash and V4 Pro names; an older R1 or V3 tutorial does not establish current availability. A gateway or local model server has a separate catalog.

Do I need a powerful GPU?

No local inference GPU is required when OpenCode calls a hosted DeepSeek API. Running DeepSeek weights through a local server is a different deployment with its own hardware and model requirements.

Can I use DeepSeek through OpenRouter instead?

Yes, when the desired model is available through that route. Connect OpenRouter with its own key and select its DeepSeek entry in OpenCode. Keep the gateway’s credential, model reference, billing, and provider policies together rather than mixing them with the direct configuration.

Can I undo an unwanted change?

OpenCode provides /undo and /redo, but file restoration depends on available snapshots in a Git worktree. Snapshots do not reverse every side effect, such as database operations or running processes. Review the snapshot limitations and keep normal Git checkpoints or backups for important work.

Which model should I choose for coding?

Start with one available model, run the same small task, and compare the correctness of the patch, successful checks, responsiveness, and actual cost. Keep the chosen provider and model visible in your test notes so the comparison remains meaningful.