Repository navigation
Conversation
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
Bedrock Converse ordinary responses and streaming metadata currently omit cache-read and cache-write tokens. Normalize both paths consistently with LiteLLM: add cache tokens to
prompt_tokens, expose the cache counters, include them in the fallback total, and preserve an explicit upstreamtotalTokensand raw usage. Support the InvokeModel cache counter aliases, giving canonical Converse fields precedence even when zero.For
inputTokens=10, cache reads of 20, cache writes of 30, andoutputTokens=8, prompt usage now reports 60 instead of 10, with both cache logging variables populated.Add 12 differential cases and end-to-end assertions for both response modes, preserving all existing test cases. Let the existing Bedrock mock select fixtures through
X-AI-Fixture.Validation:
prove -I. -v t/plugin/ai-proxy-bedrock-single.t: all 65 assertions pass locally.luacheck apisix/plugins/ai-protocols/bedrock-converse.lua t/lib/server.lua: no warnings or errors.3d526bfe3f6b9cbe06e80156d84d5d1aae5633e3: executed the source AST'sAmazonConverseConfig.transform_usageand cache-count methods with passive output containers. All 120 selected fields across 12 cases and both Lua response modes match. The Lua harness uses the realapisix.core.jsonmodule.The same fix was submitted to EE first: https://github.com/api7/api7-ee-3-gateway/pull/2331.
Which issue(s) this PR fixes:
Related: https://github.com/api7/api7-ee-3-gateway/issues/2323
Checklist