Skip to content

Comments

Feat: 💰 Track cost in Usage value object#920

Open
vinitkadam03 wants to merge 1 commit intoprism-php:mainfrom
vinitkadam03:feat/track-usage-cost
Open

Feat: 💰 Track cost in Usage value object#920
vinitkadam03 wants to merge 1 commit intoprism-php:mainfrom
vinitkadam03:feat/track-usage-cost

Conversation

@vinitkadam03
Copy link
Contributor

Description

Track cost in Usage value object. Some providers like OpenRouter return the cost of a request in their usage response. This adds a nullable float $cost property to Usage so that cost data can be captured when available, while remaining null for providers that don't report it.

Changes:

  • Added ?float $cost = null to Usage value object and its toArray() output
  • Updated Text\ResponseBuilder and Structured\ResponseBuilder to aggregate cost across steps
  • Updated StreamState::addUsage() to accumulate cost during streaming
  • Updated StreamEndEvent::toArray() to delegate to Usage::toArray() instead of inlining fields
  • Updated OpenRouter Text, Structured, and Stream handlers to extract usage.cost from API responses
  • Added UsageTest and updated existing tests for ResponseBuilders, StreamState, StreamEndEvent, and BroadcastAdapter

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.

1 participant