Runs on the Claude API pay full price for every turn's context: add a native Anthropic backend so opencode's prompt caching applies #155
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Braid can already point a run at the Claude API through Anthropic's OpenAI-compatible endpoint (kind
OpenAI-compatible, URLhttps://api.anthropic.com/v1, a key file). That layer does not support prompt caching (Anthropic's OpenAI SDK compatibility docs, "Important OpenAI compatibility limitations"), so every agent turn pays full input price for the whole conversation so far. Braid's steps run long, growing contexts, so most of the spend would be resending the same prefix.The native Messages API (
/v1/messages) caches, and opencode already does the caching itself: with@ai-sdk/anthropicas the provider (or a model id containingclaude), it marks the first two system messages and the last two messagescacheControl: ephemeralon every request. Read from the opencode 1.18.34 binary; the pinned 1.18.21 still needs checking. The Anthropic client is bundled in the binary, so nothing new is installed.What it needs
AnthropicinBACKEND_KINDS(src/osf/settings.py) and the settings page.render_run_config(src/osf/agent/server.py) renders the provider withnpm: "@ai-sdk/anthropic", for the main backend and the planning one; the key stays a{file:...}reference.auth_headerssendsAuthorization: Bearer, but Anthropic'sGET /v1/modelswantsx-api-keyandanthropic-version. It is used by the engine probe (engine/runtime.py), the settings page's Test (api/settings.py) andapi/artifacts.py. Without this the probe fails and no agent step is admitted.chat_template_kwargs, no thinking budget, and nonothink/briefvariants (Claude Opus 5.5 rejects disabling thinking with a 400).Done when
The fake model in the simulated runs speaks only the OpenAI API, so the live run is the end-to-end check unless a fake
/v1/messagesis worth adding.validate --all --strictfails on 42 specs #156Shipped in
ecf013e(deployed; production serves it, new boot id). Change archived asopenspec/changes/archive/2026-10-08-anthropic-backend.What shipped
cache_control: ephemeral. The key is sent asx-api-keywithanthropic-version, by the run, Test connection and the engine probe.highincluded); the handoff and the cut-off re-prompt think atlowthere, since current Claude models refuse a request with thinking off.tokens.inputis only the uncached part; without this the gauge read 4 for a 16,680-token turn and would never have handed a step off on Claude.openspec update), the uv image 0.12.24, lockfiles refreshed within their ranges. Playwright and its MCP stay at 1.63.0 / 0.0.80: no MCP release is built on Playwright 1.64.0.Live check, Claude Sonnet 5.5, one quick-fix run from a local stack: both agent steps succeeded, lanes green on the first run, no model error or 429. From the second turn of a step on, about 97% of each request was a cache read; 70% of all input over the two short steps. $0.10 against $0.21 uncached.
Deferred: #156 (long requirements under OpenSpec 1.14.1's strict check), #157 (Playwright 1.64 with its MCP), #158 (TypeScript 7, virtua 0.53, @types/node 26), #159 (Node and Python base images).
Not yet checked: a trogdor run on the new build. The model server is unreachable from production and from the laptop right now (unrelated to this deploy); the check is to start one run and see its first agent step begin.
To use it: Settings → Kind Anthropic, URL
https://api.anthropic.com/v1, a model such asclaude-sonnet-5-5, and a key file holding a workspace-scoped key.