Skip to content

Handle structured token usage details#1680

Open
AgenticSpark wants to merge 1 commit into
openai:mainfrom
AgenticSpark:agenticspark/fix-token-usage-details
Open

Handle structured token usage details#1680
AgenticSpark wants to merge 1 commit into
openai:mainfrom
AgenticSpark:agenticspark/fix-token-usage-details

Conversation

@AgenticSpark

Copy link
Copy Markdown

Fixes #1582.

Token usage aggregation now converts OpenAI SDK usage objects into mappings and only sums numeric fields. Numeric nested detail fields such as completion_tokens_details.reasoning_tokens are included under flattened usage_* result keys, so final reporting no longer raises when structured usage details are present.

Tested with:
uv run --no-project --with pytest --with blobfile --with openai --with tiktoken --with pyyaml --with pandas --with numpy --with snowflake-connector-python --with beartype --with requests --with filelock --with tqdm --with typing-extensions --with lz4 --with zstandard --with backoff pytest evals\\cli\\oaieval_test.py -q

Flatten numeric fields from OpenAI SDK usage detail objects before summing token usage, so final reporting no longer raises when completion_tokens_details is present.

Tested with: uv run --no-project --with pytest --with blobfile --with openai --with tiktoken --with pyyaml --with pandas --with numpy --with snowflake-connector-python --with beartype --with requests --with filelock --with tqdm --with typing-extensions --with lz4 --with zstandard --with backoff pytest evals\\cli\\oaieval_test.py -q

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

TypeError: unsupported operand type(s) for +: 'int' and 'CompletionTokensDetail

1 participant