Coder powers secure, scalable development across key industries — automotive, finance, government, and technology — enabling faster builds, tighter compliance, and seamless AI adoption in enterprise-grade cloud environments.
AI Gateway is part of AI Governance, which is
included with a Premium license.
OpenCode supports both OpenAI and Anthropic models and can be configured to use AI Gateway by setting custom base URLs for each provider.
Centralized API Key
You can configure OpenCode to connect to AI Gateway by setting the following configuration options in your OpenCode configuration file (e.g., ~/.config/opencode/opencode.json):
Select anthropic (and repeat for openai if needed), then paste the corresponding API key you obtained earlier when prompted.
Custom models through Bedrock Mantle
You can use OpenCode with custom model IDs through a Bedrock Mantle provider configured by your Coder administrator.
AI Gateway signs requests with AWS credentials centrally, so you only need a Coder API token in OpenCode.
Use a custom provider in OpenCode that matches your model's API, rather than its native Amazon Bedrock integration.
The following example uses Astra with the Responses API.
For other models, choose the SDK package that matches the API:
Model API
OpenCode npm package
Responses
@ai-sdk/openai
Chat Completions
@ai-sdk/openai-compatible
Anthropic Messages
@ai-sdk/anthropic
In a shell where you're logged in with the Coder CLI, set your token:
export CODER_TOKEN="$(coder login token)"
This command sets CODER_TOKEN without printing the token.
Merge the following configuration into ~/.config/opencode/opencode.json:
Replace coder.example.com with your AI Gateway host and bedrock-provider-name with the provider name configured in Coder.
Keep the /v1 suffix.
Replace openai.gpt-6-astra with the exact Mantle model ID available in your AWS account and region.
Set npm to the SDK package for that model's API.
Set tool_call to true only if the model supports tools.
The astra key is a local model alias in OpenCode.
The id field is the model ID sent upstream.
Preserve any vendor prefix in the model ID, such as openai. or anthropic..
You can add more entries under models to use model IDs outside OpenCode's built-in catalog.
The optional model and small_model fields select the default model and the model for lightweight tasks, such as title generation.
This example uses Astra for both, so both types of request use the same gateway provider.
To use a different small model, add its entry under models and update small_model to coder-mantle/<model-alias>.
Start OpenCode from the same shell:
opencode
OpenCode uses the configured Astra model through AI Gateway.
All three SDK packages use the same gateway base URL ending in /v1.
The selected SDK sends requests to /v1/responses, /v1/chat/completions, or /v1/messages.
Use a model that supports the selected API.
For more configuration options, refer to OpenCode custom providers.