Skip to content

Commit 6e65058

Browse files
cursoragentclaude
andcommitted
Fix: Use elif to prevent streaming token usage override
Changed the second if statement to elif in _calculate_completions_token_usage to ensure that streaming_message_token_usage takes precedence over response.usage. This prevents valid streaming usage data from being silently overwritten when response has a usage attribute. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent d1ae0b2 commit 6e65058

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

sentry_sdk/integrations/openai.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ def _calculate_completions_token_usage(
164164

165165
if streaming_message_token_usage:
166166
usage = streaming_message_token_usage
167-
168-
if hasattr(response, "usage"):
167+
elif hasattr(response, "usage"):
169168
usage = response.usage
170169

171170
if usage is not None:

0 commit comments

Comments
 (0)