OpenCode with DeepSeek API: what you need
Running OpenCode with DeepSeek API models is one of the cheapest ways to get an agentic coding workflow in your terminal. OpenCode can talk to any OpenAI-compatible endpoint, so you only need a base URL, an API key, and a model name. This guide gives you a working config, explains which DeepSeek model to use for which task, and shows how to keep token spend predictable.
The setup below uses the BangunWeb AI Router. It is one key and one prepaid balance that covers DeepSeek, Claude, GPT, and other models. You can switch models later without changing your tooling.
What you need before you start
- OpenCode installed (see the official OpenCode docs for the install method for your OS).
- A BangunWeb account and an API key that starts with
bwr_live_. - A prepaid token balance or the free trial tokens that new Google sign-ins receive.
There is no subscription and no credit card requirement. You can pay with QRIS, Indonesian bank transfer, retail outlets, or USDT. The QRIS and USDT payment page explains the options.
Why pair OpenCode with DeepSeek models
Coding agents are token-hungry. A single task can involve reading many files, planning, editing, running tests, and reading the output. Every step re-sends context. That makes the price per 1M tokens matter more than almost anything else when you choose a model.
DeepSeek models are popular for this reason: they handle everyday coding work at a low per-token cost. The DeepSeek family on the router currently includes deepseek-v4-flash, deepseek-v4-pro, deepseek-v4.1-flash, deepseek-v4.1-creative, deepseek-v4-flash-0731, and deepseek-v4-pro-0813. Live prices are on the DeepSeek API pricing page. They change, so check there instead of trusting any number in a blog post.
Step-by-step: connect OpenCode to the router
OpenCode supports custom providers through a JSON config file that uses an OpenAI-compatible adapter. The steps below follow that pattern. Option names can change between OpenCode releases, so compare with the current OpenCode docs if something does not load.
- Create your API key. Sign in to BangunWeb, open the AI Router dashboard, and copy your
bwr_live_...key. - Export the key as an environment variable so it never lands in a repo:
export BANGUNWEB_API_KEY="bwr_live_..." - Add a provider to your OpenCode config (for example
opencode.jsonin your project or your global config folder):{ "$schema": "https://opencode.ai/config.json", "provider": { "bangunweb": { "npm": "@ai-sdk/openai-compatible", "name": "BangunWeb", "options": { "baseURL": "https://router.bangunweb.com/v1", "apiKey": "{env:BANGUNWEB_API_KEY}" }, "models": { "deepseek-v4-flash": { "name": "DeepSeek V4 Flash" }, "deepseek-v4-pro": { "name": "DeepSeek V4 Pro" } } } }, "model": "bangunweb/deepseek-v4-flash" } - Start OpenCode in your project folder and open the model picker. You should see the BangunWeb models you listed.
- Run a small task first, such as "explain this function", and check your balance afterward to see how many tokens it used.
There is also a shorter walkthrough on the OpenCode with BangunWeb page.
Test the endpoint before blaming the agent
If OpenCode shows an error, test the key and model outside the agent first. This curl call uses the OpenAI-format endpoint:
curl https://router.bangunweb.com/v1/chat/completions \
-H "Authorization: Bearer bwr_live_..." \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "Write a Python function that reverses a string."}]
}'
If this works, the key, balance, and model name are fine, and the problem is in the OpenCode config. If it fails, check the key, the balance, and the exact model slug. You can list valid slugs with GET /v1/models. The AI Router API docs cover auth and endpoints.
Which DeepSeek model for which job
You do not need the biggest model for every prompt. A practical split looks like this:
| Task | Model to try | Why |
|---|---|---|
| Quick edits, renames, boilerplate, explaining code | DeepSeek V4 Flash | Fast and low cost, good for high-volume agent loops |
| Multi-file refactors, tricky bugs, planning | DeepSeek V4 Pro | Stronger model for harder reasoning, at a higher per-token cost |
| Newer Flash tier | DeepSeek V4.1 Flash | Worth comparing against V4 Flash on your own codebase |
The honest way to choose is to run the same two or three real tasks on each model and compare the result and the token usage. Public benchmarks do not tell you how a model behaves on your repo.
When a task is truly hard, you can switch to a Claude or GPT model with the same key. Claude models unlock after your first purchase. See the Claude API pricing page and the GPT API pricing page for what is available.
Keep token spend under control
Cheap per-token pricing does not help if the agent burns through millions of tokens on a vague prompt. These habits help most:
- Scope the task. "Fix the null check in
auth.ts" costs far less than "improve the auth system". - Start new sessions often. Long conversations re-send the whole history on every turn.
- Use a Flash model by default and move up only when the output is not good enough.
- Exclude junk from context. Keep build output, lockfiles, and vendored folders out of what the agent reads.
- Check usage after the first few tasks so you know your real cost per task before you scale up.
To turn token counts into a budget, read how to estimate AI API cost per request. Use the live model price table for the per-1M-token numbers.
Common problems and fixes
"Model not found"
The slug in your config must match the router exactly. DeepSeek V4.1 Flash is deepseek-v4.1-flash with a dot, while its web page URL uses dashes. Check GET /v1/models if unsure.
401 or authentication errors
Confirm that the environment variable is set in the same shell where you start OpenCode. A key exported in another terminal tab will not be visible.
Insufficient balance
Prepaid billing means requests stop when the balance runs out. Top up and retry. Package pricing is shown live on the token package page. Bigger packages cost less per token.
You prefer Claude Code instead
The router also speaks the Anthropic format. If Claude Code is your main tool, follow the Claude Code custom base URL guide.
Is a router better than going direct?
It depends on what you need. Going direct to one provider is simple if you already have an account and a card that works. A router is useful when you want several model families under one key, prepaid billing, or local payment methods. For a neutral breakdown, see the comparison with OpenRouter and official APIs and the OpenRouter alternative page, which also says when OpenRouter fits better.
Next step
Create your key, paste the config above, and run one small task on DeepSeek V4 Flash. Then check your usage and decide whether to step up to Pro. You can start from the BangunWeb AI Router overview, and new Google accounts get free trial tokens to test the setup before buying anything.