Skip to main content

OpenCode

One anyray-connect command points OpenCode's providers at the gateway, including a ChatGPT Pro or Plus sign-in.

Connect​

1
Enroll, then connect
npx anyray-connect@latest --gateway http://<gateway>:8787 --tools opencode

Enroll first (--enroll <link> or --sso) to get a personal ark_… client key. --dry-run previews. Drop --tools to configure every detected tool.

2
Restart OpenCode
3
Pick a model and check the console

Any anthropic/* or openai/* model routes through the gateway. Your turn shows in Sessions.

Connect merges its provider block (your key plus x-anyray-metadata) and MCP entry into the existing opencode.jsonc, opencode.json, or config.json. It keeps comments, backs the file up first, and --revert removes only what it owns.

Existing custom gateway providers
What you hadWhat Connect does
A custom provider on this gateway serving only Claude modelsMigrates it onto the managed anthropic block and rewrites model refs to anthropic/*. The backup keeps the original
Any other custom provider on this gatewayLeaves it as is; adds only missing x-anyray-api-key and x-anyray-metadata headers. --revert removes just those
An anthropic or openai block you pinned to your own upstreamKeeps your Authorization, key, and passthrough headers (x-anyray-auth-mode, x-anyray-custom-host, x-anyray-provider), and says which lanes it skipped. --upstream moves them to a managed passthrough
A foreign MCP server named anyrayLeaves it alone
Tool approvals

Connect sets these to allow so agents run unattended: anyray_anyray_retrieve, anyray_anyray_recall, anyray_anyray_search, anyray_anyray_read, anyray_anyray_read_batch, anyray_anyray_history.

Your own matching permission key (patterns like anyray_* too) wins. anyray_read_batch ignores permission.read; see Batch reads.

Tool-output trimming

~/.config/opencode/plugins/anyrayTrim.js runs __anyray-hook after each tool call and keeps the smaller output (the original on failure). The same file loads on OpenCode 1.x and 2.x. No tees, no verdict cache. Installed only when the Connect binary is at a durable path.

Set it up by hand
1
Open the config
Edit the existing file under ~/.config/opencode/. Create opencode.json only when none exists.
2
Add the Anyray provider
Under provider, set the openai or anthropic entry's options.baseURL to http://<gateway>:8787/v1 and options.apiKey to your personal ark_… key. Copilot needs the plugin Connect writes, so run Connect for that lane.
3
Restart
Save the file and restart OpenCode.

Copilot subscription seat​

With a Copilot plan, Connect adds a github-copilot provider on /v1/copilot/<plan>/header and writes ~/.config/opencode/plugins/anyrayCopilotSeat.js, which carries your gateway key and points OpenCode 2's Copilot requests at the gateway. The key stays out of opencode.json, because OpenCode 2 sends the headers set there to GitHub's own host. Copilot is not routed through a non-localhost http:// gateway (use https://) or to GitHub Enterprise data-residency hosts (*.ghe.com).

Model prefixWhat it spends
github-copilot/*Your Copilot subscription
anthropic/* and openai/*The direct providers, in api-key mode with separate billing

Set ANYRAY_COPILOT_PLAN (individual, business, enterprise, team, or any tier) only if your org enforces the host api.<plan>.githubcopilot.com.

ChatGPT subscription​

Sign in with ChatGPT Pro/Plus (opencode auth login) and pick an openai/* model. Your plan pays. Connect writes ~/.config/opencode/plugins/anyrayChatgptSeat.js, which sends those requests through the gateway on OpenCode 1.x and 2.x.

OpenCode 2 compresses ChatGPT requests in a format gateways older than v1.10.425 cannot read. On an older gateway they stay on chatgpt.com until you upgrade it.

Connect skips the plugin on a non-localhost http:// gateway (use https://), when another owner has the file, or when the machine is not enrolled. Then:

Your openai laneResult
Org API key on the gatewayStill routed and attributed by key. Gateway key and metadata are kept off provider.openai, so you lose session and intent tags and the exact tool name
Your own upstream, wired by handLeft untouched, or the gateway key an earlier run added is removed
Your own upstream, written by --upstreamThe block and its upstream key are removed (they would leak your private host to chatgpt.com); OpenAI models fall back to OpenCode's native setup

The Anthropic lane is unaffected.

Paths that bypass the plugin

Plugins turned off, OPENCODE_EXPERIMENTAL_WEBSOCKETS, or a plugin that fails to load or replaces fetch after ours: ChatGPT requests go straight to chatgpt.com, with your gateway key when openai/* is on your org's API account. Connect cannot detect these.

Claude subscription​

Anthropic allows a Claude Pro or Max sign-in only in Claude Code and its own apps, so OpenCode's Anthropic provider takes an API key. For a personal Claude subscription use Claude Code. To spend a subscription on Claude models in OpenCode, pick the github-copilot/claude-* models with a Copilot plan.