Multi-Model Workflows with OpenCode

Learn to switch between Gemini, GLM, DeepSeek, and MiniMax mid-session in OpenCode. Match each provider to task type and cut costs without sacrificing quality.

opencodemulti-modelgeminideepseekglmminimaxtutorial

Multi-Model Workflows with OpenCode

Multi-Model Workflows with OpenCode

OpenCode supports 75+ LLM providers. You can switch mid-session. Most developers pick one and stick with it — that's leaving 90% of the value on the table. This tutorial covers the real workflow: matching providers to task types, switching mid-session, and cutting costs without sacrificing output quality.

Why Multi-Model?

One model can't be the best at everything. Anthropic dominates reasoning. Google dominates context length. DeepSeek dominates cost. GLM handles bilingual tasks. MiniMax has strong creative output.

OpenCode is the only CLI tool that lets you use all of them in a single session. Claude Code locks you to Anthropic. Gemini CLI locks you to Google. OpenCode doesn't care.

The pattern: use the right model for the right phase of work.

Provider Setup

Adding providers

# Anthropic (best reasoning)
opencode provider add anthropic
export ANTHROPIC_API_KEY=sk-ant-...

# Google (best context length)
opencode provider add google
export GOOGLE_API_KEY=...

# DeepSeek (best cost)
opencode provider add deepseek
export DEEPSEEK_API_KEY=sk-...

# GLM (bilingual)
opencode provider add glm
export GLM_API_KEY=...

# MiniMax (creative)
opencode provider add minimax
export MINIMAX_API_KEY=...
ProviderModelBest ForApprox. Cost (per 1M tokens)
Geminigemini-2.5-proLarge codebase analysisFree tier (rate-limited) / ~$3.50 input paid API
GLMglm-4-plusBilingual tasks (ZH/EN)~$2.00
DeepSeekdeepseek-chat (V3)Bulk generation, boilerplate~$0.27
DeepSeekdeepseek-reasoner (R1)Complex multi-step reasoning~$0.55
MiniMaxabab-6.5sCreative writing, copy~$1.00
Anthropicclaude-sonnet-4-20250514Architecture, review, quality$3.00/$15.00

The Task-Type Matrix

Architecture & Planning

Use Claude or Gemini. You need reasoning depth, not speed or volume. These tasks are short — the cost difference is negligible.

# Switch to Anthropic for architecture work
opencode provider set anthropic
opencode model set claude-sonnet-4-20250514
Design the data model for a multi-tenant SaaS app with row-level security.
Include table relationships, index strategy, and migration plan.

Large Codebase Analysis

Use Gemini. 1M+ context window reads an entire project in one pass. No other provider comes close.

# Switch to Google for large context analysis
opencode provider set google
opencode model set gemini-2.5-pro
Analyze the entire src/ directory for performance bottlenecks.
Identify N+1 queries, unnecessary re-renders, and slow database calls.

Bulk Code Generation

Use DeepSeek. 95% cheaper than Claude. For boilerplate, tests, API endpoints, and repetitive code, the quality difference is negligible — the cost difference is massive.

# Switch to DeepSeek for cheap bulk generation
opencode provider set deepseek
opencode model set deepseek-chat
Generate Jest unit tests for the following 12 utility functions.
Each test should cover normal case, edge case, and error case.

Bilingual or Chinese Content

Use GLM. Native Chinese understanding that other providers have to translate internally.

# Switch to GLM for bilingual content
opencode provider set glm
opencode model set glm-4-plus
Translate this technical documentation to Chinese, preserving code
examples and technical terminology. Target: mainland China developers.

Creative Writing & Copy

Use MiniMax. Strong creative output with natural tone variation.

# Switch to MiniMax for creative copy
opencode provider set minimax
opencode model set abab-6.5s
Write landing page copy for a developer tool. Technical audience.
Friendly but not casual. Three sections: hero, features, CTA.

The Mid-Session Switch Pattern

The real power is switching during a session. Here's a real workflow:

Session: Build a feature with tests and docs

Phase 1 — Architecture (Claude)

# Switch to Anthropic for architecture work
opencode provider set anthropic
opencode model set claude-sonnet-4-20250514

Claude designs the feature architecture. Detailed reasoning, edge cases, data flow. This is 2-3 back-and-forth turns. ~5,000 tokens total. Cost: ~$0.09.

Phase 2 — Code Generation (DeepSeek)

# Switch to DeepSeek for cheap bulk generation
opencode provider set deepseek
opencode model set deepseek-chat

DeepSeek generates the implementation. Boilerplate, component structure, type definitions. 4-5 turns. ~15,000 tokens. Cost: ~$0.004.

Phase 3 — Code Review (Claude)

# Switch back to Anthropic for code review
opencode provider set anthropic

Claude reviews everything for correctness, security, and style. 1-2 turns. ~3,000 tokens. Cost: ~$0.05.

Total: ~$0.14. All-Claude would have been ~$0.40.

When to switch checklist

Task PhaseUseWhy
Architecture/DesignClaudeBest reasoning, worth the cost
Requirements AnalysisGeminiLarge context, nuanced understanding
Code GenerationDeepSeekCheap, fast, code quality is fine
Test GenerationDeepSeekHigh volume, low reasoning requirement
Code ReviewClaudeNeed to catch subtle issues
DocumentationDeepSeek/MiniMaxVolume task, creative tone
Large Codebase ScanGemini1M context, document analysis
Bilingual TasksGLMNative language understanding
Copy/MarketingMiniMaxCreative output, tone variation

Cost Comparison: Real Session

A session building a new API endpoint with tests and documentation:

PhaseProviderTokens (in/out)Cost
ArchitectureClaude2,000 / 1,500$0.029
ImplementationDeepSeek3,000 / 4,000$0.002
Test generationDeepSeek2,000 / 6,000$0.002
Code reviewClaude5,000 / 1,000$0.030
DocumentationMiniMax1,000 / 2,000$0.003
Total5 providers27,500$0.066
All-Claude equivalent1 provider27,500$0.22

Multi-provider: 70% cheaper. Quality: same (architecture and review are Claude, which is what matters).

OpenCode Configuration

opencode.json provider defaults

{
  "providers": {
    "default": "deepseek",
    "architect": "anthropic",
    "review": "anthropic",
    "analyze": "google",
    "bilingual": "glm",
    "creative": "minimax"
  },
  "models": {
    "anthropic": "claude-sonnet-4-20250514",
    "google": "gemini-2.5-pro",
    "deepseek": "deepseek-chat",
    "glm": "glm-4-plus",
    "minimax": "abab-6.5s"
  }
}

AGENTS.md conventions

## Provider Strategy

When working on this project, follow this provider selection:
- Architecture and design: Claude (reasoning quality)
- Implementation and generation: DeepSeek (cost efficiency)
- Code review: Claude (correctness matters)
- Large codebase analysis: Gemini (1M context)
- Chinese/Japanese content: GLM (native understanding)
- Copy and marketing: MiniMax (creative tone)

Default provider for quick questions: DeepSeek.

Common Pitfalls

Switching too aggressively

Don't switch providers for single-turn questions. The overhead of loading a new model context is not worth it for one-off queries. Switch at phase boundaries — when the task type fundamentally changes.

Using expensive models for volume tasks

DeepSeek generates code at 1/55th the cost of Claude Sonnet. If you're generating 4,000 tokens of test code, the quality improvement of using Claude is negligible. Save Claude for the 200 tokens of architecture decisions.

Ignoring free tiers

Gemini's free tier is generous. If your usage is within limits, route all Gemini-capable tasks through Google and save the API keys for other providers. GLM also has a free tier that covers moderate usage.

Not setting default provider

Without a default, every new session starts with the last-used provider. Set "default": "deepseek" in opencode.json. You're not going to overpay for "what does this error mean" queries.

Advanced: Same Model, Different Provider

DeepSeek models are available through their own API. They're also available through OpenRouter and Groq. The behavior can differ:

Providerdeepseek-chat BehaviorLatency
DeepSeekOriginal behavior, rate limit sensitive~3s
OpenRouterMay include system prompt injection~4s
GroqFastest inference, limited context~0.5s

When you need DeepSeek speed: use Groq. When you need DeepSeek accuracy: use their own API. OpenCode supports both — just add multiple providers pointing to the same model through different gateways.

Troubleshooting

Provider returns rate limit errors

DeepSeek rate limits are aggressive during peak hours (Beijing daytime). Switch to GLM or Gemini as backup. If you hit Anthropic rate limits, use DeepSeek R1 for reasoning tasks — it's not as good but costs 1/27th.

Model not available

Providers deprecate models constantly. Check opencode provider list for current models. The gemini-2.5-pro ID changes with updates — verify the exact model string before scripting.

Context window exceeded

If a session gets too long, the switch-to-Gemini trick helps: Gemini's 1M context can absorb the accumulated session history where other providers truncate. Switch to Gemini for the summary generation, then start a new session with the summary as context.