Open
Description
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.
Metadata
Metadata
Assignees
Labels
New feature or requestNew feature or request