fix(gateway): strip Anthropic fallbacks unless server-side-fallback beta is present

Clients now send body.fallbacks; upstream rejects it without
anthropic-beta: server-side-fallback-2026-07-01. Mirror the
context_management sanitize so OAuth mimic / default API-key
beta paths no longer 400 with "fallbacks: Extra inputs are not permitted".
This commit is contained in:
alfadb
2026-09-01 14:23:33 +08:00
parent a2fb09260a
commit 200b1406d7
4 changed files with 404 additions and 14 deletions
+11
View File
@@ -25,6 +25,17 @@ const (
BetaRedactThinking = "redact-thinking-2026-02-12"
BetaContextManagement = "context-management-2025-06-27"
BetaExtendedCacheTTL = "extended-cache-ttl-2025-04-11"
// server-side refusal fallback beta 字段族(beta Messages API 专有)。
// 客户端(Claude Code / SDK / OpenCode 等)会默认透传 body.fallbacks /
// body.fallback_credit_token,上游仅在 anthropic-beta 携带对应 token 时接受;
// 缺 token 时 Pydantic 拒收:"fallbacks: Extra inputs are not permitted"。
// 仅用于 sanitize 的条件判断(strip-or-keep),禁止加入
// FullClaudeCodeMimicryBetas / DefaultBetaHeader / APIKeyBetaHeader /
// Bedrock 白名单:server-side fallback 会换模型、改计费,不能默认打开。
BetaServerSideFallback = "server-side-fallback-2026-07-01"
BetaFallbackCredit = "fallback-credit-2026-07-01"
BetaFallbackCreditLegacy = "fallback-credit-2026-06-01"
)
// DroppedBetas 是转发时需要从 anthropic-beta header 中移除的 beta token 列表。