Integration guide
OpenCode
OpenCode loads providers from opencode.json. Register Relay through @ai-sdk/openai-compatible and pick a relay/ model — billing stays per token on your Relay balance.
Setup
- 1
Create a Relay API key in the console.
- 2
Save the provider block to ~/.config/opencode/opencode.json (or a project-level opencode.json) — it registers relay on the OpenAI-compatible endpoint.
- 3
Replace YOUR_MODEL_ID with a catalog model, then launch opencode and select relay/YOUR_MODEL_ID.
Configuration
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"relay": {
"npm": "@ai-sdk/openai-compatible",
"name": "Relay",
"options": {
"baseURL": "https://proxystacks.com/v1",
"apiKey": "sk-relay-your-key"
},
"models": {
"kimi-k3.1-pro": {
"name": "kimi-k3.1-pro"
}
}
}
},
"model": "relay/kimi-k3.1-pro"
}Save to ~/.config/opencode/opencode.json (or a project-level opencode.json), then pick model relay/YOUR_MODEL_ID.
Advanced config: environment variable API key, multi-model providers & max output tokens
Use a project-specific config file with environment variable interpolation, multiple custom API models (DeepSeek V4.1 Flash, GLM-5.3 Flash, Kimi K3.1 Pro), and explicit context/output token limits.
{
// Project-specific ./opencode.jsonc or global ~/.config/opencode/opencode.jsonc
"$schema": "https://opencode.ai/config.json",
"provider": {
"relay": {
"npm": "@ai-sdk/openai-compatible",
"name": "ProxyStacks Relay",
"options": {
"baseURL": "https://proxystacks.com/v1",
"apiKey": "{env:RELAY_API_KEY}"
},
"models": {
"deepseek-v4.1-flash": {
"name": "DeepSeek V4.1 Flash",
"limit": { "context": 1000000, "output": 64000 }
},
"glm-5.3-flash": {
"name": "GLM-5.3 Flash",
"limit": { "context": 1000000, "output": 32000 }
},
"kimi-k3.1-pro": {
"name": "Kimi K3.1 Pro",
"limit": { "context": 1000000, "output": 32000 }
}
}
}
},
"model": "relay/deepseek-v4.1-flash",
"small_model": "relay/glm-5.3-flash"
}Troubleshooting
- 401: check the Relay key and authentication header. Never paste a secret into a support ticket.
- 404: use an exact published model ID and the documented base URL, not an upstream alias.
- For streaming use stream: true. Codex uses Responses; keep disable_response_storage = true.
Common questions
Where is the OpenCode config file (opencode.json / opencode.jsonc) for CLI, Desktop, and project-specific setups?
Both the OpenCode CLI and OpenCode Desktop app load the global config from ~/.config/opencode/opencode.json (or ~/.config/opencode/opencode.jsonc with comments; %USERPROFILE%\.config\opencode\opencode.json on Windows). For a project-specific config, place opencode.json or opencode.jsonc in your repository root.
How do I set an API key in OpenCode (opencode set api key) using environment variables?
Export RELAY_API_KEY in your shell environment and set "apiKey": "{env:RELAY_API_KEY}" inside provider.relay.options in opencode.json or opencode.jsonc. This keeps secrets out of version control.
How do I add custom API providers and configure max output tokens in opencode.jsonc?
Register @ai-sdk/openai-compatible under provider.relay with baseURL "https://proxystacks.com/v1", list each model ID (deepseek-v4.1-flash, glm-5.3-flash, kimi-k3.1-pro) under models, and set a per-model limit (for example output 64000 for DeepSeek V4.1 Flash, 32000 for GLM-5.3 Flash / Kimi K3.1 Pro) to control context window and max output tokens.
Can OpenCode run with a single gateway endpoint for airgapped networks or custom subagent rules?
Yes. Routing all models through https://proxystacks.com/v1 requires allowlisting only one HTTPS endpoint and one API key, while project-specific opencode.jsonc settings let you control small_model routing, subagent behavior, and model invocation.
How do I point OpenCode (including the Zen provider) at ProxyStacks Relay's base URL?
OpenCode Zen is a built-in provider; you do not need to change its base URL to use Relay. Add a custom provider.relay block with npm "@ai-sdk/openai-compatible", options.baseURL "https://proxystacks.com/v1", and options.apiKey "{env:RELAY_API_KEY}", then select relay/deepseek-v4.1-flash (or another published model). The same options.baseURL override also works when proxying an existing provider.
How do I set thinking budget or reasoning effort in opencode.json?
OpenCode has no single global thinking_budget key; reasoning effort is configured per model or per agent. Set it in the model or agent options block (for example options: { reasoningEffort: "low" }) only when the upstream API accepts that parameter, and validate against the current schema at https://opencode.ai/config.json. Relay passes supported parameters through; remove the option if the upstream model rejects it.
How do I limit subagent depth or disable model invocation in OpenCode?
In OpenCode v2, experimental.subagent_depth controls nesting: 0 blocks subagents, 1 is the default (subagents cannot spawn further subagents), and 2 allows one more level. disable-model-invocation is a Claude Code command/skill frontmatter option, not an OpenCode config key; in OpenCode, restrict delegation with per-agent permissions or tool settings instead.