Skip to content

RunResult missing .usage property for token usage tracking #1487

@usman-naseem

Description

@usman-naseem

Summary

The RunResult object currently does not include the .usage property, making it difficult to track token usage directly from the result. This property is expected based on OpenAI API responses but is missing in the Agents SDK.

Steps to Reproduce

  1. Create a simple agent run with any supported model.
  2. Inspect the returned RunResult object.
  3. Notice that .usage is not available, even though the API response contains usage data.
result = agent.run("Hello")
print(result.usage)  # AttributeError: 'RunResult' object has no attribute 'usage'


###Expected Behavior

The RunResult object should include a .usage attribute that reflects the token usage data from the API response, similar to how the Python API client exposes it.

###Actual Behavior

The .usage attribute is missing, requiring developers to manually parse raw responses to get token usage.

### Possible Solution

- Update the RunResult class to store the usage field from the API response.
- 
- Ensure .usage is directly accessible.
- 
- Add unit tests verifying .usage is populated correctly.
- 

### Environment

- openai-agents-python version: 0.2.0
- 
- Python version: 3.11.9
- 
- OS: Windows 11 Pro 23H2 (Build 22631)
- Additional Context

**This change would simplify token tracking and improve developer experience by matching behavior of other OpenAI SDKs.**

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions