From c10bfb0d79dbbc998539a0a3e6c6a736a4e6db06 Mon Sep 17 00:00:00 2001 From: David Brailovsky Date: Fri, 2 Oct 2026 16:10:34 +0200 Subject: [PATCH] fix(ai): use dashed Claude model IDs for Cloudflare AI Gateway The gateway's /anthropic passthrough forwards the model ID to Anthropic unchanged. models.dev lists the gateway's Claude models with dotted versions (claude-opus-5.5), which Anthropic rejects with a 404. Convert dots to dashes (claude-opus-5-5) when generating the catalog. --- packages/ai/CHANGELOG.md | 1 + packages/ai/scripts/generate-models.ts | 5 ++++- packages/ai/test/stream.test.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index 66c4dd632..db8b1f449 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixed - Fixed "Selected model is at capacity" provider errors ending the turn instead of being retried ([#10278](https://github.com/earendil-works/pi/issues/10278)) +- Fixed Cloudflare AI Gateway Claude models failing with a 404 by using dashed model IDs (`claude-opus-5-5` instead of `claude-opus-5.5`), which Anthropic requires ## [1.0.0] - 2026-10-01 diff --git a/packages/ai/scripts/generate-models.ts b/packages/ai/scripts/generate-models.ts index 5ff0e98c4..c1730928b 100644 --- a/packages/ai/scripts/generate-models.ts +++ b/packages/ai/scripts/generate-models.ts @@ -1966,7 +1966,10 @@ async function loadModelsDevData(): Promise[]> { } else if (upstream === "anthropic") { api = "anthropic-messages"; baseUrl = CLOUDFLARE_AI_GATEWAY_ANTHROPIC_BASE_URL; - id = nativeId; + // The /anthropic passthrough forwards the model ID to Anthropic unchanged. + // models.dev lists dotted versions (claude-opus-5.5), but Anthropic only + // accepts dashed IDs (claude-opus-5-5). + id = nativeId.replaceAll(".", "-"); } else if (upstream === "workers-ai") { api = "openai-completions"; baseUrl = CLOUDFLARE_AI_GATEWAY_COMPAT_BASE_URL; diff --git a/packages/ai/test/stream.test.ts b/packages/ai/test/stream.test.ts index cf48452b2..fc6f2de6c 100644 --- a/packages/ai/test/stream.test.ts +++ b/packages/ai/test/stream.test.ts @@ -700,9 +700,9 @@ describe("Generate E2E Tests", () => { ); describe.skipIf(!hasCloudflareAiGatewayCredentials() || !process.env.ANTHROPIC_API_KEY)( - "Cloudflare AI Gateway → Anthropic BYOK (claude-sonnet-4.5 via /anthropic messages)", + "Cloudflare AI Gateway → Anthropic BYOK (claude-sonnet-4-5 via /anthropic messages)", () => { - const llm = getModel("cloudflare-ai-gateway", "claude-sonnet-4.5"); + const llm = getModel("cloudflare-ai-gateway", "claude-sonnet-4-5"); const options = { headers: { Authorization: `Bearer ${process.env.ANTHROPIC_API_KEY}` } }; const thinkingOptions = { ...options,