OpenClaw integration

Use Plan2API as a custom provider in OpenClaw

OpenClaw takes Plan2API as 1 custom provider entry in ~/.openclaw/openclaw.json: baseUrl https://api.plan2api.com/v1, api openai-completions and a p2a_ key. Set the primary model to plan2api/claude/claude-sonnet-5 and your Claude, ChatGPT, Gemini or Kimi plan runs the agent, with 50 free chat requests a day.

Config file
~/.openclaw/openclaw.json
api
openai-completions
Model ref format
plan2api/<Plan2API model id>
Free plan
50 chat requests a day

Updated

OpenClaw settings for Plan2API

OpenClaw talks to Plan2API as a custom provider that uses the OpenAI-compatible Chat Completions format, set up in its config file. The table below lists the values to put in your config.

openclaw.json values for Plan2API
SettingValue
Config file~/.openclaw/openclaw.json (JSON5)
Provider entrymodels.providers.plan2api
baseUrlhttps://api.plan2api.com/v1
apiKey${PLAN2API_KEY}
apiopenai-completions
models[].idA Plan2API id, such as claude/claude-sonnet-5
Default modelagents.defaults.model.primary
Model refplan2api/claude/claude-sonnet-5

When Plan2API helps in OpenClaw

OpenClaw already signs in to ChatGPT and Codex with OAuth, reuses a local Claude CLI login (and setup-token auth still works), and takes Anthropic, Google AI Studio, Vertex AI and Kimi API keys. However, it doesn't create Gemini CLI or Antigravity OAuth profiles.

Add Plan2API to openclaw.json

  1. Sign up with a Google account, connect your Claude, ChatGPT, Google AI or Kimi subscription, and copy your p2a_ key.
  2. Put PLAN2API_KEY in ~/.openclaw/.env or in the gateway's environment, since the config's apiKey field reads ${PLAN2API_KEY} and only matches uppercase names.
  3. Add the provider block to ~/.openclaw/openclaw.json (or the file in OPENCLAW_CONFIG_PATH), listing each model you want to use with at least its id.
  4. Save the file so the config hot-reloads; OpenClaw validates keys strictly, and an unknown key stops the gateway from starting until you run openclaw doctor --fix.

This example adds the provider block and sets the primary model at the same time.

JSON
{
  "agents": {
    "defaults": {
      "model": { "primary": "plan2api/claude/claude-sonnet-5" }
    }
  },
  "models": {
    "providers": {
      "plan2api": {
        "baseUrl": "https://api.plan2api.com/v1",
        "apiKey": "${PLAN2API_KEY}",
        "api": "openai-completions",
        "timeoutSeconds": 300,
        "models": [
          {
            "id": "claude/claude-sonnet-5",
            "name": "Claude Sonnet 5 (Plan2API)",
            "reasoning": true,
            "input": ["text", "image"],
            "contextWindow": 1000000
          },
          {
            "id": "openai/gpt-6.1-sol",
            "name": "GPT-6.1 Sol (Plan2API)",
            "reasoning": true
          },
          {
            "id": "gemini/gemini-3.8-flash-high",
            "name": "Gemini 3.8 Flash (Plan2API)",
            "reasoning": true,
            "input": ["text", "image"],
            "contextWindow": 1048576
          },
          {
            "id": "kimi/k3",
            "name": "Kimi K3 (Plan2API)",
            "reasoning": true,
            "input": ["text", "image"],
            "contextWindow": 1048576
          }
        ]
      }
    }
  }
}

Pick the default model

OpenClaw model refs follow a provider/model format and split at the first slash. That means plan2api/claude/claude-sonnet-5 tells OpenClaw to use the plan2api provider and send the model id claude/claude-sonnet-5 to the API.

You can set the default in agents.defaults.model.primary, run openclaw models set plan2api/claude/claude-sonnet-5 in your terminal, or pick it in the Control UI (http://127.0.0.1:18789, under Settings, then Models). Run openclaw models list any time to see the available refs. The table below lists the common model refs along with the contextWindow value to set for each one (without contextWindow and with no discovered window, OpenClaw falls back to a 200,000-token budget).

Plan2API model refs for OpenClaw
Model refSubscriptioncontextWindow
plan2api/claude/claude-sonnet-5Claude Pro or Max1000000
plan2api/claude/claude-opus-5-5Claude Pro or Max1000000
plan2api/claude/claude-haiku-4-5Claude Pro or Max200000
plan2api/openai/gpt-6.1-solChatGPT plan (Codex)From GET /v1/models
plan2api/gemini/gemini-3.8-flash-highGoogle AI Pro or Ultra1048576
plan2api/kimi/k3Kimi Code membership1048576

Thinking, images and timeouts

  • Setting reasoning: true on a model makes OpenClaw send reasoning_effort when thinking is turned on (while /think off omits it), which works across all four providers, though xhigh and max require compat.supportedReasoningEfforts on the model entry.
  • Setting input to ["text", "image"] lets WebChat and node attachments reach Claude, Gemini and Kimi models as images instead of text-only media references.
  • Leaving maxTokens unset tells OpenClaw to send neither max_tokens nor max_completion_tokens, and Claude models then allow up to 128K output (or 64K on claude/claude-haiku-4-5).
  • Setting timeoutSeconds under models.providers.plan2api extends OpenClaw's default 120-second wait for the first response from a cloud endpoint, which helps on long reasoning turns.

temperature and top_p are ignored on Claude and Codex models and fixed on Kimi (temperature 1, top_p 0.95), so sampling settings only change Gemini output.

Plan2API plans for OpenClaw agents

An OpenClaw agent sends one chat request per model call, so a single task with tool calls and follow-up turns can go through several requests. The Free plan ($0, no card needed) includes 1 connected subscription, 50 chat requests a day resetting at 00:00 UTC, 1 request per second with bursts up to 20, and 4 requests at once, which is plenty for testing your config.

For daily agent runs, Pro is $12 a month or $99 a year with no daily request cap, 10 requests per second with bursts up to 600, 16 requests at once and 3 connected subscriptions, while Scale is $29 a month or $249 a year with 25 subscriptions and 32 requests at once. Plan2API never bills per token and adds no token quota of its own, so Claude's own usage limits and your other providers' limits still apply alongside the Plan2API plan limits and pricing.

Troubleshooting OpenClaw with Plan2API

  • Gateway won't start after editing ~/.openclaw/openclaw.json: OpenClaw stops on unknown or misspelled keys, so run openclaw doctor --fix to repair the config.
  • 401 invalid_api_key: PLAN2API_KEY isn't set in the gateway's process environment or ~/.openclaw/.env, so ${PLAN2API_KEY} stays unresolved and OpenClaw emits a warning; a revoked or mistyped key gives the same 401.
  • 403 no_credentials: your vault has no connected subscription for the provider prefix on that model id.
  • 400 model_not_found: the models[].id entry in your config needs to be the exact model id from GET /v1/models, such as claude/claude-sonnet-5 without the plan2api/ prefix.
  • 400 unsupported_parameter: the request sent a json_object or json_schema response_format to a Claude model, which only accepts text responses.
  • 429 subscription_quota_exhausted with a Retry-After header: every connected account for that provider has hit its usage limit until the reset time in Retry-After (or on the Free plan, 429 daily_requests when you pass 50 chat requests before 00:00 UTC).

See the API documentation and error reference for the full list of error codes and streaming error events.

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

How do I add a custom OpenAI-compatible provider to OpenClaw?

Add a provider entry under models.providers in ~/.openclaw/openclaw.json with baseUrl, apiKey, api set to "openai-completions", and a models array listing each model's id. For Plan2API, set baseUrl to https://api.plan2api.com/v1 and apiKey to "${PLAN2API_KEY}".

What model ref do I use for Claude Sonnet 5?

Use plan2api/claude/claude-sonnet-5. OpenClaw splits the ref at the first slash, picks the plan2api provider, and sends the model id claude/claude-sonnet-5 in the request body.

Do I need Plan2API if OpenClaw already signs in to ChatGPT?

Not if you only use Codex, since OpenClaw's built-in ChatGPT OAuth sign-in already handles that. Plan2API is for running Gemini models from a Google AI Pro or Ultra plan, which OpenClaw doesn't sign in to, or putting Claude, Codex, Gemini and Kimi behind one key and one provider block.

Can I use api anthropic-messages with Plan2API?

No, because Plan2API doesn't have an Anthropic /v1/messages endpoint and doesn't accept the x-api-key header. Set api to "openai-completions" for every model, including Claude.

Why does OpenClaw get 401 invalid_api_key from Plan2API?

In most cases ${PLAN2API_KEY} didn't resolve because PLAN2API_KEY isn't defined in the gateway's environment or ~/.openclaw/.env (OpenClaw ignores provider keys in a workspace .env). OpenClaw leaves a missing or empty variable unresolved and emits a warning, and it only substitutes uppercase names. A revoked or mistyped key also returns 401.

Sources

  1. OpenClaw docs: Custom providersdocs.openclaw.ai
  2. OpenClaw docs: Model providersdocs.openclaw.ai
  3. OpenClaw docs: Configurationdocs.openclaw.ai
  4. OpenClaw docs: Thinking levelsdocs.openclaw.ai
  5. OpenClaw releases (GitHub)github.com