feat: support openrouter usage in api #1055
Merged
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.
Author Description
OpenRouter recently added an api parameter to get the cost of the request in the responses:
https://openrouter.ai/docs/use-cases/usage-accounting
This PR introduces the following changes:
usage
parameter in the request body (enable cost report)usage
format (described here)usage
in the non-streaming response (we already do that in the streaming responses)Description
🔄 What Changed
This PR adds support for OpenRouter's usage accounting feature by implementing the following changes:
usage
parameter to the request configurationOpenrouterUsageDetails
to properly type the usage data format🔍 Impact of the Change
This enhancement allows users to receive detailed cost and token usage information from OpenRouter API calls, including cost reporting and detailed token usage breakdowns.
📁 Total Files Changed
1 file modified:
src/providers/openrouter/chatComplete.ts
(+23, -15)🧪 Test Added
N/A - No tests were added in this PR
🔒 Security Vulnerabilities
No security vulnerabilities identified
Motivation
OpenRouter recently added an API parameter to get the cost of the request in the responses, as documented in their usage accounting documentation. This PR implements support for this feature to provide users with detailed usage information.
Type of Change
How Has This Been Tested?
Screenshots (if applicable)
N/A
Checklist
Related Issues
Related to OpenRouter's usage accounting feature: https://openrouter.ai/docs/use-cases/usage-accounting
Quality Recommendations
Add unit tests to verify the new usage parameter functionality
Add validation for the usage parameter to ensure it's a boolean value
Add documentation comments for the new OpenrouterUsageDetails interface
Consider adding examples of how to use the new usage parameter in the code comments