OpenCode custom provider: opencode.json setup for Claude and GPT
OpenCode is a terminal coding agent that talks to any OpenAI-compatible or Anthropic-compatible API. apillms exposes both https://apillms.com/v1 (OpenAI-compatible) and https://apillms.com (Anthropic-compatible, no /v1), so you can point OpenCode at it as a custom provider and choose which model to run per session, per repo, or even per task.
This guide walks through getting your key, writing the provider config, verifying the connection, picking a model, and estimating what a typical session will cost before you run it.
Get your key and base URL
Sign up at apillms and log in. Every account gets exactly one API key, created automatically — there is no "create key" feature. From the console, go to API keys and click Show to view it, or Roll to disable the old key and generate a new one if it's ever exposed.
New accounts also start with 50 free credits (1 credit = $0.005), which is enough to test the OpenCode setup before you commit to a pack.
For OpenCode, use the OpenAI-compatible base URL:
https://apillms.com/v1
If you'd rather wire OpenCode's Anthropic-style provider directly to Claude models, use the Anthropic-compatible base URL instead (note: no /v1 suffix):
https://apillms.com
Both share the same key and the same account balance — pick whichever matches the provider type OpenCode expects for the models you want.
Add apillms as a custom provider
OpenCode reads provider definitions from its config file. Add a custom provider block pointing at apillms, with your key as the bearer token, and list the model ids you want available:
{
"provider": {
"apillms": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://apillms.com/v1",
"apiKey": "YOUR_API_KEY"
},
"models": {
"claude-sonnet-5": {},
"claude-opus-5-5": {},
"gpt-5.5": {},
"deepseek-v4-flash": {}
}
}
}
}
Replace YOUR_API_KEY with the key from API keys. If you'd rather not hardcode the key in the config file, set it as an environment variable and reference it from your shell before launching OpenCode — the same key also works as ANTHROPIC_AUTH_TOKEN if you're using the Anthropic-compatible base URL (set ANTHROPIC_BASE_URL to https://apillms.com in that case).
Exact config file location and field names can vary slightly between OpenCode versions. Check the OpenCode integration guide for the current ready-to-paste snippet before you start, and compare it against what's above if something doesn't match.
Verify the connection
Before launching a full OpenCode session, confirm your key and base URL work with a plain curl request:
curl https://apillms.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-5","messages":[{"role":"user","content":"ping"}]}'
A normal chat completion response means the key and base URL are correct, and OpenCode will work with the same values. You can also use the Connect page in the console to test your key directly and open the app-specific guides, including OpenCode's.
If the request fails:
- 401/invalid key — re-copy the key from API keys; if you rolled the key recently, the old one is disabled and your config still has the old value.
- Connection refused or wrong path — double-check you're using
https://apillms.com/v1for OpenAI-compatible calls (with/v1) orhttps://apillms.comfor Anthropic-compatible calls (without/v1). Mixing the two is the most common misconfiguration. - Unknown model id — confirm the id matches one from the catalog on /models exactly, including hyphens and version suffixes (e.g.
claude-opus-5-5, notclaude-opus-5.5).
Pick a model
Every id under models in the config above is a real model id on sale on apillms. A few useful ones for coding work, with per-million-token prices:
| Model id | Input / 1M | Output / 1M | Cache read / 1M |
|---|---|---|---|
| claude-sonnet-5 | $0.274 | $1.37 | $0.046 |
| claude-opus-5-5 | $0.639 | $3.19 | $0.106 |
| gpt-5.5 | $0.532 | $3.19 | $0.03 |
| deepseek-v4-flash | $0.047 | $0.047 | $0.027 |
The full catalog, with capability filters, is on /models. You can add more ids to the models block (any id on sale works) and switch between them in OpenCode per session without touching the provider config again.
A practical pattern: use deepseek-v4-flash or gpt-5.5 for routine edits, lint fixes, and boilerplate, and reserve claude-sonnet-5 or claude-opus-5-5 for harder refactors or multi-file reasoning where the extra cost is worth it.
What an OpenCode session costs
OpenCode sessions are mostly repeated "agent turns": a large chunk of cached context (the repo, prior messages) plus a small amount of fresh input and output each turn. Using apillms prices and prompt caching:
- claude-sonnet-5: one agent turn (100,000 cache-read + 5,000 fresh input + 1,000 output tokens) = $0.021; 1,000 such turns = $20.99
- claude-opus-5-5: one agent turn = $0.041; 1,000 such turns = $41.07
- gpt-5.5: one agent turn = $0.013; 1,000 such turns = $13.45
- deepseek-v4-flash: one agent turn = $0.006; 1,000 such turns = $5.88
Prompt caching on apillms is automatic and per-user — there's nothing to configure. Repeated turns in the same OpenCode session hit the cheaper cache-read price shown above by default. See how prompt caching cuts the bill for more on why this matters for agent workflows specifically.
For reference, OpenRouter lists claude-sonnet-5 at $2 / $10 input/output and gpt-5.5 at $5 / $30 — apillms is cheaper on both input and output for these ids. Compare live numbers for every model on /compare, or see pack sizes and token estimates on /pricing.
Pay-as-you-go, no expiring credits
Credits never expire, and failed requests aren't billed — so a bad OpenCode run, a dropped connection, or an aborted session doesn't cost you anything. Packs start at Starter $5 for 1,000 credits, up to Builder $20 for 4,200 credits, Pro $50 for 11,000 credits, and Scale $100 for 23,000 credits. Top up on /billing with PayPal or card; payment history and the refund policy are on the same page.
Because credits are shared across the whole account, the same balance covers OpenCode plus any other tool you connect — Claude Code, the Playground, Image studio, and so on.
Switching models and tools mid-project
Because the provider config lists several model ids under one apillms provider, you can switch between them inside OpenCode without changing keys or base URLs — run deepseek-v4-flash for quick edits and claude-sonnet-5 for harder refactors in the same repo, in the same session.
The same single API key and base URL work across other clients too, so you're not locked into one tool for a given project. If you also use Claude Code or VS Code Chat on the same codebase, see the Claude Code setup guide or VS Code Chat guide — both reuse the exact same key you just configured for OpenCode.
If your workflow also needs image or voice generation alongside coding, those run through separate console tools (Image studio, Voice studio) on the same account balance, but OpenCode itself only needs the chat/completions endpoint described above.
Takeaway
OpenCode works as a drop-in client once you add apillms as a custom OpenAI-compatible provider with your account's base URL and single API key. Verify the connection with a plain curl request before trusting a full session, pick cheaper models for routine edits and reserve pricier ones for harder tasks, and let automatic prompt caching keep repeated-context turns cheap without any extra setup.
Try apillms
One API key for Claude, GPT, Grok, DeepSeek and Kimi. OpenAI- and Anthropic-compatible, prompt caching included, pay-as-you-go from $5 with PayPal or card. Credits never expire.
FAQ
Does OpenCode need a special apillms plugin?
No. apillms exposes a standard OpenAI-compatible API at https://apillms.com/v1, so OpenCode's generic custom provider support (e.g. @ai-sdk/openai-compatible) works without any apillms-specific plugin.
Can I use multiple apillms models in the same OpenCode config?
Yes. List as many model ids as you want under the provider's "models" block and pick which one to use per session or per task.
Do I need a separate API key per model or project?
No. Each apillms account has exactly one API key; use it everywhere, including multiple OpenCode projects and other tools like Claude Code.
Will unused credits expire if I only use OpenCode occasionally?
No, apillms credits never expire, and failed requests aren't billed, so idle periods between OpenCode sessions don't cost anything.