Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/plugin/provider/cloudflare-ai-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export const CloudflareAIGatewayPlugin = define({
// gateway's stored/BYOK keys instead.
const isWorkersAi = modelID.startsWith("workers-ai/") || modelID.startsWith("@cf/")
const unified = createUnified(isWorkersAi ? { apiKey: config.apiKey } : {})
return gateway(unified(modelID))
// models.dev lists Anthropic ids with dotted versions (claude-haiku-4.5) but Anthropic's
// real slugs use dashes (claude-haiku-4-5). The Unified API forwards the id straight to
// the upstream provider, so a dotted Anthropic id 404s. Other providers use dots natively.
const upstreamID = modelID.startsWith("anthropic/") ? modelID.replaceAll(".", "-") : modelID
return gateway(unified(upstreamID))
},
}
}),
Expand Down
55 changes: 55 additions & 0 deletions packages/core/test/plugin/provider-cloudflare-ai-gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,61 @@ describe("CloudflareAIGatewayPlugin", () => {
),
)

it.effect("translates models.dev's dotted Anthropic ids to Anthropic's native dashed slugs", () =>
withEnv(cloudflareEnv(), () =>
Effect.gen(function* () {
resetCalls()
const plugin = yield* PluginV2.Service
const aisdk = yield* AISDK.Service
yield* addPlugin()

const result = yield* aisdk.runSDK({
model: ModelV2.Info.make({
...ModelV2.Info.empty(
ProviderV2.ID.make("cloudflare-ai-gateway"),
ModelV2.ID.make("anthropic/claude-haiku-4.5"),
),
api: {
id: ModelV2.ID.make("anthropic/claude-haiku-4.5"),
type: "aisdk",
package: "test-provider",
},
}),
package: "ai-gateway-provider",
options: { name: "cloudflare-ai-gateway" },
})

result.sdk.languageModel("anthropic/claude-haiku-4.5")

expect(unifiedCalls).toEqual(["anthropic/claude-haiku-4-5"])
}),
),
)

it.effect("leaves non-Anthropic ids with dots untouched (e.g. OpenAI's gpt-4.1)", () =>
withEnv(cloudflareEnv(), () =>
Effect.gen(function* () {
resetCalls()
const plugin = yield* PluginV2.Service
const aisdk = yield* AISDK.Service
yield* addPlugin()

const result = yield* aisdk.runSDK({
model: ModelV2.Info.make({
...ModelV2.Info.empty(ProviderV2.ID.make("cloudflare-ai-gateway"), ModelV2.ID.make("openai/gpt-4.1")),
api: { id: ModelV2.ID.make("openai/gpt-4.1"), type: "aisdk", package: "test-provider" },
}),
package: "ai-gateway-provider",
options: { name: "cloudflare-ai-gateway" },
})

result.sdk.languageModel("openai/gpt-4.1")

expect(unifiedCalls).toEqual(["openai/gpt-4.1"])
}),
),
)

it.effect("ignores non Cloudflare AI Gateway packages", () =>
withEnv(cloudflareEnv(), () =>
Effect.gen(function* () {
Expand Down
Loading