fix: strip x-anthropic-billing-header to fix vLLM prefix caching#28
Merged
Merged
Conversation
Claude Code injects a per-turn `x-anthropic-billing-header: ...; cch=<hash>` line into the system prompt text. The cch hash changes every turn, making the system prompt differ between requests and collapsing vLLM/OpenAI-compatible prefix cache hit rates. Strip this line in anthropicSystemPromptToText, the single choke point on the Anthropic->OpenAI translation path. Native Anthropic passthrough and GCP/AWS Anthropic backends are unaffected, where the header is legitimate. Claude-Session: https://claude.ai/code/session_01QrCxVdawaDk3sd89zzT3a2
Code Review — PR #28
To review PR comments and correctly patch the sticky comment please use this skill https://raw.githubusercontent.com/blackfuel-ai/code-review/main/skills/assess-pr-comments/SKILL.md. |
There was a problem hiding this comment.
Code review passed.
Both Major findings describe non-deterministic map iteration, which affects testing/config stability but does not present a risk of downtime, data corruption, data leak, or a security weakness. The Minor findings are advisory by criteria. These issues appear to be pre-existing code quality concerns rather than risks introduced by this PR.
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.
Summary
x-anthropic-billing-headerline from the system prompt on the Anthropic→OpenAI translation path, to fix vLLM/OpenAI-compatible prefix caching.Problem
Claude Code injects
x-anthropic-billing-header: cc_version=...; cch=<hash>as a line inside the system prompt text (it's not an HTTP header, despite the name). Thecch(conversation context hash) changes on every turn, making the ~31k-token system prompt differ between requests. This breaks vLLM's prefix cache for the entire prompt.Observed in the upstream claudish proxy (MadAppGang/claudish#101): per-request
cached_tokenswas stuck at ~48/31k (0.15%) and rose to ~99.9% after stripping the line.Fix
anthropicSystemPromptToText(internal/translator/openai_helper.go) is the single choke point where the Anthropic system prompt is flattened to a string for OpenAI-compatible backends. A line-anchored regex strips the header there:This is scoped to the OpenAI-compatible path only — native Anthropic passthrough and GCP/AWS Anthropic backends don't route through this function, so the header is preserved where it's legitimate for billing.
Tests
go test ./internal/translator/ -run TestAnthropicSystemPromptToText -v— passes, including a regression guard asserting two prompts differing only bycch=produce identical output.go test ./internal/translator/...— passes.go build ./...— clean.🤖 Generated with Claude Code