Connecting OpenCode
Difficulty ⌨️ Intermediate (JSON config file) | API format OpenAI compatible | base_url
https://byesu.com/v1
https://byesu.com/v1claude-opus-4-8OpenCode is one of the most-starred open-source AI coding agents on GitHub — a terminal-first assistant (with a desktop app and IDE extension too) that is deliberately provider-agnostic: it never locks you into a single model vendor. That philosophy pairs naturally with byesu, an AI API gateway with OpenAI-compatible and Anthropic-native endpoints. Declare byesu once as a custom provider in opencode.json, and a single key puts Claude Opus 4.8, Claude Sonnet 5, GPT-5.6 and Grok 4.5 in OpenCode's model picker — billed pay-as-you-go, no subscription.
Before you start
Go to Console → Tokens and create a token in the group that covers the models you plan to use (see Choosing a Group). Replace sk-xxxx below with your own key.
Prerequisites
① OpenCode installed — any of the official methods works:
curl -fsSL https://opencode.ai/install | bashnpm install -g opencode-aibrew install anomalyco/tap/opencodeOnce installed, verify it:
opencode --version② A byesu token — created in the console, in the group that matches the models you want (that's what the "no available channel" error is about later).
Step 1: Add byesu as a custom provider
OpenCode reads opencode.json from two places:
- Global:
~/.config/opencode/opencode.json— applies to every project. Recommended home for the provider block. - Project:
opencode.jsonin the project root — overrides the global file for that project.
Create (or extend) either file with the following:
{
"$schema": "https://opencode.ai/config.json",
"model": "byesu/claude-opus-4-8",
"small_model": "byesu/claude-sonnet-5",
"provider": {
"byesu": {
"npm": "@ai-sdk/openai-compatible",
"name": "byesu",
"options": {
"baseURL": "https://byesu.com/v1",
"apiKey": "sk-your-token"
},
"models": {
"claude-opus-4-8": { "name": "Claude Opus 4.8" },
"claude-sonnet-5": { "name": "Claude Sonnet 5" },
"gpt-5.6-terra": { "name": "GPT-5.6 Terra" },
"grok-4.5": { "name": "Grok 4.5" }
}
}
}
}What each part does:
| Field | Meaning |
|---|---|
provider.byesu | The key you pick here becomes the provider ID — every model reference uses byesu/<model-id> |
npm | The AI SDK adapter OpenCode loads for this provider. byesu's endpoint speaks /v1/chat/completions, so it's @ai-sdk/openai-compatible |
options.baseURL | https://byesu.com/v1 — ends with /v1, don't append /chat/completions |
options.apiKey | Your sk- token; OpenCode sends it as a Bearer header for you |
models | Each key is a model ID exactly as listed in the console; name is only the display label in the picker |
model / small_model | Default model, plus a lightweight helper model (session titles, summaries) — both in provider_id/model_id form |
The three easiest things to get wrong
npmmust be@ai-sdk/openai-compatible. The@ai-sdk/openaipackage targets OpenAI's/v1/responsesAPI and won't match this endpoint.- Model keys under
modelsmust match console names exactly (claude-opus-4-8, notclaude-opus-4.8). - Everywhere else in the config, models carry the provider prefix:
byesu/claude-opus-4-8, never the bare name.
Optionally, each model entry also accepts a
limitobject ({ "context": ..., "output": ... }) so OpenCode's context meter is accurate. Everything works without it.
Step 2 (optional): Keep the key out of the file
Two clean ways to avoid a plain-text key in opencode.json:
Environment variable interpolation. OpenCode expands {env:VAR} placeholders inside the config:
"options": {
"baseURL": "https://byesu.com/v1",
"apiKey": "{env:BYESU_API_KEY}"
}# Add to ~/.zshrc or ~/.bashrc, then reopen your terminal
export BYESU_API_KEY="sk-your-token"The /connect command. Start opencode, type /connect, choose Other, enter byesu as the provider ID and paste your key. OpenCode stores the credential in its own store, and you can drop apiKey from the config entirely.
WARNING
The provider ID you enter in /connect must match the key under provider in opencode.json (here: byesu), otherwise the stored credential is never picked up.
Step 3: Run it and verify
Go into any project directory and start it:
opencodeType /models — the four byesu entries should appear in the picker. Pick one and ask something small (for example, "list the files in the current directory"). If it answers normally, you're connected ✅
Switching models, Plan and Build
/models switches models at any time mid-session. Tab toggles between the Build agent (full tool access) and the Plan agent (analysis mode that asks before editing files), and each agent can pin its own byesu model:
{
"agent": {
"plan": { "model": "byesu/claude-sonnet-5" }
}
}A typical split: Opus 4.8 as the default for Build, Sonnet 5 for the Plan agent and small_model duty.
Stuck?
- 401 / invalid token → the key is wrong, or the
/connectprovider ID doesn't match yourproviderkey in the config (details) - No available channel → the token's group doesn't cover the model you picked; create a token in the right group (Choosing a Group, details)
- Model not found → a key under
modelsdoesn't match the console model name exactly, or a reference is missing thebyesu/prefix (details) - Insufficient balance → top up in the console with USDT, Alipay or WeChat Pay (details)
- For anything else, see Common Errors & Solutions
FAQ
How do I add a custom OpenAI-compatible provider to OpenCode?
Declare it under the provider key in opencode.json: set npm to @ai-sdk/openai-compatible, options.baseURL to https://byesu.com/v1, options.apiKey to your sk- token, and list model IDs under models. From then on, reference every model as byesu/<model-id>.
Which npm package should a custom OpenCode provider use?
@ai-sdk/openai-compatible — it's the adapter for providers that speak /v1/chat/completions, which is what byesu's OpenAI-compatible endpoint uses. @ai-sdk/openai targets OpenAI's /v1/responses API instead and won't match.
Can I keep my API key out of opencode.json?
Yes, two ways: use environment variable interpolation ("apiKey": "{env:BYESU_API_KEY}" plus an export in your shell profile), or run /connect inside OpenCode and store the key under a provider ID that matches your config key.
Why does OpenCode return a "no available channel" error?
The token was created in a group that doesn't cover the model you selected. Create a token in the matching group in the byesu console (see Choosing a Group), swap in the new key, and retry.
Can OpenCode's Plan and Build agents use different models?
Yes. Tab switches between Build and Plan during a session, and each agent takes its own model override in opencode.json — for example agent.plan.model set to byesu/claude-sonnet-5 while Build stays on byesu/claude-opus-4-8.
How is OpenCode usage billed through byesu?
Pay-as-you-go per token, with transparent multipliers over official list prices and no subscription. The console shows the live billed price next to each model, and you can top up with USDT, Alipay or WeChat Pay.
