Skip to navigation

OpenCode (gateway)

Route OpenCode’s LLM calls through the Respan gateway for automatic logging, caching, and model switching. Only your RESPAN_API_KEY is needed.

Setup

1

Install OpenCode

npm install -g opencode-ai
2

Set environment variables

Add to your shell profile (.bashrc, .zshrc, or PowerShell $PROFILE):

export OPENAI_BASE_URL="https://api.respan.ai/api/"
export OPENAI_API_KEY="YOUR_RESPAN_API_KEY"

No separate OpenAI API key needed. The Respan gateway handles provider authentication.

3

Run OpenCode

opencode run -m "openai/gpt-5.5" "your prompt"

All LLM calls now route through Respan.

Switch models

Change the -m flag to use 1000+ models from different providers through the same gateway.

opencode run -m "openai/gpt-5.5" "your prompt"
opencode run -m "openai/gpt-5-mini" "your prompt"

OpenCode validates model IDs against its own catalog for the built-in openai provider, so only OpenAI model names work behind the openai/ prefix. For Claude, Gemini, and other providers, add Respan as a custom provider as shown below.

See the full model list.

Use any gateway model with a custom provider

Add a respan provider to ~/.config/opencode/opencode.json (or opencode.json in your project). Any model ID the gateway exposes can be listed here:

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"respan": {
"npm": "@ai-sdk/openai-compatible",
"name": "Respan Gateway",
"options": {
"baseURL": "https://api.respan.ai/api",
"apiKey": "{env:RESPAN_API_KEY}"
},
"models": {
"gpt-4o": { "name": "GPT-4o" },
"claude-sonnet-4-5-20250929": { "name": "Claude Sonnet 4.5" },
"gemini/gemini-3.5-flash": { "name": "Gemini 3.5 Flash" }
}
}
}
}

Export the key and run with the respan/ prefix:

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
opencode run -m "respan/claude-sonnet-4-5-20250929" "your prompt"
opencode run -m "respan/gemini/gemini-3.5-flash" "your prompt"