PR to enhance the `Usage` object and related logic, to support more granular token accounting, matching the details available in the [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses) . Specifically, it: - Adds `input_tokens_details` and `output_tokens_details` fields to the `Usage` dataclass, storing detailed token breakdowns (e.g., `cached_tokens`, `reasoning_tokens`). - Flows this change through - Updates and extends tests to match - Adds a test for the Usage.add method ### Motivation - Aligns the SDK’s usage with the latest OpenAI responses API Usage object - Supports downstream use cases that require fine-grained token usage data (e.g., billing, analytics, optimization) requested by startups --------- Co-authored-by: Wulfie Bain <wulfie@openai.com> |
||
|---|---|---|
| .. | ||
| fastapi | ||
| mcp | ||
| model_settings | ||
| models | ||
| tracing | ||
| voice | ||
| __init__.py | ||
| conftest.py | ||
| fake_model.py | ||
| README.md | ||
| test_agent_config.py | ||
| test_agent_hooks.py | ||
| test_agent_runner.py | ||
| test_agent_runner_streamed.py | ||
| test_agent_tracing.py | ||
| test_cancel_streaming.py | ||
| test_computer_action.py | ||
| test_config.py | ||
| test_doc_parsing.py | ||
| test_extension_filters.py | ||
| test_extra_headers.py | ||
| test_function_schema.py | ||
| test_function_tool.py | ||
| test_function_tool_decorator.py | ||
| test_global_hooks.py | ||
| test_guardrails.py | ||
| test_handoff_tool.py | ||
| test_items_helpers.py | ||
| test_max_turns.py | ||
| test_openai_chatcompletions.py | ||
| test_openai_chatcompletions_converter.py | ||
| test_openai_chatcompletions_stream.py | ||
| test_openai_responses_converter.py | ||
| test_output_tool.py | ||
| test_pretty_print.py | ||
| test_responses.py | ||
| test_responses_tracing.py | ||
| test_result_cast.py | ||
| test_run_config.py | ||
| test_run_step_execution.py | ||
| test_run_step_processing.py | ||
| test_strict_schema.py | ||
| test_tool_choice_reset.py | ||
| test_tool_converter.py | ||
| test_tool_use_behavior.py | ||
| test_trace_processor.py | ||
| test_tracing.py | ||
| test_tracing_errors.py | ||
| test_tracing_errors_streamed.py | ||
| test_usage.py | ||
| test_visualization.py | ||
| testing_processor.py | ||
Tests
Before running any tests, make sure you have uv installed (and ideally run make sync after).
Running tests
make tests
Snapshots
We use inline-snapshots for some tests. If your code adds new snapshot tests or breaks existing ones, you can fix/create them. After fixing/creating snapshots, run make tests again to verify the tests pass.
Fixing snapshots
make snapshots-fix
Creating snapshots
make snapshots-update