feat: add cost and cost_details to ChatGenerationTokenUsage schema#66
Open
untilhamza wants to merge 1 commit intoOpenRouterTeam:mainfrom
Open
feat: add cost and cost_details to ChatGenerationTokenUsage schema#66untilhamza wants to merge 1 commit intoOpenRouterTeam:mainfrom
untilhamza wants to merge 1 commit intoOpenRouterTeam:mainfrom
Conversation
The OpenRouter API returns `cost`, `is_byok`, and `cost_details` in the `usage` object of chat completion responses, but the OpenAPI spec doesn't define these fields. This causes them to be silently dropped during deserialization. Adds the following optional/nullable fields to ChatGenerationTokenUsage: - `cost` (number) — total generation cost in USD - `is_byok` (boolean) — whether the request used bring-your-own-key - `cost_details` (object) — breakdown with upstream_inference_cost, upstream_inference_prompt_cost, upstream_inference_completions_cost Fixes OpenRouterTeam#65
Author
|
@mattapperson , @robert-j-y please take a look at this. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The OpenRouter API returns
cost,is_byok, andcost_detailsin theusageobject of chat completion responses, but the OpenAPI spec doesn't define these fields — so they're silently dropped duringmodel_dump().This PR adds the missing fields to
ChatGenerationTokenUsageinin.openapi.yaml.Fields added
costis_byokcost_details.upstream_inference_costcost_details.upstream_inference_prompt_costcost_details.upstream_inference_completions_costThe problem
Raw HTTP response includes cost data:
{ "usage": { "prompt_tokens": 158, "completion_tokens": 152, "total_tokens": 310, "cost": 8.41005e-05, "is_byok": false, "cost_details": { "upstream_inference_cost": 8.495e-05, "upstream_inference_prompt_cost": 8.95e-06, "upstream_inference_completions_cost": 7.6e-05 } } }But after the SDK deserializes via
model_dump(),costandcost_detailsare gone:Verification
I patched
ChatGenerationTokenUsagelocally to add these fields and confirmed cost data flows through correctly aftermodel_dump().Fixes #65