Skip to content

fix(provider): send Anthropic's dashed native slug through the AI Gateway - #44251

Closed
superhighfives wants to merge 1 commit into
anomalyco:devfrom
superhighfives:gateway-anthropic-ids
Closed

fix(provider): send Anthropic's dashed native slug through the AI Gateway#44251
superhighfives wants to merge 1 commit into
anomalyco:devfrom
superhighfives:gateway-anthropic-ids

Conversation

@superhighfives

@superhighfives superhighfives commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #44252

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Every Anthropic model under cloudflare-ai-gateway fails with Error: 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?

  • Built the single binary and ran against a live Cloudflare AI Gateway: anthropic/claude-haiku-4.5 went from Error: model: claude-haiku-4.5 to a normal completion; openai/* and workers-ai/@cf/* still work.
  • Added a regression test in cf-ai-gateway-e2e.test.ts asserting 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/ in packages/opencode passes (one unrelated pre-existing flake in header-timeout.test.ts, which also fails on dev). tsgo --noEmit clean.

Screenshots / recordings

N/A (not a UI change).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The Unified API forwards the model id straight to the upstream provider.
models.dev lists Anthropic ids with dotted versions (claude-haiku-4.5)
but Anthropic's real slugs use dashes (claude-haiku-4-5), so a dotted id
404s and unified billing / BYOK never works for any Anthropic model.
Other proxied providers use dots natively, so the fix is scoped to the
anthropic/ prefix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@superhighfives

Copy link
Copy Markdown
Contributor Author

Ah, I think we're using the legacy endpoint here. Closing.

@superhighfives superhighfives changed the title fix(core): translate dotted Anthropic ids for Cloudflare AI Gateway fix(provider): send Anthropic's dashed native slug through the AI Gateway Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudflare-ai-gateway: Anthropic models 404 (dotted id not translated to Anthropic's dashed slug)

1 participant