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.

OpenCode provider settings for Plan2API
SettingValue
Config fileopencode.json or ~/.config/opencode/opencode.json
Provider idplan2api
npm package@ai-sdk/openai-compatible
options.baseURLhttps://api.plan2api.com/v1
options.apiKey{env:PLAN2API_API_KEY} or /connect
Model keysclaude/claude-opus-5-5, openai/gpt-6.1-sol
More model keysgemini/gemini-4-argon-high, kimi/k3
Model in OpenCodeplan2api/claude/claude-opus-5-5

Set up OpenCode with Plan2API

  1. 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.
  2. Install OpenCode with curl -fsSL https://opencode.ai/v2/install | bash, npm i -g @opencode/cli@latest, or brew install anomalyco/tap/opencode-v2.
  3. Export your key as PLAN2API_API_KEY in the shell where you run OpenCode, or if you'd rather not use an environment variable, run /connect inside OpenCode, choose Other, set the provider id to plan2api, and paste the key so OpenCode saves it to ~/.local/share/opencode/auth.json.
  4. Save the opencode.json file from the next section in your project root (which overrides your global config) or globally at ~/.config/opencode/opencode.json.
  5. Start opencode and run /models to select a Plan2API model.
Shell
# 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
opencode

The 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 plan2api becomes the prefix of every model id you call in OpenCode.
  • Each key under models must match the upstream Plan2API model id, including its provider prefix like claude/ or gemini/.
  • Setting small_model to plan2api/gemini/gemini-3.8-flash-high routes light background tasks to Gemini 3.8 Flash so they don't eat into your Claude quota.
JSON
{
  "$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.

Plan2API models in OpenCode
OpenCode modelSubscription it usesContext window
plan2api/claude/claude-opus-5-5Claude Pro or Max1M tokens
plan2api/claude/claude-sonnet-5Claude Pro or Max1M tokens
plan2api/openai/gpt-6.1-solChatGPT plan through Codex500K default in Codex
plan2api/gemini/gemini-4-argon-highGoogle AI Pro or Ultra1,048,576 tokens
plan2api/gemini/gemini-3.8-flash-highGoogle AI Pro or Ultra1,048,576 tokens
plan2api/kimi/k3Kimi Code1,048,576 tokens

What works and what doesn't

  • Streaming, tool and function calling, and reasoning_effort (or reasoning.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 npm to @ai-sdk/openai-compatible rather than @ai-sdk/openai, because @ai-sdk/openai calls /v1/responses, which Plan2API doesn't serve.
  • Plan2API does not serve /v1/embeddings, /v1/completions, or Anthropic's /v1/messages.
  • JSON mode (response_format set to json_object or json_schema) works on Codex, Kimi and Gemini, but returns HTTP 400 unsupported_parameter on Claude models.
  • temperature and top_p are ignored on Claude and Codex models, passed through on Gemini, and fixed at 1 and 0.95 on 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.

Common errors
ErrorCauseFix
401 invalid_api_keyKey not exported or mistypedExport PLAN2API_API_KEY, then restart opencode
403 no_credentialsNo plan connected for that model's providerConnect the plan at plan2api.com/connect
400 model_not_foundModel key differs from the Plan2API idCopy the id from GET /v1/models
400 unsupported_parameterJSON mode sent to a Claude modelUse a GPT, Gemini or Kimi model for JSON
429 subscription_quota_exhaustedEvery connected account is out of quotaWait 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

  1. OpenCode providers docsopencode.ai
  2. OpenCode config docsopencode.ai
  3. OpenCode models docsopencode.ai
  4. OpenCode on GitHubgithub.com