OpenCode
Connect OpenCode to OpenGateway with an OpenAI-compatible custom provider, browse available models, and run requests through the CLI without changing your current default.
opengateway-opencode skill.Set it up by hand#
1. Get an API key#
OpenGateway → API Keys → Create Key. Export the key in your shell (~/.zshrc or ~/.bashrc if you want it available in new terminals):
export OPENGATEWAY_API_KEY="YOUR_OPENGATEWAY_API_KEY"
2. Add the provider#
Merge this provider into ~/.config/opencode/opencode.json for all projects, or the opencode.json at a project root for that project only. Keep any existing config, including top-level default model settings.
{"$schema": "https://opencode.ai/config.json","provider": {"opengateway": {"npm": "@ai-sdk/openai-compatible","name": "OpenGateway","options": {"baseURL": "https://apis.opengateway.ai/v1","apiKey": "{env:OPENGATEWAY_API_KEY}"},"models": {"deepseek/deepseek-v4.1-flash-ultrafast": {"name": "DeepSeek V4.1 Flash UltraFast","limit": { "context": 1000000 }},"z-ai/glm-5.3-flash-ultrafast": {"name": "GLM 5.3 Flash UltraFast","limit": { "context": 1000000, "output": 131072 }}}}}}
baseURL ends in /v1 because this OpenAI-compatible provider uses Chat Completions. Keep the API key in the environment and use OpenCode's {env:NAME} syntax; do not put the key itself in a file that may be committed. Both models have a 1,000,000-token context window. limit.output is model metadata for OpenCode; it is set only for GLM here, whose configured maximum output is 131,072 tokens. The public model catalog does not publish a maximum output for DeepSeek, so the example does not guess one.
To let OpenCode store the credential instead, run opencode auth login --provider opengateway or use /connect in the TUI and choose Other. Then omit options.apiKey from the provider config.
3. Select and verify#
OpenCode's TUI lists configured models under /models. Or send one prompt from the command line:
opencode run -m opengateway/deepseek/deepseek-v4.1-flash-ultrafast "Reply with OK"
The model reference is the provider ID followed by the model ID, so the repeated slash is expected. A response confirms the request worked. To make this the default for OpenCode, set the top-level model key to opengateway/deepseek/deepseek-v4.1-flash-ultrafast; leaving that key unchanged preserves your current default.
Models#
The example includes the recommended UltraFast model, deepseek/deepseek-v4.1-flash-ultrafast, and the lower-priced alternative, z-ai/glm-5.3-flash-ultrafast. To add another model, check the public model catalog for an active model whose endpoints include chat_completions. Use its exact ID and context_window for the model entry and set limit.output only when its maximum output is confirmed. Current pricing is on /models.
UltraFast has a per-key, per-model concurrency cap. Exceeding it returns 429 with code concurrency_limit_exceeded and a Retry-After header; reduce in-flight requests or contact support to request a higher limit. For deepseek/deepseek-v4.1-flash-ultrafast and z-ai/glm-5.3-flash-ultrafast, a request with more than 256K total input tokens has double the input price for the whole request; cache reads and output tokens are not surcharged. See UltraFast for details.
Troubleshooting#
- 401 Unauthorized: Check that
OPENGATEWAY_API_KEYis exported in the shell that starts OpenCode and that theapiKeyvalue is exactly{env:OPENGATEWAY_API_KEY}. For credentials stored by OpenCode, checkopencode auth list. - Model not found or missing from
/models: Check theopengatewayprovider ID, exact model ID, and that the selected catalog entry is active and supportschat_completions. Restart OpenCode after editing the config. - 429 concurrency limit: Wait for
Retry-Afterand lower concurrent requests to the same UltraFast model, or contact support to request a higher per-key limit. - Context or output budget looks wrong: Check the
limit.contextandlimit.outputvalues in the provider model entry. OpenCode uses these limits to track the configured model's token budget.
For the current configuration format, see the official OpenCode config and provider documentation.