Coding tools
OpenCode setup: custom provider with @ai-sdk/openai-compatible
In short: OpenCode is a terminal coding agent that supports our gateway as a custom provider in opencode.json via @ai-sdk/openai-compatible; save the key with /connect.
On this page
https://api.oneaiapikey.com/v1OpenCode is an open-source coding agent for the terminal. It builds on the AI SDK, which means any OpenAI-compatible service can be plugged in as a custom provider through the @ai-sdk/openai-compatible package. Our gateway is one of those, so a short JSON block gives OpenCode access to every model in our catalogue on one prepaid balance.
What do I need to use OpenCode with the gateway?
Using OpenCode with the gateway needs three things:
- OpenCode installed and starting normally in your terminal.
- A funded account: any balance above $0, the sign-up credit included, pays for every model; when it runs out, add $1 or more (sign up).
- An API key from the console, starting with
sk-.
How do I save my key with /connect?
Save your key by starting opencode, running the /connect command, scrolling to Other and entering a provider ID. Use one-ai-api-key, because the config in the next step refers to the same ID. Paste your sk- key when asked.
OpenCode stores the credential in its local auth file (~/.local/share/opencode/auth.json), outside your project, so it never ends up in git.
Prefer environment variables? Skip /connect and reference a variable from the config instead (shown in step 2).
How do I describe the provider in opencode.json?
Describe the provider in opencode.json. OpenCode reads a global config at ~/.config/opencode/opencode.json and an optional opencode.json in your project root. The global file is the right place for a provider you’ll use everywhere:
{
"$schema": "https://opencode.ai/config.json",
"model": "one-ai-api-key/claude-sonnet-5-5",
"provider": {
"one-ai-api-key": {
"npm": "@ai-sdk/openai-compatible",
"name": "One AI API Key",
"options": {
"baseURL": "https://api.oneaiapikey.com/v1"
},
"models": {
"claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" },
"claude-opus-5-5": { "name": "Claude Opus 5.5" },
"gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
"glm-5.3-flash": { "name": "GLM-5.3 Flash" }
}
}
}
}How the pieces fit:
- The key under
providermust match the ID you used with/connect. npm: "@ai-sdk/openai-compatible"tells OpenCode to talk to the Chat Completions endpoint.options.baseURLincludes/v1; the SDK adds/chat/completionsitself.- Each key under
modelsis an exact model id from our catalogue. Thenameis only a display label. - The top-level
modeluses theprovider/modelformat and becomes your default.
If you went the environment variable route, add an apiKey reference to options and set the variable in your shell:
"options": {
"baseURL": "https://api.oneaiapikey.com/v1",
"apiKey": "{env:ONEAIAPIKEY_API_KEY}"
}Optionally, give each model a limit object with context and output token counts so OpenCode can manage long sessions accurately.
Which models work best with OpenCode?
claude-sonnet-5-5, claude-opus-5-5, gpt-6.1-sol and glm-5.3-flash are the recommended OpenCode models. Rates are USD per 1M tokens, pulled from our catalogue:
| Model id | Good for | Input | Output |
|---|---|---|---|
claude-sonnet-5-5 | Daily coding, Coding agents, Code review | $1.40 | $7 |
claude-opus-5-5 | Agentic coding, Large refactors, Complex reasoning | $2.80 | $14 |
gpt-6.1-sol | Codex CLI, Tool calling, Long context | $0.70 | $3.50 |
glm-5.3-flash | Quick answers, Drafting, Sub-agents | $0.07 | $0.21 |
claude-sonnet-5-5 is a solid default for agentic work. Add glm-5.3-flash for cheap, quick tasks and claude-opus-5-5 for the hard ones. Switch between them any time with the /models command. Browse the rest on the models page.
How do I verify OpenCode works?
Verify the provider by running a one-shot prompt from your shell:
opencode run "Reply with the single word: ready"If the reply comes back, the provider works. Inside the interactive UI, open /models and confirm the gateway’s models are listed under the provider name. Each request also appears in your console’s usage log within a few seconds.
How do I fix common OpenCode errors?
The common OpenCode errors and their fixes are listed below.
401 Unauthorized. OpenCode didn’t send a valid key. Re-run /connect with the same provider ID, or check that the environment variable named in {env:...} is set in the shell that launched OpenCode.
Provider or models missing from /models. Usually a JSON syntax error or a mismatched provider ID. Validate the file (the $schema line enables editor validation) and make sure the ID matches the one in /connect.
404 Not Found. The baseURL is wrong. Use https://api.oneaiapikey.com/v1, no trailing slash, no endpoint path.
“Model not found” or “no available channel”. A key under models doesn’t match a catalogue id. Ids are lowercase and use the exact punctuation shown above.
Long responses time out. OpenCode streams by default, which keeps long generations alive. In your own scripts, send "stream": true for long outputs, since proxies cut idle non-streaming requests at about 100 seconds.
Balance exhausted. Requests fail at zero credit. Top up in the console; no config changes needed.
Next steps
Also using an editor? See the Kilo Code and Zed guides, or the full list of tool guides. The quickstart covers direct API calls, and the pricing page lists every rate.