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.
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=...
Recommended models per provider
| Provider | Model | Best For | Approx. Cost (per 1M tokens) |
|---|---|---|---|
| Gemini | gemini-2.5-pro | Large codebase analysis | Free tier (rate-limited) / ~$3.50 input paid API |
| GLM | glm-4-plus | Bilingual tasks (ZH/EN) | ~$2.00 |
| DeepSeek | deepseek-chat (V3) | Bulk generation, boilerplate | ~$0.27 |
| DeepSeek | deepseek-reasoner (R1) | Complex multi-step reasoning | ~$0.55 |
| MiniMax | abab-6.5s | Creative writing, copy | ~$1.00 |
| Anthropic | claude-sonnet-4-20250514 | Architecture, 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 Phase | Use | Why |
|---|---|---|
| Architecture/Design | Claude | Best reasoning, worth the cost |
| Requirements Analysis | Gemini | Large context, nuanced understanding |
| Code Generation | DeepSeek | Cheap, fast, code quality is fine |
| Test Generation | DeepSeek | High volume, low reasoning requirement |
| Code Review | Claude | Need to catch subtle issues |
| Documentation | DeepSeek/MiniMax | Volume task, creative tone |
| Large Codebase Scan | Gemini | 1M context, document analysis |
| Bilingual Tasks | GLM | Native language understanding |
| Copy/Marketing | MiniMax | Creative output, tone variation |
Cost Comparison: Real Session
A session building a new API endpoint with tests and documentation:
| Phase | Provider | Tokens (in/out) | Cost |
|---|---|---|---|
| Architecture | Claude | 2,000 / 1,500 | $0.029 |
| Implementation | DeepSeek | 3,000 / 4,000 | $0.002 |
| Test generation | DeepSeek | 2,000 / 6,000 | $0.002 |
| Code review | Claude | 5,000 / 1,000 | $0.030 |
| Documentation | MiniMax | 1,000 / 2,000 | $0.003 |
| Total | 5 providers | 27,500 | $0.066 |
| All-Claude equivalent | 1 provider | 27,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:
| Provider | deepseek-chat Behavior | Latency |
|---|---|---|
| DeepSeek | Original behavior, rate limit sensitive | ~3s |
| OpenRouter | May include system prompt injection | ~4s |
| Groq | Fastest 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.
Related Content
- OpenCode Patterns — OpenCode ↔ Hermes iterative cleanup loop
- Claude Code Cost Optimization — Hooks + DeepSeek for 95% cheaper bulk generation
- Gemini CLI Antigravity Pipeline — CLI-first coding with Antigravity image generation
- OpenCode Getting Started — Installation and first session
Related Articles
Antigravity CLI — Patterns
Reusable patterns for Antigravity CLI. Multi-agent workflows, async tasks, hooks, model routing, cross-model review, and CI/CD integration.
Gemini CLI — Getting Started (Enterprise)
Enterprise installation and setup for Gemini CLI via Vertex AI. Product is deprecated for public use — replaced by Google Antigravity. Covers enterprise auth, sandbox modes, and first session.
Claude Code — AI Coding Agent
Complete guide to Claude Code, Anthropic's terminal-based AI coding agent. Covers installation, prompt engineering, configuration, CLAUDE.md patterns, and best practices.