[proxy] Anchor the Anthropic date strip to Claude ids

The release-date normalizer matched a bare "-YYYYMMDD" suffix on any id.
Pricing looks every model up through it regardless of surface, and an
operator can register a custom model under any id at all, so a custom
"internal-llm-20250101" would silently inherit the rate registered for
"internal-llm".

Anchor the pattern on "claude" so it still covers the vendor-prefixed
Bedrock forms while leaving every other vendor's id untouched.
This commit is contained in:
mlsmaycon
2026-08-11 13:04:41 +00:00
parent b1337f09d0
commit a39b3c4af4
2 changed files with 34 additions and 21 deletions
+16 -11
View File
@@ -46,20 +46,25 @@ func NormalizeBedrockModel(modelID string) string {
return bedrockVersionSuffix.ReplaceAllString(m, "")
}
// anthropicDateSuffix matches the trailing "-YYYYMMDD" release-date suffix
// Anthropic appends to a pinned model id. No other vendor in the catalog
// ends an id in eight consecutive digits, so the pattern is safe to apply
// before a lookup regardless of surface.
var anthropicDateSuffix = regexp.MustCompile(`-\d{8}$`)
// anthropicDatedModel matches a Claude model id carrying the trailing
// "-YYYYMMDD" release-date suffix Anthropic appends to a pinned release,
// capturing the id without it. The "claude" anchor is load-bearing: pricing
// looks every model up through this helper regardless of surface, and an
// operator may register a custom id with any shape at all, so an unanchored
// "-\d{8}$" would let "internal-llm-20250101" silently inherit the rate
// registered for "internal-llm". The anchor also covers the vendor-prefixed
// forms ("anthropic.claude-...", "us.anthropic.claude-...").
var anthropicDatedModel = regexp.MustCompile(`(?i)^(.*claude.*)-\d{8}$`)
// NormalizeAnthropicModel strips the trailing release-date suffix from a
// first-party Anthropic model id, e.g. "claude-sonnet-4-5-20250929" ->
// "claude-sonnet-4-5", so a dated id a client pins matches the undated one
// the operator registered. Callers try the verbatim id first and fall back
// to this, so two dated releases of the same family stay distinct wherever
// both are registered explicitly.
// Claude model id, e.g. "claude-sonnet-4-5-20250929" -> "claude-sonnet-4-5",
// so a dated id a client pins matches the undated one the operator
// registered. Ids that are not Claude-family are returned untouched.
// Callers try the verbatim id first and fall back to this, so two dated
// releases of the same family stay distinct wherever both are registered
// explicitly.
func NormalizeAnthropicModel(modelID string) string {
return anthropicDateSuffix.ReplaceAllString(modelID, "")
return anthropicDatedModel.ReplaceAllString(modelID, "$1")
}
// NormalizeVertexModel strips the "@version" suffix from a Vertex AI model id