OpenCode Integration
OpenCode Integration
OpenCode is an AI-powered CLI coding agent. It uses a JSON configuration file to define providers and models.
Configuration File
OpenCode reads from opencode.json in your project root or home directory.
Configuring Providers
All Providers in One Config
{ "providers": { "anthropic": { "apiKey": "${ANTHROPIC_API_KEY}", "models": { "claude-sonnet-4-20250514": { "maxTokens": 8192 } } }, "openai": { "apiKey": "${OPENAI_API_KEY}", "models": { "gpt-4o": { "maxTokens": 4096 } } }, "google": { "apiKey": "${GEMINI_API_KEY}", "models": { "gemini-2.0-flash": { "maxTokens": 8192 } } }, "deepseek": { "apiKey": "${DEEPSEEK_API_KEY}", "models": { "deepseek-coder": { "maxTokens": 4096 } } }, "groq": { "apiKey": "${GROQ_API_KEY}", "models": { "llama-3.3-70b-versatile": { "maxTokens": 8192 } } } }}Single Provider Examples
Anthropic Claude:
{ "providers": { "anthropic": { "apiKey": "${ANTHROPIC_API_KEY}", "models": { "claude-sonnet-4-20250514": { "maxTokens": 8192 }, "claude-3-haiku-20240307": { "maxTokens": 4096 } } } }}OpenAI GPT:
{ "providers": { "openai": { "apiKey": "${OPENAI_API_KEY}", "models": { "gpt-4o": { "maxTokens": 4096 }, "gpt-4o-mini": { "maxTokens": 4096 } } } }}Google Gemini:
{ "providers": { "google": { "apiKey": "${GEMINI_API_KEY}", "models": { "gemini-2.5-pro-preview-0520": { "maxTokens": 8192 }, "gemini-2.0-flash": { "maxTokens": 8192 } } } }}DeepSeek:
{ "providers": { "deepseek": { "apiKey": "${DEEPSEEK_API_KEY}", "models": { "deepseek-chat": { "maxTokens": 4096 }, "deepseek-coder": { "maxTokens": 4096 } } } }}Groq:
{ "providers": { "groq": { "apiKey": "${GROQ_API_KEY}", "models": { "llama-3.3-70b-versatile": { "maxTokens": 8192 }, "mixtral-8x7b-32768": { "maxTokens": 4096 } } } }}Environment Variables
Set the API keys for whichever providers you use:
export ANTHROPIC_API_KEY="your-anthropic-key"export OPENAI_API_KEY="your-openai-key"export GEMINI_API_KEY="your-gemini-key"export DEEPSEEK_API_KEY="your-deepseek-key"export GROQ_API_KEY="your-groq-key"Add to your shell profile to persist across sessions:
echo 'export ANTHROPIC_API_KEY="your-key"' >> ~/.bashrcsource ~/.bashrcVerification
-
Confirm your config file is valid JSON:
Terminal window cat opencode.json | python3 -m json.tool -
Run OpenCode and check available models:
Terminal window opencode -
Test with a simple prompt to confirm the provider responds correctly.
Troubleshooting
- Invalid API key error: Verify the environment variable is set with
echo $ANTHROPIC_API_KEY - Model not found: Check the model name matches exactly what the provider expects
- Rate limit errors: Switch to a different provider or wait for the limit to reset