You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes an issue where OpenRouterResponses did not populate MessageMetrics.cost even when the OpenRouter Responses API returned cost information in the usage data.
The fix propagates the optional cost value from response_usage into MessageMetrics.cost while remaining compatible with usage objects that do not expose a cost attribute.
Type of change
Bug fix
New feature
Breaking change
Improvement
Model update
Other:
Checklist
Code complies with style guidelines
Ran format/validation scripts (./scripts/format.sh and ./scripts/validate.sh)
Self-review completed
Documentation updated (comments, docstrings)
Examples and guides: Relevant cookbook examples have been included or updated (if applicable)
Tested in clean environment
Tests added/updated (if applicable)
Duplicate and AI-Generated PR Check
I have searched existing open pull requests and confirmed that no other PR already addresses this issue
If a similar PR exists, I have explained below why this PR is a better approach
Check if this PR was entirely AI-generated (by Copilot, Claude Code, Cursor, etc.)
Additional Notes
Added regression coverage for cost values, missing cost attributes, and zero-cost responses.
No API or breaking changes.
No documentation or cookbook changes are required for this internal metrics fix.
Related issue: #9566
The PR propagates an optional Responses API usage cost into MessageMetrics for OpenRouter while preserving None and zero-cost behavior.
Adds cost extraction to the shared OpenAI Responses metrics conversion.
Adds OpenAI and OpenRouter unit coverage for populated, absent, and zero cost values.
The new coverage directly mocks the target attribute rather than validating its SDK-deserialized representation.
Confidence Score: 4/5
The PR appears safe to merge, with a non-blocking gap in regression-test fidelity around SDK deserialization of OpenRouter’s cost field.
The production assignment safely handles missing and zero cost values, but the tests do not establish that a real SDK-deserialized OpenRouter usage object exposes the provider-specific field through normal attribute access.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue where OpenRouterResponses did not populate MessageMetrics.cost even when the OpenRouter Responses API returned cost information in the usage data.
The fix propagates the optional cost value from response_usage into MessageMetrics.cost while remaining compatible with usage objects that do not expose a cost attribute.
Type of change
Checklist
./scripts/format.shand./scripts/validate.sh)Duplicate and AI-Generated PR Check
Additional Notes
Added regression coverage for cost values, missing cost attributes, and zero-cost responses.
No API or breaking changes.
No documentation or cookbook changes are required for this internal metrics fix.
Related issue: #9566