Skip to main content
OpenCode is an open-source terminal coding agent. It reaches the AI Gateway as a custom OpenAI-compatible provider, so one access key covers every model you add to its config.

What you’ll need

Add the gateway as a provider

Export your access key so OpenCode can read it:
Add the gateway as a provider in ~/.config/opencode/opencode.json, or in an opencode.json beside your project:
Each key in models is the model name OpenCode sends to the gateway. Use any model ID from the model catalog, or provider:model to pin a provider. The limit values are optional, but they let OpenCode track how much context is left.

Test the connection

Start OpenCode, run /models, and pick one of the models under ngrok AI Gateway. Or send a single prompt from the command line:
The -m value is your provider ID, a slash, then the model key from opencode.json. Confirm the request in AI Gateway observability in app.ngrok.ai.

Use a model you run yourself

To reach a model on your own machine, register it as a custom provider, then add its provider:model name to models, such as ollama:llama3.2. See Use a model you run yourself for the full setup.

Next steps