From ef26ce0fedc43477e9dc85c04a3b4d44ea010b08 Mon Sep 17 00:00:00 2001 From: kaiyuan Zhang Date: Wed, 12 Mar 2025 15:51:39 +0800 Subject: [PATCH] Fix token usage attribute names in stream_response for streamed outputs This PR fixes an issue in the streaming response processing where the code incorrectly accessed non-existent attributes (input_tokens and output_tokens) on the Usage object. Instead, the correct property names (prompt_tokens and completion_tokens) should be used. --- src/agents/run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agents/run.py b/src/agents/run.py index dfff7e389..bb3866401 100644 --- a/src/agents/run.py +++ b/src/agents/run.py @@ -651,8 +651,8 @@ async def _run_single_turn_streamed( usage = ( Usage( requests=1, - input_tokens=event.response.usage.input_tokens, - output_tokens=event.response.usage.output_tokens, + input_tokens=event.response.usage.prompt_tokens, + output_tokens=event.response.usage.completion_tokens, total_tokens=event.response.usage.total_tokens, ) if event.response.usage