Skip to main content

Claude Code with OpenCheese

/ API docs

← API quickstartView as Markdown

Claude Code talks to the Anthropic Messages API, which OpenCheese serves at https://api.opencheese.dev. Point it there with an OpenCheese API key and it runs on the models enabled for your account.

The fastest way: the generated file

Sign in, open Configuration, choose the Claude Code tab with Claude Code (CLI) selected, pick an API key and confirm your password. Copy the generated settings.json and merge its env block into your user settings:

System File
macOS and Linux ~/.claude/settings.json
Windows %USERPROFILE%\.claude\settings.json

The generated file pins the newest Claude models your plan includes to Claude Code's model aliases (opus, sonnet, haiku and fable), so /model opus and the others resolve to models you can use. A family your plan does not include is left out. It also turns on the one-hour prompt cache.

Manual setup

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.opencheese.dev",
    "ANTHROPIC_API_KEY": "YOUR_OPENCHEESE_API_KEY",
    "ENABLE_PROMPT_CACHING_1H": "1",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "OPUS_MODEL_ID",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "SONNET_MODEL_ID",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "HAIKU_MODEL_ID",
    "ANTHROPIC_DEFAULT_FABLE_MODEL": "FABLE_MODEL_ID"
  }
}
  • ANTHROPIC_BASE_URL must not end in /v1: Claude Code appends /v1/messages itself.
  • Take the model IDs from GET /v1/models with your key (see Models).
  • Merge the keys into your existing file so your permissions, hooks and MCP settings survive.
  • Keep it in your user settings. A .claude/settings.json committed to a repository publishes your API key to everyone with access to it.

Prompt cache lifetime

With an API key, Claude Code asks for the five-minute prompt cache. ENABLE_PROMPT_CACHING_1H makes it ask for the one-hour cache on every request, as it does on a Claude subscription, so a session you leave for more than five minutes still reads its history from the cache. A one-hour cache write costs more than a five-minute one; the price list shows both in its Cache write column, marked 5m and 1h.

  • Claude Code 2.1.242 and later can set the two kinds of request apart: CLAUDE_CODE_PROMPT_CACHE_TTL for the main conversation and CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL for subagents, compaction and other background requests, each 5m or 1h. They take precedence over ENABLE_PROMPT_CACHING_1H.
  • FORCE_PROMPT_CACHING_5M=1 forces the five-minute cache everywhere.
  • Remove ENABLE_PROMPT_CACHING_1H to go back to the five-minute cache.

Switch models

Inside Claude Code, use /model with an alias such as opus, sonnet, haiku or fable; each resolves to the model pinned in your settings. Claude Code reloads settings.json while it runs, but reads the alias mapping at startup, so restart it after changing an alias.

The effort level you choose in Claude Code is sent with every request. A level the model does not offer is refused with a message naming the levels it does.

Auto mode

In auto mode Claude Code runs commands and tools without asking you, after a safety check of each one. OpenCheese answers that check on every model. For an answer that runs commands, makes network calls or touches files outside your project, OpenCheese may send one short extra request to the same model; it appears under Transactions as Auto mode check and is billed like any other request. Reading, searching and editing files inside your project need no check.

  • A command the check stops does not run: Claude Code tells the model why, and the model carries on without it.
  • If Claude Code still refuses actions with "Auto mode can't check actions in this session", update Claude Code and start a new session. To have Claude Code check actions itself instead, set CLAUDE_CODE_AUTO_MODE_SERVER to 0 in the env block; its own checks are ordinary requests on your key.

In VS Code, Cursor and JetBrains IDEs

The Claude Code extension for VS Code and Cursor, and the JetBrains plugin, use the same ~/.claude/settings.json, so the setup above covers them too. See VS Code and JetBrains.

Claude Desktop

The same Claude Code tab has a Claude Desktop switch. Claude Desktop takes a file you download and import inside the app; see Claude Desktop.

Usage and costs

Every request appears under Transactions in the dashboard, grouped as one session per conversation, with its token usage and cost.

Troubleshooting

  • "Invalid or disabled OpenCheese API key": the key was revoked, disabled or copied incompletely. Check it on the API keys page and regenerate the configuration.
  • The website answers instead of the API: the base URL must be https://api.opencheese.dev, not https://opencheese.dev.
  • Requests fail with a doubled path: a base URL ending in /v1 sends Claude Code to /v1/v1/messages. Remove the /v1.
  • "Not included in your current plan": the model is outside your plan. Choose another model, or keep Use balance for Credit Models on in the Overview page to pay for it from your balance.
The cheese has holes. Your infrastructure should not.