OpenCode
Use Foza models with the OpenCode terminal coding agent
Before you start#
OpenCode can connect to OpenAI-compatible providers through its provider config. For Foza, you need:
- A Foza API key from Console -> API Keys
- That key subscribed to at least one coding-capable model
- OpenCode installed locally
- A project folder where OpenCode can read and edit files
Recommended first models:
anthropic/claude-sonnet-4.6for coding-agent workopenai/gpt-4ofor general chat and code edits
Recommended: Console setup#
Use the setup generator from your API key page. This is the safest path because it uses the exact key, connected models, and operating system-specific config paths.
Open your API key
Go to Console -> API Keys, open the key you want to use, and make sure the key is Active.
Open the OpenCode tab
In the key detail page, select the OpenCode tab.
Choose operating system
Select macOS / Linux or Windows. The generated command will use the correct config path for that OS.
Choose models
Assign the model or models you want OpenCode to use. The dropdowns only show models linked to this API key.
Create setup command
Click Create setup command, copy the generated command, and run it in your terminal. It writes the Foza provider config, base URL, API key reference, and selected model slugs.
The key detail page can also create a remove command. Use it when you want to remove only the Foza OpenCode configuration without uninstalling OpenCode.
Manual setup#
Install OpenCode
Install OpenCode using the installer from the OpenCode docs, then verify it is available:
opencode --versionCreate an OpenCode config file
Create opencode.json in your project root for a project-specific setup, or ~/.config/opencode/opencode.json for a global default.
Add Foza as an OpenAI-compatible provider
{ "$schema": "https://opencode.ai/config.json", "provider": { "foza": { "npm": "@ai-sdk/openai-compatible", "name": "Foza", "options": { "baseURL": "https://api.foza.ai/v1", "apiKey": "{env:FOZA_API_KEY}" }, "models": { "anthropic/claude-sonnet-4.6": { "name": "Claude Sonnet 4.6" }, "openai/gpt-4o": { "name": "GPT-4o" } } } }, "model": "foza/anthropic/claude-sonnet-4.6" }
Set your Foza key
export FOZA_API_KEY=sk-foza-xxxxxAdd the export to ~/.zshrc, ~/.bashrc, or your shell profile if you want it to persist.
Start OpenCode
cd /path/to/your/project opencode
Inside OpenCode, use /models to switch between the Foza models listed in opencode.json.
Quick test prompt#
Start with a low-risk request:
Read this project and summarize the main entry points. Do not edit files yet.If that works, try a small edit:
Add a short comment explaining the validation logic in the smallest relevant file.Troubleshooting#
| Symptom | What to check |
|---|---|
| Provider does not show up | The provider ID is foza, and the config file is valid JSON |
| Authentication fails | echo $FOZA_API_KEY returns the key in the same shell where you run opencode |
| Model not found | The model key in models matches the Foza model slug exactly |
| Requests reach the wrong host | baseURL is exactly https://api.foza.ai/v1, not /v1/chat/completions |
Keep project-specific OpenCode configs in the repository when teams should share the same model list, but keep API keys in environment variables.