@@ -165,7 +165,8 @@ function extractUpstreamHeaders(body: unknown): Record<string, unknown> | undefi
165165function gatewayModel ( apiId : string , gatewayToken = "test" ) {
166166 const aigateway = createAiGateway ( { accountId : "test" , gateway : "test" , apiKey : gatewayToken } )
167167 if ( apiId . startsWith ( "openai/" ) ) return aigateway ( createOpenAI ( ) ( apiId . slice ( "openai/" . length ) ) )
168- if ( apiId . startsWith ( "anthropic/" ) ) return aigateway ( createAnthropic ( ) ( apiId . slice ( "anthropic/" . length ) ) )
168+ if ( apiId . startsWith ( "anthropic/" ) )
169+ return aigateway ( createAnthropic ( ) ( apiId . slice ( "anthropic/" . length ) . replaceAll ( "." , "-" ) ) )
169170 const isWorkersAi = apiId . startsWith ( "workers-ai/" ) || apiId . startsWith ( "@cf/" )
170171 const unified = createUnified ( isWorkersAi ? { apiKey : gatewayToken } : { } )
171172 return aigateway ( unified ( apiId ) )
@@ -195,6 +196,17 @@ describe("cf-ai-gateway routing", () => {
195196 expect ( upstream ?. model ) . toBe ( "claude-sonnet-4-6" )
196197 } )
197198
199+ test ( "anthropic/* with a dotted models.dev id reaches Anthropic as a dashed native slug" , async ( ) => {
200+ // models.dev ids are dotted (claude-haiku-4.5); Anthropic's Messages API 404s unless the
201+ // version is dashed (claude-haiku-4-5). Regression guard for the dotted-id translation.
202+ await callThroughGateway ( "anthropic/claude-haiku-4.5" , { } )
203+ const step = firstStep ( captured ?. outerBody )
204+ expect ( step ?. provider ) . toBe ( "anthropic" )
205+ expect ( step ?. endpoint ) . toBe ( "v1/messages" )
206+ const upstream = extractUpstreamQuery ( captured ?. outerBody )
207+ expect ( upstream ?. model ) . toBe ( "claude-haiku-4-5" )
208+ } )
209+
198210 test ( "workers-ai models stay on the unified /compat route" , async ( ) => {
199211 await callThroughGateway ( "workers-ai/@cf/moonshotai/kimi-k2.6" , { } )
200212 const step = firstStep ( captured ?. outerBody )
0 commit comments