OpenCode
Connect OpenCode to Gateway through its built-in Merge Gateway provider
OpenCode lists Merge Gateway in its model registry, so connecting to Gateway’s /v1/ai-sdk endpoint takes one command and no config file. Shared setup: Building with coding agents.
Connect OpenCode
Export your key, run opencode in your project, then /connect and select Merge Gateway. Paste the key when prompted, or skip if MERGE_GATEWAY_API_KEY is set. Pick a model with /models and ask for a small code change. OpenCode’s session header groups each session into one thread in Logs.
Curate models in opencode.json
The registry’s model list is a snapshot that can lag the model catalog. To rename models or add unlisted ones and aliases, add a merge-gateway block to opencode.json in your project root or ~/.config/opencode/opencode.json. Skip npm, name, and the key, which the registry and your export supply.
To override the host, set options.baseURL to a URL ending in /v1/ai-sdk.
Fix “Failed to initialize provider: merge-gateway”
On the first message, OpenCode downloads merge-gateway-ai-sdk-provider from npm and caches it in ~/.cache/opencode/packages. This error means the download failed before any request reached Gateway, so a new API key won’t help. Usual causes are a proxy or VPN, a private npm registry that hasn’t approved the package, or a firewall blocking registry.npmjs.org.
Seed the cache from your terminal, which has your proxy and registry settings:
If that fails, its error names the blocker: check npm config list for unexpected registry, proxy, or https-proxy values, and make sure a private registry allows the package and its dependencies. Then delete ~/.cache/opencode/packages and retry.
If you can’t change npm, use OpenCode’s built-in OpenAI-compatible provider. It downloads nothing, but you list models yourself and lose Gateway-specific response detail such as cache token breakdowns.