You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenCode CLI Tutorial: Use DeepSeek API in Your Terminal (Setup, Model Selection & Cost Guide)
#20
Using DeepSeek API with OpenCode CLI in Your Terminal
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 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
# 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 API Key
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 ~/.zshrcexport 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
$ 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
export OPENCODE_MODEL="deepseek-v4-flash"
Spec
Value
Input pricing
$0.14 / 1M tokens
Output pricing
$0.28 / 1M tokens
Context window
1M tokens
HumanEval
89.2%
Fast responses, massive context window, excellent coding ability. The 1M context is particularly useful in terminal ??you can pipe entire log files or source files through it.
Heavy Lifting: DeepSeek V4 Pro
# Switch for a single session
OPENCODE_MODEL="deepseek-v4-pro" opencode chat "Refactor this module to use a pub/sub pattern"
Spec
Value
Input pricing
$0.42 / 1M tokens
Output pricing
$0.84 / 1M tokens
Context window
1M tokens
HumanEval
92.1% (beats GPT-4o 90.2%)
Use it when accuracy matters more than cost.
Reasoning: DeepSeek R1
export OPENCODE_MODEL="deepseek-r1"
Spec
Value
Input pricing
$0.605 / 1M tokens
Output pricing
$2.409 / 1M tokens
Context window
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"
Spec
Value
Input pricing
$0.00 / 1M tokens
Output pricing
$0.00 / 1M tokens
Context window
128K tokens
HumanEval
72.5%
Completely free ??zero cost per token. Use it for quick lookups and simple questions.
Practical Usage Patterns
Pattern 1: Explain Code in Your Pipeline
# 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
$ 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
$ opencode file-review app/auth.py
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"
$ git diff --staged | opencode chat "Write a concise conventional commit message for this diff"
Script Wrappers for Quick Model Switching
# Add to ~/.bashrc or ~/.zshrcoc() {
local cmd="$1"shiftcase"$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 using AIWave pricing:
Usage Pattern
Avg Tokens (In/Out) per Call
Calls/Day
Model
Monthly Cost
Quick questions
1K / 500
20
DeepSeek V4 Flash ($0.14/$0.28)
~$0.17
Code generation
3K / 2K
10
Qwen3 Coder ($0.12/$0.36)
~$0.32
Code review
8K / 2K
5
DeepSeek V4 Pro ($0.42/$0.84)
~$0.76
Debugging
5K / 3K
3
DeepSeek R1 ($0.605/$2.409)
~$0.92
Misc lookups
??
unlimited
GLM-4.7 Flash ($0.00)
$0.00
Total: ~$2.17/month. Compare this to Cursor at $20/month or Copilot at $10/month ??that's 5? to 9? cheaper, with pay-per-use so you only pay for what you actually use.
Advanced: Using OpenCode with Neovim
-- In your Neovim configvim.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 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: Check pricing for rate limit details by tier.
Base URL: Ensure your base URL is exactly https://aiwave.live/v1 with no trailing slash, no query params, no extra path segments.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Using DeepSeek API with OpenCode CLI in Your Terminal
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 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:
It's designed for developers who prefer
vim/neovimor just don't want another Electron app eating RAM.Installation
Verify installation:
Step 1: Get Your API Key
https://aiwave.live/v1Step 2: Environment Variable Configuration
OpenCode reads configuration from environment variables. Set them in your shell profile:
Reload your shell:
For Windows (PowerShell), add to your profile:
Step 3: Verify the Connection
$ 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
Fast responses, massive context window, excellent coding ability. The 1M context is particularly useful in terminal ??you can pipe entire log files or source files through it.
Heavy Lifting: DeepSeek V4 Pro
Use it when accuracy matters more than cost.
Reasoning: DeepSeek R1
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
Completely free ??zero cost per token. Use it for quick lookups and simple questions.
Practical Usage Patterns
Pattern 1: Explain Code in Your Pipeline
Pattern 2: Generate Shell Commands
Pattern 3: Code Review in the Terminal
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:
Pattern 5: Git Commit Messages
Script Wrappers for Quick Model Switching
Cost Analysis for Terminal Usage
Terminal interactions tend to be shorter than IDE chat sessions. Here's a realistic monthly estimate using AIWave pricing:
Total: ~$2.17/month. Compare this to Cursor at $20/month or Copilot at $10/month ??that's 5? to 9? cheaper, with pay-per-use so you only pay for what you actually use.
Advanced: Using OpenCode with Neovim
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 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: Check pricing for rate limit details by tier.
Base URL: Ensure your base URL is exactly
https://aiwave.live/v1with no trailing slash, no query params, no extra path segments.Summary
Sign up at AIWave to get $5 free credit and try it out. Explore the full model catalog ??60+ models available.
All reactions