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:
In your OpenCode configuration, add a top-level provider entry (not a providers array):
json
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:
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"andcode: null— the gateway received the header but rejected the key. Check thatTOYGATE_API_KEYis exported, begins withgw_, 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. Checkcurl <GatewayUrl/>/v1/catalog | jq '.data[].id', then update themodelsobject and-mvalue.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