Integrations
OpenCode with Plan2API: custom provider setup
Add Plan2API to OpenCode as a custom provider in opencode.json: npm package @ai-sdk/openai-compatible, baseURL https://api.plan2api.com/v1 and your p2a_ key from an environment variable. One key then runs Claude, GPT-6, Gemini 4 Argon and Kimi K3 from your plans, with ids like plan2api/kimi/k3.
- Provider package
- @ai-sdk/
openai-compatible - baseURL
- api.plan2api.com/
v1 - API key
- {env:PLAN2API_
API_ KEY} - Model example
- plan2api/
kimi/ k3
Updated
Settings at a glance
Here are the values you need for the provider block in opencode.json. OpenCode is MIT-licensed and accepts any OpenAI-compatible API as a custom provider.
| Setting | Value |
|---|---|
| Config file | opencode.json or ~/ |
| Provider id | plan2api |
| npm package | @ai-sdk/ |
| options.baseURL | https:// |
| options.apiKey | {env:PLAN2API_ |
| Model keys | claude/ |
| More model keys | gemini/ |
| Model in OpenCode | plan2api/ |
Set up OpenCode with Plan2API
- Sign in with a Google account at plan2api.com/connect, connect your Claude Pro or Max, ChatGPT, Google AI Pro or Ultra, or Kimi Code plan, and generate a
p2a_API key. - Install OpenCode with
curl -fsSL https://opencode.ai/v2/install | bash,npm i -g @opencode/cli@latest, orbrew install anomalyco/tap/opencode-v2. - Export your key as
PLAN2API_API_KEYin the shell where you run OpenCode, or if you'd rather not use an environment variable, run/connectinside OpenCode, chooseOther, set the provider id toplan2api, and paste the key so OpenCode saves it to~/.local/share/opencode/auth.json. - Save the
opencode.jsonfile from the next section in your project root (which overrides your global config) or globally at~/.config/opencode/opencode.json. - Start
opencodeand run/modelsto select a Plan2API model.
# Install OpenCode
curl -fsSL https://opencode.ai/v2/install | bash
# Make your Plan2API key available to OpenCode
export PLAN2API_API_KEY="p2a_your_key"
# Start OpenCode in your project
opencodeThe opencode.json config
Drop this opencode.json provider config into your project root or ~/.config/opencode/opencode.json to wire up your models and set your defaults.
- The provider id
plan2apibecomes the prefix of every model id you call in OpenCode. - Each key under
modelsmust match the upstream Plan2API model id, including its provider prefix likeclaude/orgemini/. - Setting
small_modeltoplan2api/gemini/gemini-3.8-flash-highroutes light background tasks to Gemini 3.8 Flash so they don't eat into your Claude quota.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"plan2api": {
"npm": "@ai-sdk/openai-compatible",
"name": "Plan2API",
"options": {
"baseURL": "https://api.plan2api.com/v1",
"apiKey": "{env:PLAN2API_API_KEY}"
},
"models": {
"claude/claude-opus-5-5": { "name": "Claude Opus 5.5" },
"openai/gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
"gemini/gemini-4-argon-high": { "name": "Gemini 4 Argon" },
"gemini/gemini-3.8-flash-high": { "name": "Gemini 3.8 Flash" },
"kimi/k3": { "name": "Kimi K3" }
}
}
},
"model": "plan2api/claude/claude-opus-5-5",
"small_model": "plan2api/gemini/gemini-3.8-flash-high"
}Pick your models
You can mix models from Claude, ChatGPT Codex, Gemini and Kimi under the same p2a_ key, and the table below lists the main ids and token limits. OpenCode reads the part before the first slash as the provider id and keeps everything after it as the model id, so the double slash in plan2api/claude/claude-opus-5-5 is right. Run GET /v1/models with your key to see every model id Plan2API serves, including the openai/<model> Codex entries; models from providers you haven't connected return HTTP 403 no_credentials.
| OpenCode model | Subscription it uses | Context window |
|---|---|---|
| plan2api/ | Claude Pro or Max | 1M tokens |
| plan2api/ | Claude Pro or Max | 1M tokens |
| plan2api/ | ChatGPT plan through Codex | 500K default in Codex |
| plan2api/ | Google AI Pro or Ultra | 1,048,576 tokens |
| plan2api/ | Google AI Pro or Ultra | 1,048,576 tokens |
| plan2api/ | Kimi Code | 1,048,576 tokens |
What works and what doesn't
- Streaming, tool and function calling, and
reasoning_effort(orreasoning.effort) work across Claude, Codex, Gemini and Kimi models. - Image input works on Claude, Gemini and Kimi models, plus Codex models that accept images, with up to 32 image URLs fetched per request (up to 20 MB and 15 seconds each).
- Set
npmto@ai-sdk/openai-compatiblerather than@ai-sdk/openai, because@ai-sdk/openaicalls/v1/responses, which Plan2API doesn't serve. - Plan2API does not serve
/v1/embeddings,/v1/completions, or Anthropic's/v1/messages. - JSON mode (
response_formatset tojson_objectorjson_schema) works on Codex, Kimi and Gemini, but returns HTTP400unsupported_parameteron Claude models. temperatureandtop_pare ignored on Claude and Codex models, passed through on Gemini, and fixed at1and0.95on Kimi.- The Free plan includes 50 chat requests per day (resetting at 00:00 UTC), and every tool-call round trip OpenCode makes counts as one request.
Troubleshooting
When a request fails, Plan2API returns an OpenAI-style error object with message, type and code (or a final server-sent event if streaming has already started), and the table below covers the common status codes.
If your models don't show up when you run /models, run opencode auth list in your terminal and verify that the provider id plan2api, npm package @ai-sdk/openai-compatible, and options.baseURL https://api.plan2api.com/v1 match your opencode.json.
| Error | Cause | Fix |
|---|---|---|
| 401 invalid_ | Key not exported or mistyped | Export PLAN2API_ |
| 403 no_ | No plan connected for that model's provider | Connect the plan at plan2api.com/ |
| 400 model_ | Model key differs from the Plan2API id | Copy the id from GET / |
| 400 unsupported_ | JSON mode sent to a Claude model | Use a GPT, Gemini or Kimi model for JSON |
| 429 subscription_ | Every connected account is out of quota | Wait for Retry-After or switch model |
Use the AI subscriptions you already pay for as one OpenAI-compatible API key.
- Free: 1 subscription, 50 requests a day, no card
- Pro: $12 a month
FAQ
Does OpenCode support OpenAI-compatible APIs?
Yes. Add a provider block in opencode.json with npm set to @ai-sdk/openai-compatible, set options.baseURL and options.apiKey, and list the model ids you want to use under models.
Can I use my Claude Pro or Max plan in OpenCode?
OpenCode no longer bundles a direct Claude Pro or Max login as of version 1.3.0. When you connect your Claude account to Plan2API, your subscription shows up in OpenCode under ids like plan2api/claude/claude-opus-5-5 and plan2api/claude/claude-sonnet-5.
Where does OpenCode store my API key?
Keys added through the /connect command are written to ~/.local/share/opencode/auth.json. If you set "apiKey": "{env:PLAN2API_API_KEY}" in opencode.json instead, OpenCode reads the key from your shell environment, so you can skip /connect.
Why does the model id have two slashes?
OpenCode splits on the first slash: it uses plan2api as the provider id and passes the rest of the string (claude/claude-opus-5-5) to the API as the model id. Because Plan2API uses a provider prefix of its own (claude/, openai/, gemini/, kimi/), the full id in OpenCode has two slashes, and plan2api/claude/claude-opus-5-5 is valid.
Which Plan2API plan do I need?
The Free plan ($0, no card needed) connects 1 subscription and gives you 50 requests a day, which is plenty for testing the setup but runs out fast during multi-step agent tool calls. Pro is $12 a month ($99 a year) for 3 connected subscriptions with no daily request cap, and Scale is $29 a month ($249 a year) for 25 connected subscriptions and 32 concurrent requests.
Sources
- OpenCode providers docsopencode.ai
- OpenCode config docsopencode.ai
- OpenCode models docsopencode.ai
- OpenCode on GitHubgithub.com