Skip to content

fix anthropic usage object to follow openai format for usage object#1484

Closed
narengogi wants to merge 1 commit into
Portkey-AI:mainfrom
narengogi:fix/anthropic-usage
Closed

fix anthropic usage object to follow openai format for usage object#1484
narengogi wants to merge 1 commit into
Portkey-AI:mainfrom
narengogi:fix/anthropic-usage

Conversation

@narengogi

Copy link
Copy Markdown
Member

Description: (required)

  • The anthropic usage object is not compliant with the openai format, this PR fixes it

Type of Change:

  • Bug fix (non-breaking change which fixes an issue)

Copilot AI 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.

Pull request overview

This PR fixes the Anthropic usage object structure to align with OpenAI's format. The primary issue was incorrect token calculation where cache tokens were being added to total_tokens instead of being included in prompt_tokens.

Key Changes:

  • Corrected token calculation logic to include cache tokens in prompt_tokens rather than total_tokens
  • Simplified streaming usage handling by removing redundant state management
  • Improved code maintainability by extracting token calculations into separate variables

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/providers/anthropic/chatComplete.ts
Comment thread src/providers/anthropic/chatComplete.ts
@narengogi narengogi marked this pull request as draft December 24, 2025 13:37
@narengogi narengogi closed this Jan 12, 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.

2 participants