Skip to content

Conversation

@rtfeldman
Copy link
Contributor

@rtfeldman rtfeldman commented Dec 16, 2025

Closes #38533

Screenshot 2025-12-16 at 2 32 21 PM

Release Notes:

  • Use up-to-date token counts from LLM responses when reporting tokens used per thread
This change addresses token count inaccuracy by using Anthropic's dedicated
token counting API instead of GPT-4's tiktoken tokenizer.

Changes:
- Add count_tokens API support in anthropic crate
- Update AnthropicModel to use API with tiktoken fallback
- Add tokens_before_message helper for cached token baseline
- Add comprehensive tests for token counting functionality

The Anthropic API provides accurate token counts for Claude models,
with tiktoken as fallback for network issues or cloud/copilot providers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 16, 2025
@rtfeldman rtfeldman force-pushed the rtfeldman/token-count-accuracy branch 2 times, most recently from 0f2ce43 to c881341 Compare December 16, 2025 14:21
@rtfeldman rtfeldman marked this pull request as ready for review December 16, 2025 14:24
@rtfeldman rtfeldman marked this pull request as draft December 16, 2025 14:25
@rtfeldman rtfeldman force-pushed the rtfeldman/token-count-accuracy branch from edc8d21 to 7350962 Compare December 16, 2025 14:26
@rtfeldman rtfeldman marked this pull request as ready for review December 16, 2025 18:52
@rtfeldman rtfeldman merged commit d16619a into main Dec 16, 2025
23 checks passed
@rtfeldman rtfeldman deleted the rtfeldman/token-count-accuracy branch December 16, 2025 19:32
HactarCE pushed a commit that referenced this pull request Dec 17, 2025
Closes #38533

<img width="807" height="425" alt="Screenshot 2025-12-16 at 2 32 21 PM"
src="https://github.com/user-attachments/assets/6ebb915c-91d3-4158-a2b9-9fe17d301dd6"
/>


Release Notes:

- Use up-to-date token counts from LLM responses when reporting tokens
used per thread

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
)

Closes zed-industries#38533

<img width="807" height="425" alt="Screenshot 2025-12-16 at 2 32 21 PM"
src="https://github.com/user-attachments/assets/6ebb915c-91d3-4158-a2b9-9fe17d301dd6"
/>


Release Notes:

- Use up-to-date token counts from LLM responses when reporting tokens
used per thread

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
)

Closes zed-industries#38533

<img width="807" height="425" alt="Screenshot 2025-12-16 at 2 32 21 PM"
src="https://github.com/user-attachments/assets/6ebb915c-91d3-4158-a2b9-9fe17d301dd6"
/>


Release Notes:

- Use up-to-date token counts from LLM responses when reporting tokens
used per thread

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

2 participants