For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
OpenCode
Configure the OpenCode AI coding agent to use agentgateway running in Kubernetes
Route LLM requests from OpenCode through agentgateway in Kubernetes. In this guide, OpenCode uses a virtual key, and the provider API key stays in a Kubernetes Secret.
Before you begin
- Set up an agentgateway proxy.
- Set up access to the OpenAI LLM provider. Use the OpenAI v1/chat/completions tab to create a route that allows requests to
/v1/chat/completions. - Require virtual key authentication for the Gateway. This guide uses the
vk-alice-4f9c2aexample key. Token budgets are optional. - Install OpenCode. This guide was tested with OpenCode 1.18.35.
Set the gateway URL and virtual key
Set the base URL with the required
/v1suffix. UseINGRESS_GW_ADDRESSfrom the installation quickstart, orhttp://localhost:8080/v1for port-forwarding.export AGENTGATEWAY_BASE_URL="http://${INGRESS_GW_ADDRESS}/v1"Save the virtual key in an environment variable.
export AGENTGATEWAY_API_KEY='vk-alice-4f9c2a'
Note
For a TLS-enabled Gateway, set AGENTGATEWAY_BASE_URL to its HTTPS URL ending in /v1.
Connect OpenCode to agentgateway
Create
opencode.jsonin your project directory. For settings that apply to all projects, use~/.config/opencode/opencode.json.cat > opencode.json <<'EOF' { "$schema": "https://opencode.ai/config.json", "model": "agentgateway/gpt-4o-mini", "provider": { "agentgateway": { "npm": "@ai-sdk/openai-compatible", "name": "Agentgateway", "options": { "baseURL": "{env:AGENTGATEWAY_BASE_URL}", "apiKey": "{env:AGENTGATEWAY_API_KEY}" }, "models": { "gpt-4o-mini": { "name": "gpt-4o-mini" } } } } } EOFSetting Description modelThe default model, in <provider>/<model>format.provider.agentgateway.npmThe AI SDK package for an OpenAI-compatible API. options.baseURLReads the Gateway base URL from AGENTGATEWAY_BASE_URL.options.apiKeyReads the virtual key from AGENTGATEWAY_API_KEYto keep it out of the file. You can also enter the key with OpenCode’s/connectcommand.modelsThe models that OpenCode can request. List only models that the Gateway allows. Start OpenCode from the same directory.
opencode
Verify the connection
Send a prompt in OpenCode, or run a single prompt from the command line:
opencode run "Say hello"Verify that the request appears in the agentgateway proxy logs.
kubectl logs deployment/agentgateway-proxy -n agentgateway-system --since=5m \ | grep 'http.path=/v1/chat/completions' \ | tail -n 5A successful entry has
http.status=200andhttp.path=/v1/chat/completions.
If the virtual key is missing, unknown, or revoked, OpenCode shows the 401 response from the proxy.
Error: Unauthorized: api key authentication failure: invalid credentials