DeepSeek in OpenCode: API key, Go, Zen and OpenRouter
Use DeepSeek V4.1 Flash and V4 Pro in OpenCode: model IDs, December 2026 prices with peak hours, the opencode.json block, and where each route sends your code.
With a DeepSeek API key, run /connect in OpenCode, type deepseek, paste the key and pick deepseek/deepseek-flash (V4.1 Flash) or deepseek/deepseek-v4-pro. Both have a 1M-token context and 384K of output, and DeepSeek charges $0.15 in and $0.60 out per million tokens for Flash off-peak, double that on weekdays from 01:00 to 04:00 and 06:00 to 10:00 UTC. Your prompts then go to DeepSeek, whose privacy policy stores data in China. Without a DeepSeek key, OpenCode sells the same models itself: opencode/deepseek-v4.1-flash at $0.12 / $0.48 on its pay-as-you-go catalogue, hosted in the US and EU, or opencode-go/deepseek-v4.1-flash inside the $10 Go plan once Regions is set to Global. Through OpenRouter, use openrouter/deepseek/deepseek-v4.1-flash-1017 and pin the host you want. Prices as listed on December 2, 2026, with OpenCode 2.4.3 current.
The routes side by side
Four ways in, all serving the same weights. They differ in who bills you, what each token costs, and whose servers read your code. Flash prices per million tokens (input / output), December 2, 2026:
| Route | Model ID in OpenCode | Flash price | Who sees the prompts |
|---|---|---|---|
Your DeepSeek key | deepseek/deepseek-flash | $0.15 / $0.60 off-peak, $0.30 / $1.20 peak | DeepSeek, storing data in China |
OpenCode pay-as-you-go (the Console, formerly Zen) | opencode/deepseek-v4.1-flash | $0.12 / $0.48 at any hour, listed as 60% off | Hosts in the US and EU, zero retention |
OpenCode Go | opencode-go/deepseek-v4.1-flash | Part of the $10 or $40 monthly plan | A Global-region host, 0 days’ retention under a DeepSeek agreement |
OpenCode’s free model | opencode/deepseek-v4.1-flash-free | Free for a limited time, daily cap | A zero-retention provider |
OpenRouter | openrouter/deepseek/deepseek-v4.1-flash-1017 | Each host’s own price; DeepSeek’s matches its direct one | Whichever of 53 hosts answers, unless you pin one |
V4 Pro follows the same pattern at higher prices, and is not offered free. The sections below give each route’s setup, its V4 Pro figures and the terms behind the last column.
DeepSeek’s own API key
OpenCode’s catalogue, models.dev, has DeepSeek built in under the provider ID deepseek, so there is nothing to configure beyond the key (making one is in the DeepSeek API key guide). In the terminal interface:
- Run
/connect, typedeepseekand select the provider. - Paste the key. It is stored in OpenCode’s database, not in a config file.
- Run
/models(or Ctrl+X then M) and choose Flash or V4 Pro.
DeepSeek’s own OpenCode page recommends v1.18.30 or later and says to “Select the DeepSeek-V4-Flash model”. That name is out of date. In the catalogue’s DeepSeek entries, the current Flash is deepseek-flash, which serves DeepSeek-V4.1-Flash-1017, while deepseek-v4-flash is marked deprecated. DeepSeek’s API still accepts the old name and serves V4.1 Flash for it at the Flash price, so an older config naming it keeps working. The two current models, from DeepSeek’s pricing page on December 2, 2026:
| Per million tokens | Flash, off-peak | Flash, peak | V4 Pro, off-peak | V4 Pro, peak |
|---|---|---|---|---|
Input, cache hit | $0.003 | $0.006 | $0.022 | $0.044 |
Input, cache miss | $0.15 | $0.30 | $0.66 | $1.32 |
Output | $0.60 | $1.20 | $1.98 | $3.96 |
Peak is 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday; weekends and Chinese public holidays are off-peak all day. Both models take 1M tokens of context and return up to 384K, think by default and call tools; only Flash reads images. DeepSeek allows 2,500 concurrent Flash requests per account and 500 for Pro, and notes that prices may change. A coding agent resends the whole conversation every turn, so most of its input lands in the cache-hit row, which is where DeepSeek is cheapest.
Effort comes from the catalogue too: DeepSeek takes low, high (the default) or max, and Ctrl+T cycles a model’s variants in the session. OpenCode’s providers docs also give DeepSeek models a longer wait for the first response, ten minutes instead of five, which matters when a long thinking turn starts slowly.
On a server: the key and opencode.json
/connect works over SSH, since a key needs no browser. For a machine you set up from a shell, or an unattended run, the key can live in a file only you can read and be referenced from the config. This writes it without the key reaching your history or the screen; it overwrites any file already at that path. After the second line, paste the key and press Enter:
mkdir -p ~/.config/deepseek && chmod 700 ~/.config/deepseek
(umask 077; read -rs KEY; printf '%s' "$KEY" > ~/.config/deepseek/key)CopiedThen, in ~/.config/opencode/opencode.json, set the default model and point the DeepSeek provider at the file:
{
"$schema": "https://opencode.ai/config.json",
"model": "deepseek/deepseek-flash",
"providers": {
"deepseek": {
"settings": {
"apiKey": "{file:~/.config/deepseek/key}"
}
}
}
}CopiedThe config docs warn that a missing file “will be replaced with an empty string”, as an unset {env:...} variable is, so a wrong path sends requests with an empty key and DeepSeek answers with an authentication error rather than OpenCode warning you. This is the version 2 form; version 1’s provider block with options.apiKey is still read, per the migration page.
The other way is the environment variable the catalogue names, DEEPSEEK_API_KEY. In version 2 it has to be set on the server process, OpenCode’s background service, not in your shell. Paste the key after the first line; the last should list DeepSeek as an environment connection:
read -rs KEY
opencode service set env DEEPSEEK_API_KEY "$KEY"
unset KEY
opencode auth listCopiedSetting it restarts the service on the next OpenCode command, and a key saved with /connect for the same provider wins over the variable. Where each of these copies is kept, and how to remove one, is in OpenCode API keys.
Through OpenCode Go or the pay-as-you-go catalogue
Both come through one entry: run /connect, choose OpenCode and sign in with your OpenCode account. Neither needs a DeepSeek account, and they differ in price and in where the model runs.
Pay-as-you-go, billed from prepaid credit with 4.6% plus $0.31 added to each purchase, lists on its models page opencode/deepseek-v4.1-flash at $0.12 input, $0.48 output and $0.0024 cached, marked 60% off a $0.30 / $1.20 list price, and opencode/deepseek-v4-pro at $1.74 / $3.48, with $0.145 cached. No peak hours are listed. That makes Flash cheaper there than at DeepSeek even off-peak, and Pro dearer than at DeepSeek even at peak. The page says “All our models are hosted in the US and EU” and that its providers keep nothing and do not train, and DeepSeek is not among its listed exceptions.
Go ($10 a month, Go Plus $40) counts DeepSeek against the plan’s shared allowance. On the Go page, now listing 29 models, V4.1 Flash covers up to $100 a month on Go and $200 on Go Plus if used alone, about 43,300 and 86,700 requests per five hours; V4 Pro covers $15 and $60, about 1,040 and 4,180. The catch is the region. The Go docs say:
By default, paid endpoints that train on request data are blocked, and allowed regions are Europe & United States.Copiedand, for both DeepSeek models, “select Global under Regions”, which a workspace owner or admin does under Settings, then Privacy. Until then requests to the two models are blocked. The same docs list both at 0 days’ retention with a footnote: “DeepSeek: ZDR agreement is renewed monthly. The current agreement is valid through December 31, 2026.” The docs do not say where Global sends the request; in August 2026 an issue report listed the same switch as “OpenCode Go China-hosted model opt-in”. Use the model as opencode-go/deepseek-v4.1-flash or opencode-go/deepseek-v4-pro; everything else about the plan is in the OpenCode Go guide.
The free model, opencode/deepseek-v4.1-flash-free, needs no account. Its provider keeps no data and does not train on it, it is free “for a limited time”, and it shares OpenCode’s daily cap on free use, counted per network (the free usage limit covers what happens at the cap).
Through OpenRouter, pinned to a host
With an OpenRouter key connected, OpenCode takes OpenRouter’s full model ID after the openrouter/ prefix. The ID decides who can answer. On December 2, 2026, OpenRouter’s API listed 53 hosts for deepseek/deepseek-v4.1-flash-1017, DeepSeek among them at its own prices with the weekday peak, and the cheapest at $0.02 per million input tokens, a host whose endpoints are tagged fp4. The undated deepseek/deepseek-v4.1-flash had 33 hosts and none of them DeepSeek. V4 Pro is deepseek/deepseek-v4-pro-0813, with 20 hosts. OpenRouter bills each host’s list price and takes its fee, 5.5% on the Standard plan, when you buy credits.
By default OpenRouter picks a host per request by what a good response would cost at each, so consecutive turns can land on different hosts. OpenCode’s provider entries take a body whose fields are merged into each request, and it can be set on one model, so OpenRouter’s own provider object goes there. This keeps Flash on DeepSeek’s servers:
{
"$schema": "https://opencode.ai/config.json",
"model": "openrouter/deepseek/deepseek-v4.1-flash-1017",
"providers": {
"openrouter": {
"models": {
"deepseek/deepseek-v4.1-flash-1017": {
"body": {
"provider": { "only": ["deepseek"] }
}
}
}
}
}
}CopiedWith only set, no other host is allowed, so when DeepSeek cannot serve the request it fails rather than going elsewhere. To keep prompts away from DeepSeek instead, put "ignore": ["deepseek"] in the same place, or "zdr": true to allow only hosts that keep nothing. Settings on your OpenRouter account apply to every request whatever the client sends: opting out of training there means OpenRouter “will not route to providers that train”. Which hosts keep or train on prompts is in the OpenRouter data policy guide.
Where your code goes on each route
An agent sends the files it reads, not only your question, so the host is the real choice here. DeepSeek’s privacy policy, last updated February 10, 2026 and applied to its API by the platform terms, says:
To provide you with our services, we directly collect, process and store your Personal Data in People’s Republic of China.CopiedIt lists training “our machine learning models and algorithms” among the uses, with a right to opt out by writing to privacy@deepseek.com rather than a setting. That governs the direct key and OpenRouter’s DeepSeek endpoint. OpenCode’s pay-as-you-go route keeps the model in the US and EU with zero retention; Go keeps nothing under its DeepSeek agreement, dated to the end of 2026, but needs the Global region; the free model sits with a zero-retention provider for as long as it lasts; and OpenRouter’s other hosts each have their own terms. Why the weights themselves send nothing anywhere, and which hosts are in China, is in is DeepSeek safe for AI agents.