fix(provider): send Anthropic's dashed native slug through the AI Gateway - #44281
fix(provider): send Anthropic's dashed native slug through the AI Gateway#44281superhighfives wants to merge 1 commit into
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 |
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