Conversation
Claude Code and other Anthropic-native clients send requests to POST /v1/messages instead of POST /v1/chat/completions. The previous is_chat gate only matched the OpenAI path, so every Anthropic-format request bypassed the compressor entirely (0 savings, 0 chat_requests in stats). Changes: - server.py: extend is_chat to also match paths ending in /messages, and compress the top-level "system" field (Anthropic-specific key not present in OpenAI format) - stats.py: count /messages requests as chat_requests in summary() The messages[] array structure is identical between the two APIs, so compress_messages() works without modification. The only Anthropic addition is the top-level "system" string, which is now piped through _compress_text() separately. Tested with Claude Code → aip-proxy → LiteLLM → GitHub Copilot API: before this patch, compressor.calls stayed at 0; after, it correctly tracks and compresses every chat request.
There was a problem hiding this comment.
Code Review
This pull request adds support for Anthropic's /messages endpoint and implements compression for the system prompt field. Feedback focuses on ensuring that compression statistics are correctly updated for the system field and standardizing the path-matching logic across the server and statistics modules to consistently handle query parameters and use precise matching.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.
Problem
Claude Code and other Anthropic-native clients send requests to
POST /v1/messagesinstead ofPOST /v1/chat/completions. Theis_chatgate only matched the OpenAI path, so every Anthropic-format request bypassed the compressor entirely —compressor.callsstays at 0 andchat_requestsnever increments despite traffic flowing through the proxy.Changes
server.pyis_chatto also match paths ending in/messages"system"string (Anthropic-specific field, not present in OpenAI format) via_compress_text()stats.py/messagesrequests aschat_requestsinsummary()Why it's safe
The
messages[]array structure is identical between the two APIs, socompress_messages()works without any modification. The only Anthropic addition is the top-level"system"string, handled separately. Non-Anthropic traffic (/chat/completions) is completely unaffected.Tested setup
compressor.callschat_requestssavings_pct/chat/completionstraffic