Using DeepSeek API with OpenCode CLI in Your Terminal
Published: 2026-07-07 | Category: Developer Tools | Reading Time: 8 min
If you live in the terminal, you want your AI coding assistant to live there too. OpenCode CLI is a terminal-based coding assistant that works with any OpenAI-compatible API. Pair it with DeepSeek's models through AIWave, and you get a fast, cheap, and powerful coding workflow — no browser, no IDE plugin, just your shell.
This guide covers installation, configuration, model selection, and practical usage patterns.
What Is OpenCode CLI?
OpenCode is an open-source terminal AI assistant. It provides:
- Inline code explanations — pipe code through it
- Shell command suggestions — describe what you want, get the command
- File-aware chat — it reads your project files
- Model switching — swap models mid-conversation
It's designed for developers who prefer vim/neovim or just don't want another Electron app eating RAM.
Installation
OpenCode is distributed as a standalone binary. Install it via your preferred method:
# macOS / Linux (Homebrew)
brew install opencode
# Or download directly
curl -fsSL https://opencode.dev/install.sh | bash
# Go users
go install github.com/opencode-ai/opencode@latest
Verify installation:
$ opencode --version
opencode v1.x.x
Step 1: Get Your AIWave API Key
OpenCode needs an API key and base URL:
- Sign up at AIWave (GitHub, Discord, Passkey, or Email — $5 free credit on signup)
- Copy your API key from the dashboard
- Note the base URL:
https://aiwave.live/v1
Step 2: Environment Variable Configuration
OpenCode reads configuration from environment variables. Set them in your shell profile:
# ~/.bashrc or ~/.zshrc
export OPENCODE_API_BASE="https://aiwave.live/v1"
export OPENCODE_API_KEY="sk-your-aiwave-key-here"
export OPENCODE_MODEL="deepseek-v4-flash"
Reload your shell:
source ~/.bashrc
For Windows (PowerShell), add to your profile:
# In $PROFILE (run: notepad $PROFILE)
$env:OPENCODE_API_BASE = "https://aiwave.live/v1"
$env:OPENCODE_API_KEY = "sk-your-aiwave-key-here"
$env:OPENCODE_MODEL = "deepseek-v4-flash"
Step 3: Verify the Connection
Test that OpenCode can reach the API:
$ opencode chat "Say 'connection successful' and nothing else"
If configured correctly, you'll see the response in your terminal. If you get an authentication error, double-check your API key and base URL.
Model Selection for Terminal Use
Different models serve different purposes in a terminal workflow. Here's how to configure model switching.
Default: DeepSeek V4 Flash
The best default for terminal use:
export OPENCODE_MODEL="deepseek-v4-flash"
- Pricing: $0.14 input / $0.28 output per 1M tokens
- Context: 1M tokens
- HumanEval: 89.2%
- Why: Fast responses, massive context window, excellent coding ability. At this price, you won't hesitate to ask questions. The 1M context is particularly useful in terminal — you can pipe entire log files or source files through it.
Heavy Lifting: DeepSeek V4 Pro
For complex refactoring or architecture questions:
# Switch for a single session
OPENCODE_MODEL="deepseek-v4-pro" opencode chat "Refactor this module to use a pub/sub pattern"
# Pricing: $0.42 input / $0.84 output per 1M tokens
# HumanEval: 92.1%
# Context: 1M tokens
DeepSeek V4 Pro is the flagship — 92.1% HumanEval, beating GPT-4o's 90.2%. Use it when accuracy matters more than cost.
Reasoning: DeepSeek R1
For debugging and logic puzzles:
export OPENCODE_MODEL="deepseek-r1"
# Pricing: $0.605 input / $2.409 output per 1M tokens
# Context: 128K tokens
DeepSeek R1 uses chain-of-thought reasoning. It's slower and more expensive, but produces step-by-step reasoning that's invaluable for tracking down subtle bugs.
Free Option: GLM-4.7 Flash
export OPENCODE_MODEL="glm-4.7-flash"
# Pricing: FREE ($0.00/$0.00)
# Context: 128K tokens
# HumanEval: 72.5%
GLM-4.7 Flash is completely free — zero cost per token. Not the strongest coder, but at $0.00/1M you can use it as much as you want. Use it for quick lookups and simple questions.
Practical Usage Patterns
Pattern 1: Explain Code in Your Pipeline
Pipe code directly to OpenCode for explanation:
# Explain a function from your codebase
grep -A 20 "def process_order" app/orders.py | opencode chat "Explain this function"
# Explain a shell command
opencode chat "Explain this command: find . -name '*.py' -exec grep -l 'import os' {} \;"
Pattern 2: Generate Shell Commands
Describe what you want in plain English:
$ opencode chat "Find all Python files modified in the last 7 days and print their sizes"
# Response: find . -name "*.py" -mtime -7 -exec ls -lh {} \; | awk '{print $5, $9}'
Pattern 3: Code Review in the Terminal
Feed a file for review:
$ opencode file-review app/auth.py
# OpenCode reads the file and provides inline review comments
Pattern 4: Generate Boilerplate
$ opencode chat "Generate a FastAPI endpoint that accepts a JSON payload with user_id (int) and action (str), validates with Pydantic, and returns a status dict"
Expected output:
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, Field
app = FastAPI()
class ActionRequest(BaseModel):
user_id: int = Field(..., gt=0)
action: str = Field(..., min_length=1, max_length=100)
@app.post("/action")
async def handle_action(req: ActionRequest):
try:
# Process the action here
return {"status": "ok", "user_id": req.user_id, "action": req.action}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
Pattern 5: Git Commit Messages
$ git diff --staged | opencode chat "Write a concise conventional commit message for this diff"
Script Wrappers for Quick Model Switching
If you frequently switch models, create shell functions:
# Add to ~/.bashrc or ~/.zshrc
oc() {
local model="${OPENCODE_MODEL:-deepseek-v4-flash}"
local cmd="$1"
shift
case "$cmd" in
flash) OPENCODE_MODEL="deepseek-v4-flash" opencode "$@" ;;
pro) OPENCODE_MODEL="deepseek-v4-pro" opencode "$@" ;;
reason) OPENCODE_MODEL="deepseek-r1" opencode "$@" ;;
budget) OPENCODE_MODEL="glm-4.7-flash" opencode "$@" ;;
coder) OPENCODE_MODEL="qwen3-coder-480b-a35b-instruct" opencode "$@" ;;
*) opencode "$@" ;;
esac
}
# Usage:
# oc flash chat "explain this regex"
# oc coder file-review main.py
# oc reason chat "find the bug in this function: ..."
Cost Analysis for Terminal Usage
Terminal interactions tend to be shorter than IDE chat sessions. Here's a realistic monthly estimate:
| Usage Pattern | Avg Tokens per Call | Calls/Day | Model | Monthly Cost |
|---|---|---|---|---|
| Quick questions | 1K/500 | 20 | DeepSeek V4 Flash | ~$0.01 |
| Code generation | 3K/2K | 10 | Qwen3 Coder | ~$0.01 |
| Code review | 8K/2K | 5 | DeepSeek V4 Pro | ~$0.03 |
| Debugging | 5K/3K | 3 | DeepSeek R1 | ~$0.03 |
| Misc (free model) | — | — | GLM-4.7 Flash | $0.00 |
Total: ~$0.08/month. Compare this to Cursor at $20/month or Copilot at $10/month — that's 250× to 250× cheaper.
Advanced: Using OpenCode with Neovim
If you use Neovim, you can integrate OpenCode through its command interface:
-- In your Neovim config
vim.keymap.set('v', '<leader>oc', ':<C-u>!<CR>'
.. 'opencode chat "Explain the selected code and suggest improvements"<CR>')
Select code in visual mode, press <leader>oc, and OpenCode opens in a terminal split with the analysis.
Troubleshooting
Connection timeout: AIWave servers are in Singapore. If you're in North America or Europe and see >2s latency, try the free GLM-4.7 Flash ($0.00/1M) for latency-sensitive tasks — it routes through the same endpoint but responses are faster due to smaller model size.
Rate limiting: AIWave's budget tier has rate limits. If you hit them, consider upgrading. Check pricing for details.
JSON parse errors: Ensure your base URL is exactly https://aiwave.live/v1 with no trailing slash or path additions.
Next Steps
- Sign up for AIWave and get your $5 free credit
- Explore the full model catalog — 60+ models available
- Join the AIWave Discord to share your terminal workflows
Terminal AI isn't a novelty — for developers who live in the shell, it's the most natural interface. DeepSeek's models deliver GPT-4o-level coding quality at a fraction of the cost, and OpenCode makes it seamless.
Build smarter with 50+ Chinese AI models — DeepSeek, GLM, Kimi, ERNIE, Qwen & more.
One OpenAI-compatible API. $5 free credit. No Chinese phone needed.Already using OpenAI? Switch in 2 lines of code — just change the base_url.
Top comments (0)