fix(gateway): claude_code_only 不再误拦截官方 Claude Code 的 count_tokens 与非流式 messages 请求#2919
Open
wucm667 wants to merge 1 commit into
Open
fix(gateway): claude_code_only 不再误拦截官方 Claude Code 的 count_tokens 与非流式 messages 请求#2919wucm667 wants to merge 1 commit into
wucm667 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
开启
claude_code_only后,/v1/messages/count_tokens因路径包含messages会进入 Claude Code messages 严格校验。官方 Claude Code CLI 的 count_tokens 辅助请求通常不携带完整 system prompt 或metadata.user_id,导致账号选择阶段误判为非 Claude Code 客户端。issue 中还提到部分
stream=false /v1/messages请求,但当前没有提供可稳定区分的真实请求样本。为避免第三方客户端仅伪造 UA 就绕过普通 messages 主路径校验,本 PR 不额外放宽普通/v1/messages。改动
/messages/count_tokens路径新增 Claude Code UA-only 放行,和非 messages 路径保持一致。/v1/messages的 system prompt、X-App、anthropic-beta、anthropic-version、metadata.user_id严格校验。max_tokens=1+ Haiku 探测请求 bypass 行为不变。测试
go test -tags=unit ./...golangci-lint run ./...Fixes #2909