[codex] Improve proxy Anthropic token counting#127
Draft
konradciok wants to merge 1 commit intochopratejas:mainfrom
Draft
[codex] Improve proxy Anthropic token counting#127konradciok wants to merge 1 commit intochopratejas:mainfrom
konradciok wants to merge 1 commit intochopratejas:mainfrom
Conversation
Owner
|
Hi - thank you for these changes - they look good - can you resolve merge conflicts and resubmit the 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.
What changed
This PR improves proxy-side Anthropic token counting by passing an optional Anthropic SDK client into
AnthropicProviderwhenANTHROPIC_API_KEYis available.It also:
anthropicto theproxyextra so the accurate counting path is available in proxy installslitellmpin to>=1.82.6,<2headroomis onPATHlangchainextra used by full test runsWhy
The proxy currently initializes
AnthropicProvider()without an SDK client, which forces approximate token counting for Claude models even when the API key is available. This change opts into the more accurate Anthropiccount_tokenspath when possible while preserving the existing fallback behavior for OpenAI-only installs.Impact
ANTHROPIC_API_KEYis unset or the SDK is unavailableValidation
Passed:
pytest tests/test_cli/test_mcp.pypytest tests/test_proxy_count_tokens_integration.py tests/test_providers/test_anthropic.py -qRepo pre-push hook also ran full
pytest -q, but it failed in unrelated areas outside this diff:tests/test_integrations/langchain/test_langchain_live.py(langchain_openai/langchain_anthropicmissing)tests/test_memory_usage_integration.pytests/test_proxy_memory_integration.py