OpenCode setup guide
Set up DeepSeek models in OpenCode with a relay.fast key
OpenCode is an open-source coding agent that works in the terminal. To use DeepSeek in OpenCode through relay.fast, you need an API key, one configuration file and two environment variables.
What you need
As of 27 November 2026, OpenCode costs nothing to use and works with API keys from third-party providers. OpenCode reaches relay.fast as a provider at https://relay.fast/v1. Each request is charged per token to your relay.fast balance. There is no subscription. The model catalog lists deepseek-v4.1-flash, the small model for text and images, and deepseek-v4-pro, the large model for text only.
Manual DeepSeek setup in OpenCode
- Create an API key in the relay.fast dashboard.
- Save this code as the separate file
~/.config/opencode/relayfast.json. Your mainopencode.jsonstays untouched.{ "$schema": "https://opencode.ai/config.json", "model": "relayfast/deepseek-v4.1-flash", "provider": { "relayfast": { "npm": "@ai-sdk/openai-compatible", "name": "relay.fast", "options": { "baseURL": "https://relay.fast/v1", "apiKey": "{env:RELAY_FAST_OPENCODE_API_KEY}" }, "models": { "deepseek-v4.1-flash": { "name": "deepseek-v4.1-flash", "reasoning": true, "tool_call": true, "temperature": false, "attachment": true, "modalities": { "input": ["text", "image"], "output": ["text"] }, "limit": { "context": 1000000, "output": 128000 }, "options": { "reasoningEffort": "medium" }, "variants": { "low": { "reasoningEffort": "low" }, "medium": { "reasoningEffort": "medium" }, "high": { "reasoningEffort": "high" }, "xhigh": { "reasoningEffort": "xhigh" } } }, "deepseek-v4-pro": { "name": "deepseek-v4-pro", "reasoning": true, "tool_call": true, "temperature": false, "limit": { "context": 1000000, "output": 128000 }, "options": { "reasoningEffort": "medium" }, "variants": { "low": { "reasoningEffort": "low" }, "medium": { "reasoningEffort": "medium" }, "high": { "reasoningEffort": "high" }, "xhigh": { "reasoningEffort": "xhigh" } } } } } } } - Set two environment variables.
OPENCODE_CONFIGholds the path to the file.RELAY_FAST_OPENCODE_API_KEYholds the key. The file only names the variable. The key itself never goes into the file.# macOS and Linux export OPENCODE_CONFIG=~/.config/opencode/relayfast.json export RELAY_FAST_OPENCODE_API_KEY=sk-your-api-key # Windows (PowerShell), then open a new terminal setx OPENCODE_CONFIG "$HOME\.config\opencode\relayfast.json" setx RELAY_FAST_OPENCODE_API_KEY sk-your-api-key - On macOS and Linux, add the
exportlines to your shell profile, for example~/.zshrc. Otherwise the variables disappear when the terminal window closes. On Windows,setxsaves the variables permanently. They take effect in new terminal windows. - Open a new terminal and run this command. It prints
relayfast/deepseek-v4-proandrelayfast/deepseek-v4.1-flash.opencode models relayfast - Start OpenCode. The
"model"line in the file makesdeepseek-v4.1-flashthe default model. To switch to the other model, type/modelsinside OpenCode. - To send a single request without the interactive window, use this command.
opencode run --model relayfast/deepseek-v4.1-flash "Reply with one short sentence"
One-command setup
The script configures OpenCode for relay.fast. It adds a relay.fast provider with every chat model your key can use, DeepSeek models included, and keeps the key in an environment variable. It asks for the API key inside the script, so the key never appears in the command or shell history. Every downloaded file is checked against a published SHA-256 checksum, and running it again can restore the previous settings.
Windows (PowerShell):
powershell -NoProfile -ExecutionPolicy Bypass -Command "irm https://relay.fast/downloads/setup/install-opencode-en.ps1 | iex"macOS and Linux:
curl -fsSL https://relay.fast/downloads/setup/install-opencode-en.sh | bashYou can read the script before running it by opening the same URL in a browser.
What the lines of the file mean
"npm": "@ai-sdk/openai-compatible"tells OpenCode to send requests in the OpenAI format (Chat Completions). DeepSeek models do not need an extraproviderline. GPT and Claude models do. The general OpenCode guide shows that line."limit"sets the context window to 1,000,000 tokens and the maximum output to 128,000 tokens."reasoning": trueand"options": {"reasoningEffort": "medium"}turn on reasoning at the medium level."variants"lists the other levels, which are low, high and xhigh."attachment"and"modalities"appear only fordeepseek-v4.1-flash, because only this model takes images."tool_call": truesays the model can call tools. A coding agent needs tools to read and edit files.
Troubleshooting
- If
opencode models relayfastprints nothing or an error about the provider, this terminal does not seeOPENCODE_CONFIG. Open a new terminal window. - OpenCode 2 keeps a background server that remembers the environment it started with. Run
opencode --versionto see your version. On OpenCode 2, runopencode service restartafter you change the variables. - A 401 error with the text
Invalid tokenmeans the key is wrong, disabled or pasted with spaces. - A 404 error with
model_not_foundmeans the model id does not match the catalog. Copy the id from the catalog exactly. As of 27 November 2026, DeepSeek's own documentation calls the small modeldeepseek-flash. The relay.fast catalog lists the same family asdeepseek-v4.1-flash. - A context length error means the task is larger than the model's context window. Start a new session.
Keep agent costs under control
A coding agent sends the conversation, file contents and tool results with every step, so input tokens make up most of the bill. Use a mid-priced model for routine edits and a frontier model for hard tasks, prefer models with a cache-read price for long sessions, and keep auto-approve limits low until you know what a typical task costs. Current prices are in the live pricing catalog.
Current DeepSeek model prices
Prices checked from the live catalog. "From" is the lowest price among the relay.fast sources that currently serve the model. The price you pay depends on the source your request uses and can change on any day. The pricing page always shows current values.
| Model | Model ID | Official input / output per 1M tokens | relay.fast from, input / output | Cache read from | Context |
|---|---|---|---|---|---|
| DeepSeek V4.1 Flash price depends on the time of day; the peak-hours price is shown | deepseek-v4.1-flash | $0.3 / $1.2 | $0.03 / $0.12 (−90%) | $0.0006 | 1M |
| DeepSeek V4 Pro price depends on the time of day; the peak-hours price is shown | deepseek-v4-pro | $1.32 / $3.96 | $0.165 / $0.495 (−87%) | $0.0055 | 1M |
Frequently asked questions
Does DeepSeek work in Claude Code with a relay.fast key?
No. Claude Code sends requests in the Anthropic Messages format, and in that format relay.fast serves Claude models. A DeepSeek request in that format is rejected with a 400 error that says the model is not available through this endpoint and points to /v1/chat/completions.
Which other programs can use DeepSeek with a relay.fast key?
Cline, Roo Code, Kilo Code and Aider. Each has its own setup guide on relay.fast.
Do I need a subscription to use DeepSeek in OpenCode?
No. OpenCode takes an API key, and each request is charged per token to the relay.fast balance.
What is the difference between deepseek-v4-pro and deepseek-v4.1-flash?
deepseek-v4.1-flash is the small model and takes text and images. deepseek-v4-pro is the large model and takes text only. Both have a context window of 1,000,000 tokens.
Is OpenCode affiliated with relay.fast or DeepSeek?
No. OpenCode is a separate product. This page only shows how to connect it to relay.fast.