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.6 for coding-agent work
  • openai/gpt-4o for general chat and code edits

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.

1

Open your API key

Go to Console -> API Keys, open the key you want to use, and make sure the key is Active.

2

Open the OpenCode tab

In the key detail page, select the OpenCode tab.

3

Choose operating system

Select macOS / Linux or Windows. The generated command will use the correct config path for that OS.

4

Choose models

Assign the model or models you want OpenCode to use. The dropdowns only show models linked to this API key.

5

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#

1

Install OpenCode

Install OpenCode using the installer from the OpenCode docs, then verify it is available:

opencode --version
2

Create 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.

3

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"
}
4

Set your Foza key

export FOZA_API_KEY=sk-foza-xxxxx

Add the export to ~/.zshrc, ~/.bashrc, or your shell profile if you want it to persist.

5

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#

SymptomWhat to check
Provider does not show upThe provider ID is foza, and the config file is valid JSON
Authentication failsecho $FOZA_API_KEY returns the key in the same shell where you run opencode
Model not foundThe model key in models matches the Foza model slug exactly
Requests reach the wrong hostbaseURL 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.