fix: 拦截 1M 上下文窗口请求,避免不支持的账户被误标记为限流

当客户端使用 [1m] 模型时,请求会携带 anthropic-beta: context-1m 头。
部分账户订阅(如 Max)不支持 1M 上下文,上游返回 429 后系统会误将
账户标记为限流,导致后续所有请求被拦截。

现在在路由层直接检测 context-1m beta header,返回 403 提示用户
切换模型,不转发请求、不触发限流标记。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yuanhaitao
2026-02-25 23:27:53 +08:00
parent 5d0c8144dd
commit 81c7a207f3

View File

@@ -189,6 +189,17 @@ async function handleMessagesRequest(req, res) {
}
}
// 拦截 1M 上下文窗口请求anthropic-beta 包含 context-1m
const betaHeader = (req.headers['anthropic-beta'] || '').toLowerCase()
if (betaHeader.includes('context-1m')) {
return res.status(403).json({
error: {
type: 'forbidden',
message: '暂不支持 1M 上下文窗口,请切换为非 [1m] 模型'
}
})
}
logger.api('📥 /v1/messages request received', {
model: req.body.model || null,
forcedVendor,