Skip to content

feat: add completion tokens details for anthropic models - #2199

Merged
nacx merged 6 commits into
envoyproxy:mainfrom
hustxiayang:completion-tokens-details
Jun 10, 2026
Merged

feat: add completion tokens details for anthropic models#2199
nacx merged 6 commits into
envoyproxy:mainfrom
hustxiayang:completion-tokens-details

Conversation

@hustxiayang

@hustxiayang hustxiayang commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description
Anthropic recently exposed the reasoning tokens via output_tokens_details: https://platform.claude.com/docs/en/api/python/messages/create. Thus we should also added this usage information for our users.

@hustxiayang
hustxiayang requested a review from a team as a code owner June 5, 2026 19:05
@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jun 5, 2026
Signed-off-by: yxia216 <yxia216@bloomberg.net>
@hustxiayang
hustxiayang force-pushed the completion-tokens-details branch from b347896 to 174a988 Compare June 5, 2026 19:08
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jun 5, 2026
@codecov-commenter

codecov-commenter commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.72%. Comparing base (1f4d197) to head (44c6a96).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2199   +/-   ##
=======================================
  Coverage   84.71%   84.72%           
=======================================
  Files         144      144           
  Lines       21161    21171   +10     
=======================================
+ Hits        17927    17937   +10     
  Misses       2152     2152           
  Partials     1082     1082           

☔ 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.

Signed-off-by: yxia216 <yxia216@bloomberg.net>
@hustxiayang

Copy link
Copy Markdown
Contributor Author

/gemini review

@hustxiayang hustxiayang changed the title feat: add completion tokens details feat: add completion tokens details for anthropic models Jun 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the Anthropic SDK dependency to v1.46.0 and introduces support for extracting and translating reasoning (thinking) tokens into OpenAI's CompletionTokensDetails.ReasoningTokens format for both streaming and non-streaming responses. Feedback on the changes points out potential nil pointer dereference panics in the AWS and GCP Anthropic translator tests when accessing CompletionTokensDetails directly, suggesting safe inline checks to handle cases where this field might be nil.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread internal/translator/openai_awsanthropic_test.go
Comment thread internal/translator/openai_gcpanthropic_test.go
@hustxiayang

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: yxia216 <yxia216@bloomberg.net>
@hustxiayang

Copy link
Copy Markdown
Contributor Author

@yuzisun @nacx @aabchoo Could you help to review this? Thanks a lot!

@nacx
nacx enabled auto-merge (squash) June 10, 2026 16:43
Signed-off-by: hustxiayang <yxia216@bloomberg.net>
@nacx
nacx merged commit 3d12ace into envoyproxy:main Jun 10, 2026
34 checks passed
hustxiayang added a commit to hustxiayang/ai-gateway that referenced this pull request Jun 12, 2026
…2199)

**Description**
Anthropic recently exposed the reasoning tokens via
`output_tokens_details`:
https://platform.claude.com/docs/en/api/python/messages/create. Thus we
should also added this usage information for our users.

---------

Signed-off-by: yxia216 <yxia216@bloomberg.net>
Co-authored-by: Ignasi Barrera <ignasi@tetrate.io>
Signed-off-by: yxia216 <yxia216@bloomberg.net>
hustxiayang added a commit to hustxiayang/ai-gateway that referenced this pull request Jun 16, 2026
…2199)

**Description**
Anthropic recently exposed the reasoning tokens via
`output_tokens_details`:
https://platform.claude.com/docs/en/api/python/messages/create. Thus we
should also added this usage information for our users.

---------

Signed-off-by: yxia216 <yxia216@bloomberg.net>
Co-authored-by: Ignasi Barrera <ignasi@tetrate.io>
Signed-off-by: yxia216 <yxia216@bloomberg.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants