fix(provider): send Anthropic's dashed native slug through the AI Gateway - #44281
Conversation
…eway The Cloudflare AI Gateway plugin routes anthropic/* models through the native Anthropic Messages passthrough (createAnthropic), which forwards the model id to Anthropic's API unchanged. models.dev lists Cloudflare's canonical dotted ids (anthropic/claude-haiku-4.5), but Anthropic's Messages API expects dashed native slugs (claude-haiku-4-5), so every Anthropic model 404s with "model: claude-haiku-4.5". Translate dots to dashes when slicing the anthropic/ prefix. OpenAI is unaffected because its native slugs already use dots (gpt-4.1). Cloudflare's own catalog-aware REST endpoints (/ai/v1/messages, /ai/run) do this same translation internally; the native passthrough route opencode uses does not, so the plugin has to. Verified end-to-end against a live gateway: anthropic/claude-haiku-4.5 goes from "Error: model: claude-haiku-4.5" to a normal completion, with OpenAI and Workers AI models unaffected. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Correct diagnosis and a tidy fix: models.dev lists Anthropic ids dotted ( Two suggestions:
Minor: worth a quick sanity pass over the other first-party branches in |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Passed this back to the robot and got the below, which added a comment and rationalized the other two. Happy to discuss! Thanks for the review (re: #44281 (comment)). 2. Documented the safety invariant — done in 70ae461. Added a note that no native Anthropic slug contains a dot, so the blanket replacement is lossless, and contrasted it with the OpenAI branch above (whose native ids like 3. Sanity pass over the other 1. Extracting a shared |
…eway (anomalyco#44281) Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit f8b4dd7)
…eway (anomalyco#44281) Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Upstream v1.18.22 (47b6b6f, merged at 2686e4c) -> v1.18.23 (ef2880f), 13 commits / 46 files. Upstream superseded the v1.18.22 release commit with 55f9841 (sync release versions for v1.18.22) in the v1.18.23 lineage; merge base is 2a6be0a (chore: generate), effective input identical to the audited 13-commit range. Functional changes: - fix(provider): route non-native Cloudflare AI Gateway providers via the REST API (anomalyco#44828) — adopted onto fork provider.ts; the custom cloudflare loader region was untouched by the fork snapshot architecture, so the change auto-merged. Third-party models (google, xai, deepseek, ...) now point an OpenAI-compatible client at the Cloudflare REST endpoint (api.cloudflare.com/client/v4/accounts/<id>/ai/v1) bound with cf-aig-gateway-id, keeping requests gateway-routed; Workers AI keeps the unified compat route with the Cloudflare token as upstream Authorization. - fix(provider): send Anthropic's dashed native slug through the AI Gateway (anomalyco#44281) — anthropic/<id> models translate dotted versions to dashes (claude-haiku-4.5 -> claude-haiku-4-5) before the native Messages passthrough; OpenAI dotted ids untouched. - fix(opencode): send parent session header (anomalyco#44752) — x-parent-session-id moved to the provider-independent header level so opencode providers also send it; session routing headers (x-session-affinity/X-Session-Id) and opencode x-opencode-* headers unchanged. - fix(github): support immutable OIDC subjects (anomalyco#44776) — token exchange reads the repository claim via new parseRepositoryClaim (packages/function/src/github.ts + 5 tests) instead of parsing the subject, so immutable subjects (repo:owner@id/repo@id) resolve; exchange failures return 502 with context; github.handler.ts guards error reporting behind GitHub client readiness and reports raw text on token-exchange failure. - console: zen inference header lifecycle ($client replacement, keep x-opencode-* headers on new inference), requestBody nested-model parsing + tests, revert of the first-month-50 coupon delay, legal/prompt-data docs; docs(github.mdx) action token configuration. Conflicts resolved: 29 package.json version bumps (rebranded 1.18.23-sscity), bun.lock (took upstream, rebranded workspace entries via bun install). provider.ts and request.ts auto-merged; provider.ts verified to differ from pre-merge fork HEAD only by the Cloudflare changes — fork snapshot / small-model-chain / session-pinning / GLM architecture untouched. packages/function/package.json adopted upstream's new "test" script, wiring the new github tests into turbo alongside the new @opencode-ai/function#test task. Tests from both sides kept: provider 105, transform 437, retry 68, run-process 15, session llm 30 (incl. new parent session header test), cf-ai-gateway-e2e 13 (incl. dashed-slug and REST-route assertions), function github 5 (new), console requestBody 6 all pass; typecheck 30/30.
Issue for this PR
Closes #44280
Type of change
What does this PR do?
Every Anthropic model under
cloudflare-ai-gatewayfails withError: model: claude-haiku-4.5, so none of them are usable.The plugin already routes
anthropic/*models through Anthropic's native Messages passthrough (createAnthropic), which forwards the sliced model id to Anthropic's API unchanged. models.dev lists Cloudflare's canonical dotted ids (anthropic/claude-haiku-4.5), but Anthropic's Messages API expects dashed native slugs (claude-haiku-4-5) — so it 404s.The fix translates dots to dashes when slicing the
anthropic/prefix. OpenAI is unaffected because its native slugs already use dots (gpt-4.1), which is why only Anthropic was broken.Worth noting: Cloudflare's own catalog-aware REST endpoints (
/ai/v1/messages,/ai/run) accept the dotted id and do this exact dot→dash translation internally before calling Anthropic. The native passthrough route this plugin uses forwards the slug raw, so the plugin has to do the same translation. The dotted id in models.dev is correct — it's Cloudflare's canonical id (see https://developers.cloudflare.com/ai/models/anthropic/claude-haiku-4.5/), so this is fixed on the opencode side, not in the catalog. (Context: surfaced while testing anomalyco/models.dev#4922.)How did you verify your code works?
anthropic/claude-haiku-4.5went fromError: model: claude-haiku-4.5to a normal completion;openai/*andworkers-ai/@cf/*still work.cf-ai-gateway-e2e.test.tsasserting a dotted Anthropic id reaches the Anthropic Messages wire as a dashed slug; confirmed it fails without the fix and passes with it.bun test test/provider/inpackages/opencodepasses (one unrelated pre-existing flake inheader-timeout.test.ts, which also fails ondev).tsgo --noEmitclean.Screenshots / recordings
N/A (not a UI change).
Checklist