Skip to content

refactor(openai): Split token counting by API for easier deprecation#5930

Merged
ericapisani merged 10 commits into
masterfrom
ep/py-2271-refactor-openai-token-counting-8y2
Apr 2, 2026
Merged

refactor(openai): Split token counting by API for easier deprecation#5930
ericapisani merged 10 commits into
masterfrom
ep/py-2271-refactor-openai-token-counting-8y2

Merge branch 'master' into ep/py-2271-refactor-openai-token-counting-8y2

e6cdb18
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden: code-review completed Apr 2, 2026 in 1m 59s

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

See this annotation in the file changed.

@sentry-warden 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.