refactor(openai): Split token counting by API for easier deprecation#5930
1 issue
code-review: Found 1 issue (1 medium)
Medium
Missing manual output token counting for non-streaming Responses API - `sentry_sdk/integrations/openai.py:291-295`
_calculate_responses_token_usage only manually counts output tokens when streaming_message_responses is provided (lines 292-295). Unlike _calculate_completions_token_usage which falls back to counting from response.choices (lines 220-223), this function lacks equivalent logic to extract and count tokens from response.output. For non-streaming Responses API calls that don't include usage data, output tokens will remain 0.
Duration: 1m 59s · Tokens: 951.5k in / 9.2k out · Cost: $1.31 (+extraction: $0.00)
Annotations
Check warning on line 295 in sentry_sdk/integrations/openai.py
sentry-warden / warden: code-review
Missing manual output token counting for non-streaming Responses API
`_calculate_responses_token_usage` only manually counts output tokens when `streaming_message_responses` is provided (lines 292-295). Unlike `_calculate_completions_token_usage` which falls back to counting from `response.choices` (lines 220-223), this function lacks equivalent logic to extract and count tokens from `response.output`. For non-streaming Responses API calls that don't include usage data, output tokens will remain 0.