⚠️ Pending Update · 2026-08-29 Verification · Content may be outdated, please refer to official docs Updated: 2026-08-29 · Status: Pending Verification
Introduction
OpenCode itself is free — your only cost is the model API. The good news is that OpenRouter, Groq, and Together AI all expose free-tier models over an OpenAI-compatible protocol. This article gives you three ready-to-use configurations and compares their real-world behavior on coding tasks.
架构图
Prerequisites
Make sure OpenCode is installed (see us-01) and grab these keys:
OPENROUTER_API_KEYfrom https://openrouter.ai/keysGROQ_API_KEYfrom https://console.groq.com/keysTOGETHER_API_KEYfrom https://api.together.ai/settings/api-keys
Manage all of them via environment variables — never hardcode them into config files.
Config File
Write the following to opencode.json in your project root:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openrouter": {
"options": { "baseURL": "https://openrouter.ai/api/v1" },
"models": {
"meta-llama/llama-3.3-70b-instruct:free": { "name": "Llama 3.3 70B (free)" }
}
},
"groq": {
"options": { "baseURL": "https://api.groq.com/openai/v1" },
"models": {
"llama-3.3-70b-versatile": { "name": "Llama 3.3 70B Groq" },
"llama-3.1-8b-instant": { "name": "Llama 3.1 8B Instant" }
}
},
"together": {
"options": { "baseURL": "https://api.together.xyz/v1" },
"models": {
"meta-llama/Llama-3.3-70B-Instruct-Turbo": { "name": "Llama 3.3 70B Together" }
}
}
},
"model": "groq/llama-3.3-70b-versatile"
}
Inject Keys
export OPENROUTER_API_KEY="sk-or-v1-..."
export GROQ_API_KEY="gsk_..."
export TOGETHER_API_KEY="..."
OpenCode matches each provider to an environment variable of the same name, so you never hardcode keys in the config.
Launch and Switch
opencode
Inside the TUI, press Ctrl+M to switch between configured models. Use Groq's llama-3.3-70b-versatile for fast everyday coding (first-token latency often under 300ms), fall back to OpenRouter's :free Llama for heavier reasoning, and pick llama-3.1-8b-instant for the cheapest code completion.
Free-tier Comparison
| Provider | Strength | Weakness | Best for |
|---|---|---|---|
| Groq | Blazing fast | 128K context, strict TPM | Real-time chat, completion |
| OpenRouter :free | Many models | Heavy queuing | Complex reasoning |
| Together | Stable | Few fully free models | Mid-complexity tasks |
Model Selection Tips
In practice, free models differ noticeably by task: for code completion use Groq's llama-3.1-8b-instant (low latency, large free quota); for complex refactors or algorithms pick OpenRouter's llama-3.3-70b-instruct:free (70B params, stronger reasoning); for Chinese prose use Qwen on Together. Configure all of them and switch on demand.
Troubleshooting
429 Too Many Requests: Free tiers have RPM caps. Wait 30 seconds or switch providers — configuring all three lets youCtrl+Mto the next on failure.- Garbled non-English output: Set
export LANG=en_US.UTF-8, or appendAlways respond in Simplified Chineseto the prompt. - OpenRouter
:freereturns 403: Verify your account has a credit card on file — OpenRouter requires verification even for free models and will not charge you. context length exceededon 8B models: Switch to a 70B model or split the file into chunks.
You now have a fully free terminal AI coding environment.
Pitfalls and Best Practices
- Multi-provider switching needs /model command: OpenCode does not auto-fallback; when one provider hits 429 you must manually switch to the backup.
- Keep token context small: most free models have 8K-32K context; chunk long files before sending.
- Never commit API keys: use the
apiKey: "${ENV_VAR}"reference syntax; pre-commit hooks alone are not enough. - Prefer Groq over OpenRouter for speed: Groq is consistently faster for daily coding; reserve OpenRouter
:freeas the degraded fallback.
🚀 Get Started: One-Click Free API Access
Want to call all the free models above with a single API key, no need to sign up for each provider? Apishare.cc provides a unified API Key — one key, 100+ models, free models at zero cost.
👉 Register on Apishare.cc → Get your unified API Key
📊 Want to see more free model rankings? Check out the Sep 2026 Free LLM API Rankings →
Get Started: APIShare Free API Directory
- 🆓 Claim your free credits:Register on APIShare · Sign in to console
- 🔍 Browse every free API and live ranking:APIShare Free API Directory
- 📊 See the leaderboard:Free LLM API Rankings
About the Free API Aggregator
The models covered in this guide are all served through the APIShare free API aggregator, which gives you one key for the whole catalog.
- Full model catalog: APIShare free API directory
- Sign up for a free trial key: Register and claim your API key