feat(ai-rate-limiting): expose nested usage fields to cost_expr - #13984
Merged
shreemaan-abhishek merged 4 commits intoSep 28, 2026
Merged
shreemaan-abhishek merged 4 commits into
shreemaan-abhishek merged 4 commits into
Conversation
nic-6443
reviewed
Sep 24, 2026
| end | ||
|
|
||
|
|
||
| -- expose usage leaves by bare name, breadth first so shallower keys win |
Member
There was a problem hiding this comment.
Explicit usage similar to input_tokens_details.cached_tokens needs to be supported to avoid ambiguity when duplicate field names exist in nested data.
nic-6443
approved these changes
Sep 24, 2026
AlinsRan
approved these changes
Sep 28, 2026
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.
Description
Some LLM APIs report parts of usage in nested objects. The OpenAI Responses API puts
cached_tokensunderinput_tokens_detailsandreasoning_tokensunderoutput_tokens_details:cost_expronly saw top-level numbers, so these fields read as 0 and could not be priced.This PR exposes nested numeric usage fields to
cost_exprby joining the parent and child keys with__:prompt_tokens_details__cached_tokens_details__text_tokens.audio_tokensisprompt_tokens_details__audio_tokensorcompletion_tokens_details__audio_tokens.__is used because usage keys already contain single underscores, so the parent/child boundary stays visible.Tests: TEST 14-28 in
t/plugin/ai-rate-limiting-expression.t, with new fixturesopenai/responses-usage-clash.json,openai/chat-usage-audio.jsonandopenai/chat-usage-deep.json. They cover joined names for OpenAI Responses (streaming and non-streaming), nested fields not bound by their bare name, a top-level field next to a nested field with the same name, sibling fields with the same leaf name, missing joined names, and two-level nesting with arrays skipped. Docs (en, zh) updated.Which issue(s) this PR fixes:
N/A
Checklist