Skip to content

Anthropic Token Counting - #1749

Merged
TimPansino merged 3 commits into
mainfrom
feat-anthropic-token-counting
Jun 11, 2026
Merged

Anthropic Token Counting#1749
TimPansino merged 3 commits into
mainfrom
feat-anthropic-token-counting

Conversation

@TimPansino

Copy link
Copy Markdown
Contributor

Overview

  • Add token counting to Anthropic SDK for all LLM invocations.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ ACTION actionlint 9 0 0 1.13s
✅ MARKDOWN markdownlint 7 0 0 0 1.47s
✅ PYTHON ruff 1039 0 0 0 1.19s
✅ PYTHON ruff-format 1039 0 0 0 0.38s
✅ YAML prettier 23 0 0 0 1.82s
✅ YAML v8r 23 0 0 6.81s
✅ YAML yamllint 23 0 0 0.8s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@codecov-commenter

codecov-commenter commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.75000% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.03%. Comparing base (0699eca) to head (7ff997b).

Files with missing lines Patch % Lines
newrelic/hooks/mlmodel_anthropic.py 68.75% 4 Missing and 6 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1749   +/-   ##
=======================================
  Coverage   82.03%   82.03%           
=======================================
  Files         215      215           
  Lines       26417    26445   +28     
  Branches     4171     4177    +6     
=======================================
+ Hits        21670    21695   +25     
+ Misses       3324     3320    -4     
- Partials     1423     1430    +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TimPansino
TimPansino marked this pull request as ready for review June 2, 2026 22:26
@TimPansino
TimPansino requested a review from a team as a code owner June 2, 2026 22:26
@mergify mergify Bot added tests-failing Tests failing in CI. and removed tests-failing Tests failing in CI. labels Jun 8, 2026
Comment thread newrelic/hooks/mlmodel_anthropic.py Outdated
)
)
if input_message_content:
response_prompt_tokens = token_count_callback(request_model, input_message_content)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should put the token count callback invocations inside of a specific try-except block so we can log out an error message with details if the customer's callback function failed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an error message for this.

@TimPansino
TimPansino force-pushed the feat-anthropic-token-counting branch from 0935fc6 to 7ff997b Compare June 11, 2026 17:12
@TimPansino
TimPansino merged commit 1f2b421 into main Jun 11, 2026
70 of 72 checks passed
@TimPansino
TimPansino deleted the feat-anthropic-token-counting branch June 11, 2026 17:53
@hmstepanek hmstepanek added this to the v13.2.0 milestone Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants