· Updated

OpenCode Provider-Neutral Design: Why Model Freedom Matters for Coding Agents

OpenCode#guide#opencode#multi-provider#open-source#model-routing

OpenCode’s defining feature isn’t a specific capability — it’s the freedom to choose your model on every task. While commercial agents lock you into one provider’s roadmap and pricing, OpenCode treats models as interchangeable backends. Switch from Claude to GPT-4o to a local Llama with a single flag. No vendor negotiation, no platform migration, no feature loss.

This guide explains how the provider-neutral architecture works, how to configure every major provider, and practical routing strategies that cut costs without sacrificing quality.

The Problem: Vendor Lock-in Is Expensive

Most coding agents couple their product to one model provider:

Agent Locked Provider Monthly Cost (heavy use)
Cursor Anthropic (Claude) $20-50+
Claude Code Anthropic (Claude) $20-100+
GitHub Copilot OpenAI (GPT) $10-40+
Windsurf Anthropic/OpenAI $15-60+

When that provider raises prices, degrades quality, or hits rate limits — you’re stuck. OpenCode breaks this coupling entirely.

How OpenCode’s Provider Abstraction Works

OpenCode uses a unified provider interface. Every supported provider implements the same contract:

interface Provider {
  complete(request: CompletionRequest): Promise<CompletionResponse>
  stream(request: CompletionRequest): AsyncIterable<StreamChunk>
  models(): Promise<Model[]>
  validateConfig(config: ProviderConfig): ValidationResult
}

This means:

  • Same API surface — tools, context, output parsing work identically
  • Per-request provider selection--provider anthropic --model claude-3-5-sonnet
  • Per-skill provider config — different skills can use different models
  • Local models on equal footing — Ollama, llama.cpp, vLLM are first-class providers

Supported Providers (2026)

Cloud Providers

Provider Models Best For Cost/1M tokens
Anthropic Claude 3.5 Sonnet, Opus, Haiku Complex reasoning, code gen $3-15 input / $15-75 output
OpenAI GPT-4o, GPT-4o-mini, o1-preview General purpose, speed $2.50-15 input / $10-60 output
Google Gemini 1.5 Pro, Flash Large context, multimodal $1.25-3.50 input / $5-10 output
Groq Llama 3.1 70B/8B, Mixtral Ultra-fast inference ~$0.60 input / ~$0.80 output
Together AI Llama 3.1, Qwen 2.5, DeepSeek Open models, cheap ~$0.30-0.90 input/output
Fireworks Llama 3.1, DeepSeek Coder Code-specialized ~$0.20-0.50 input/output

Local Providers (Zero Marginal Cost)

Runtime Setup Models Hardware
Ollama ollama serve + pull Codellama, DeepSeek, Qwen, Phi 8GB+ RAM (quantized)
llama.cpp Binary + model file Any GGUF CPU/GPU, very flexible
vLLM Docker/PIP High-throughput serving GPU (A100/H100 ideal)
LM Studio GUI + local server Any GGUF Easy local experimentation

Configuration

Environment Variables (Simplest)

# ~/.bashrc or ~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
export GOOGLE_API_KEY="..."
export GROQ_API_KEY="..."
export TOGETHER_API_KEY="..."
export FIREWORKS_API_KEY="..."

# Local: no key needed, just run the server
# ollama serve
# llama-cpp-server -m model.gguf

Project Config (.opencode/config.json)

{
  "providers": {
    "anthropic": {
      "apiKey": "${ANTHROPIC_API_KEY}",
      "defaultModel": "claude-3-5-sonnet-20241022"
    },
    "openai": {
      "apiKey": "${OPENAI_API_KEY}",
      "defaultModel": "gpt-4o"
    },
    "ollama": {
      "baseUrl": "http://localhost:11434",
      "defaultModel": "codellama:13b"
    },
    "groq": {
      "apiKey": "${GROQ_API_KEY}",
      "defaultModel": "llama-3.1-70b-versatile"
    }
  },
  "defaultProvider": "anthropic",
  "modelRouting": {
    "simple": "groq:llama-3.1-8b-instant",
    "coding": "anthropic:claude-3-5-sonnet",
    "reasoning": "openai:o1-preview",
    "local": "ollama:codellama:13b"
  }
}

Per-Skill Provider Override

In any SKILL.md:

---
name: "code-review"
description: "Review code for bugs and style"
allowedTools: ["read", "grep", "edit"]
provider: "anthropic"
model: "claude-3-5-sonnet-20241022"
temperature: 0.1
maxTokens: 8192
---

# Code Review Skill
...

This skill will always use Claude Sonnet regardless of global defaults.

Practical Routing Strategies

1. Tiered by Task Complexity

# ~/.opencode/routing.sh
kilo_quick() {
  # Boilerplate, docs, simple transforms → cheapest fast model
  opencode --provider groq --model llama-3.1-8b-instant "$@"
}

kilo_code() {
  # Actual coding tasks → strong code model
  opencode --provider anthropic --model claude-3-5-sonnet "$@"
}

kilo_think() {
  # Architecture, debugging, complex reasoning → best reasoning model
  opencode --provider openai --model o1-preview "$@"
}

kilo_private() {
  # Sensitive code → never leaves machine
  opencode --provider ollama --model codellama:13b "$@"
}

Cost impact: 80% of daily tasks (boilerplate, docs, explanations) run on ~$0.60/M tokens instead of $15/M. Heavy reasoning stays on the best model.

2. Tiered by Privacy Requirements

Code Type Provider Why
Public OSS, tutorials Any cloud No sensitivity
Internal business logic Anthropic/OpenAI Strong models, reputable privacy policies
Auth/crypto/secrets Local (Ollama) Zero data egress
Customer data Local only Compliance (GDPR, HIPAA)

3. Failover Chains

{
  "modelRouting": {
    "primary": "anthropic:claude-3-5-sonnet",
    "fallback": [
      "openai:gpt-4o",
      "groq:llama-3.1-70b-versatile",
      "ollama:codellama:13b"
    ]
  }
}

If Anthropic hits rate limits or degrades, OpenCode transparently falls back.

4. Cost-Aware Routing (Monthly Budget)

# Track spend per provider
opencode --provider anthropic --model claude-3-5-sonnet --track-cost "$@"
# Output includes: [Cost: $0.023] 

# Monthly budget enforcement
export OPENCODE_MONTHLY_BUDGET=50  # USD
opencode --enforce-budget "$@"

See our coding agent pricing guide 2026 for detailed cost modeling.

Real-World Example: A Day with Multi-Provider Routing

# Morning: quick boilerplate (Groq - fast, cheap)
kilo_quick "react form component with zod validation"

# Feature work: actual coding (Claude - best code quality)
kilo_code "implement OAuth2 PKCE flow in auth module"

# Code review: thorough analysis (Claude - nuanced reasoning)
kilo_code --skill code-review "review PR #234"

# Architecture decision: deep reasoning (o1 - best reasoning)
kilo_think "design event sourcing vs CRUD for audit log"

# Debugging production issue (local - sensitive logs)
kilo_private "analyze this stack trace from prod"

# Evening: generate tests (Groq - high volume, lower stakes)
kilo_quick --skill test-gen "generate integration tests for auth"

Estimated daily cost: ~$1.50 vs $15-30 with single-provider premium agent.

Provider-Specific Tips

Anthropic (Claude)

  • Best for: Complex coding, reasoning, long context
  • Use claude-3-5-sonnet for daily coding — best price/performance
  • Use claude-3-opus only for hardest architecture decisions
  • Enable prompt caching for repeated context (reduces cost 90% on cache hits)

OpenAI (GPT)

  • Best for: General purpose, function calling, o1 reasoning
  • gpt-4o-mini is surprisingly good for simple tasks at 1/10th cost
  • o1-preview for genuine multi-step reasoning (not just “think harder”)

Google (Gemini)

  • Best for: Massive context (1M+ tokens), multimodal
  • gemini-1.5-flash is extremely cheap for large-context tasks
  • Good for “analyze this entire repo” workflows

Groq / Together / Fireworks

  • Best for: High-volume, low-stakes generation
  • Llama 3.1 70B on Groq = ~300 tokens/sec, ~$0.80/M
  • Use for: test generation, boilerplate, docs, simple refactors

Local (Ollama)

  • Best for: Privacy, zero marginal cost, offline
  • Quantization guide:
    • q4_k_m — 7B model ~4GB, good quality
    • q6_k — 7B model ~6GB, near-fp16 quality
    • q8_0 — 13B model ~13GB, excellent quality
  • Codellama 13B q6_k is the sweet spot for coding on 16GB RAM

Benchmarking Your Providers

Run the same task across providers to compare:

# Create test prompt
cat > /tmp/test-prompt.txt << 'EOF'
Write a TypeScript function that parses a CSV string with quoted fields,
escaped quotes, and custom delimiters. Return typed array of objects.
Include error handling for malformed input.
EOF

# Test each provider
for provider in anthropic:claude-3-5-sonnet openai:gpt-4o groq:llama-3.1-70b-versatile ollama:codellama:13b; do
  echo "=== $provider ==="
  time opencode --provider ${provider%:*} --model ${provider#*:} \
    --file /tmp/test-prompt.txt 2>&1 | head -50
  echo ""
done

Compare: latency, output quality, token usage, cost.

Migrating from Single-Provider Agents

If you’re coming from Cursor/Claude Code/Copilot:

  1. Export your prompts — save your common prompts as OpenCode skills
  2. Map your workflows/plan, /review, /test skills replace IDE buttons
  3. Start with Anthropic default — closest to what you’re used to
  4. Add cheaper providers incrementally — route boilerplate to Groq first
  5. Try local for sensitive work — the privacy win is immediate

See OpenCode deep dive for the full skill-driven workflow.

Limitations & Gotchas

Issue Workaround
Provider APIs differ in features (tools, vision, caching) OpenCode abstracts common subset; provider-specific features need conditional skills
Local models slower on CPU Use GPU (Metal/CUDA) or smaller quantized models
Rate limits vary by provider Implement fallback chains; monitor usage
Model capabilities differ Route tasks to models proven good at that task type
Context windows vary Chunk large contexts; use Gemini for 1M+ tokens

Further Reading


Why pay $20/mo for ChatGPT, $20/mo for Claude, $20/mo for Gemini? aiFiesta gives you all of them and more for just $12/mo. One subscription, every answer.

FREE RESOURCE

Get the AI Agent Cheat Sheet

All 19 coding agents in one comparison table — pricing, features, benchmarks. Updated weekly. Delivered to your inbox.

s
sage_watcher
Trend Watcher
Reads every HN thread and Reddit debate. Sees patterns before they become trends. Occasionally prophetic.

Related articles