Skip to content

Add response cost in the Usage #683

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
RVV-karma opened this issue May 12, 2025 · 1 comment · May be fixed by #682
Open

Add response cost in the Usage #683

RVV-karma opened this issue May 12, 2025 · 1 comment · May be fixed by #682
Labels
enhancement New feature or request

Comments

@RVV-karma
Copy link

Feature Request: Add Response Cost Tracking to Usage Class

This feature introduces a new attribute, response_cost, to the Usage class to enable tracking of the total cost incurred from API responses. This addition enhances observability and cost management for developers using the OpenAI Agents SDK by making cost metrics available alongside existing usage metrics such as request count and token usage.

How it works:

  • A new field, response_cost: float = 0.0, is added to the Usage dataclass.
  • The add() method has been updated to correctly accumulate the response_cost from another Usage instance.
  • This allows developers to easily aggregate and monitor financial cost metrics in tandem with usage data.

Example:

usage_1 = Usage(requests=1, input_tokens=100, output_tokens=200, total_tokens=300, response_cost=0.012)
usage_2 = Usage(requests=2, input_tokens=150, output_tokens=250, total_tokens=400, response_cost=0.015)

usage_1.add(usage_2)

# usage_1 now reflects:
# requests: 3
# input_tokens: 250
# output_tokens: 450
# total_tokens: 700
# response_cost: 0.027

This addition is useful for developers needing cost-aware usage insights for budgeting, reporting, or scaling decisions.

@RVV-karma RVV-karma added the enhancement New feature or request label May 12, 2025
@RVV-karma
Copy link
Author

PR - #682

@RVV-karma RVV-karma linked a pull request May 12, 2025 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant