OpenCode

Route OpenCode through ToyGate as an OpenAI-compatible custom provider.

Integrations

OpenCode can use ToyGate's current OpenAI Chat Completions endpoint through the official @ai-sdk/openai-compatible provider package.

Config

Set the gateway key before starting OpenCode:

export TOYGATE_API_KEY="gw_..."

In your OpenCode configuration, add a top-level provider entry (not a providers array):

json
{"$schema": "https://opencode.ai/config.json","provider": {  "toygate": {    "npm": "@ai-sdk/openai-compatible",    "name": "ToyGate",    "options": {      "baseURL": "https://api.toygate.store/v1",      "apiKey": "{env:TOYGATE_API_KEY}"    },    "models": {      "gpt-5.5": {        "name": "GPT-5.5"      },      "claude-opus-4-8": {        "name": "Claude Opus 4.8"      }    }  }}}

The models object lists the gateway slugs you want OpenCode to offer. Use enabled slugs from the catalog, not upstream model IDs.

Verify

Run a non-interactive request with the provider/model selector:

opencode run -m toygate/gpt-5.5 'Say hi'

Expected: OpenCode prints the assistant reply through ToyGate. Use -m toygate/<model> to choose another configured model; do not use --provider.

Troubleshooting

  • HTTP 401 with type: "authentication_error" and code: null — the gateway received the header but rejected the key. Check that TOYGATE_API_KEY is exported, begins with gw_, and exists in the client portal or admin panel without being revoked. Restart OpenCode after changing the environment variable.
  • 404 model_not_found — the selected gateway slug is missing from the catalog or disabled. Check curl <GatewayUrl/>/v1/catalog | jq '.data[].id', then update the models object and -m value.
  • upstream_model_unavailable — the catalog row points at an upstream model ID the provider no longer recognizes. Operator concern.

Gateway URL: https://api.toygate.store