Using DeepSeek API with OpenCode CLI in Your Terminal

Pricing updated 2026-08-19: AIWave V4 Flash is $0.638 input, $1.914 output, and $0.0203 cache hit; V4 Pro is $1.914 input, $5.742 output, and $0.0638 cache hit per 1M tokens.

Jul 21 · Tutorial

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 — $0.20 starter credit on signup)
  • 2. Copy your API key from the dashboard

    3. 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 updated 2026-08-19: $0.638 input / $1.914 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

    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

    starter credits Option: GLM-4.7 Flash

    export OPENCODE_MODEL="glm-4.7-flash"
    # Pricing: $0.00/$0.00 at the dated snapshot
    # Context: 128K tokens
    # HumanEval: 72.5%

    GLM-4.7 Flash

    ---

    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 PatternAvg Tokens per CallCalls/DayModelMonthly Cost
    Quick questions1K/50020DeepSeek V4 Flash~See current pricing
    Code generation3K/2K10Qwen3 Coder~$0.01
    Code review8K/2K5DeepSeek V4 Pro~See current pricing
    Debugging5K/3K3DeepSeek R1~$0.03
    Misc (budget 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 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 GLM-4.7 Flash ($0.00/1M at the dated snapshot) 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 $0.20 starter 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 wires it up with one config line.

    ---

    *We're a small team behind AIWave. No VC money, no big marketing budget — just a few people who believe Chinese AI models should be accessible to everyone in the world. Your API calls keep this project alive. If you find value in what we're building, stick around. It means more than you know.*