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) — export the key, or run /connect and paste it
export ANTHROPIC_API_KEY=sk-ant-...
# Google (best context length)
export GOOGLE_API_KEY=...
# DeepSeek (best cost)
export DEEPSEEK_API_KEY=sk-...
# GLM (bilingual)
export GLM_API_KEY=...
# MiniMax (creative)
export MINIMAX_API_KEY=...
OpenCode auto-detects providers from these environment variables. You can also add them interactively in the TUI with /connect — select the provider and follow the auth flow.
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.
> /models
> Select anthropic/claude-sonnet-4-5
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.
> /models
> Select google/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.
> /models
> Select deepseek/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.
> /models
> Select glm/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.
> /models
> Select minimax/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)
> /models
> Select anthropic/claude-sonnet-4-5
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)
> /models
> Select deepseek/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)
> /models
> Select anthropic/claude-sonnet-4-5
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 default model
Set your default model so every new session starts there instead of the last-used one:
{
"$schema": "https://opencode.ai/config.json",
"model": "deepseek/deepseek-chat"
}
There's no per-task provider map in the config — switch mid-session with /models as needed. Encode the routing strategy in AGENTS.md (below) so the agent applies it automatically.
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 a default model
Without a default, OpenCode falls back to the last-used model or an internal default. Set "model": "deepseek/deepseek-chat" in opencode.json so quick "what does this error mean" queries don't default to an expensive model.
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 models for the current model IDs. 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 & Guides
Building a Token Usage Tracker Plugin for OpenCode
Step-by-step guide to building an OpenCode plugin that tracks token usage per provider, reports session stats, and learns quota limits from rate-limit errors.
Claude Code Cost Optimization
Cut Claude Code costs by 70-95% using shell scripts, provider switching, and task routing. When to use extended thinking vs cheap execution.
CLI-First Antigravity Image Pipeline
Build sites with fast CLI tools, generate images in Antigravity with Nano Banana, and compress to WebP with cwebp. All under one Google AI Pro plan.