Repository navigation
fix(bedrock): bill ConverseStream at the served tier - #52565
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
[Medium impact] The PR appears safe to merge. No new actionable issues were found.
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
1 similar comment
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5df1e04. Configure here.
Handwritten 1-3 sentence description
[insert handwritten description here]
Details
Link to Devin session: https://app.devin.ai/sessions/8c0c3e94ee8344b6b1aaf829d645165a
Open in Devin Desktop: https://app.devin.ai/desktop/session/8c0c3e94ee8344b6b1aaf829d645165a?variant=devin
Requested by: @kerry-berri
TLDR
Problem this solves:
How it solves it:
User Flow
Before, the proxy logs the default price for a Priority stream.
serviceTier.typeset topriority.After, the proxy logs the Priority price for the same stream.
Pre-Submission checklist
Screenshots / Proof of Fix
Both proxies used real AWS Bedrock in
us-east-1, two workers, and the same dedicated Redis. The chat stream now reports the served tier. Messages and Responses still return usage in their existing formats.Proxy config, startup, and client commands
Set
LITELLM_AUDIT_MASTER_KEYlocally and configure a Bedrock-capable AWS profile namedlitellm-dev. The Anthropic route is unused by this probe.proxy.yaml:probe.py:Observed before and after output
Before (4874a3c)
From
base checkout, withPORT=4334:Chat Completions
Native ConverseStream
Messages
Responses
After (5df1e04)
From the PR checkout, with the same Redis and proxy config. The rerun used the local QA Postgres environment. The proxy reloaded after the final code change.
.venv/bin/python -u ~/cost-audit/probe.py http://127.0.0.1:4333from the same checkout.Chat Completions
Native ConverseStream
Messages
Responses
Live chat stream shape before and after the review fix
I ran the same proxy setup above on the previously reviewed commit, using port 4334 and the PR checkout's Python environment. Both proxies used two workers. Run the probe against each address to count SSE frames.
probe-chunks.py:Before the review fix, at
4ea4eaccb91d3a7b6fe462199167fb01686f8bd0:At
5df1e0476e519df3f81494524be3a63aa8561c94:Live SDK assembled completion
Save this as
~/cost-audit/probe-assembled.pyand run these commands from each checkout with the same AWS profile.At the merge base, the async SDK raised the coroutine error below. The same error persisted at
266a2c810dfacdc86e564394cf2fe9ec1df1115a, where the sync SDK also lost the tier.After at
5df1e0476e519df3f81494524be3a63aa8561c94, sync and async respectively:AWS served the requested Priority tier. The sync and async regression test supplies Flex on a Priority request and checks the response and the Flex price. Before the async fix, its async case failed with the same coroutine error and its sync case passed.
The same regression tests failed on the base for both SDK modes and for passthrough billing, then passed on the fix. AWS returned the requested tier in the live runs. The SDK regression supplies a different served tier to verify that the served tier takes precedence.
Type
Bug fix
Final Attestation
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work
Note
Medium Risk
Changes Bedrock streaming usage chunks and completion assembly paths that drive billing and proxy cost logging; scope is provider-specific and well-tested.
Overview
Fixes Bedrock ConverseStream billing and tier metadata so costs follow the served
serviceTierfrom stream metadata (e.g. flex vs priority), not the default rate or a dropped tier.Streaming handler attaches
service_tierwhen usage arrives on Bedrock chunks, and on the final usage-only chunk records it internally instead of emitting an extra SSE frame with empty choices. Invoke handler mapsserviceTier.typefrom converse stream events onto responses via_with_served_service_tier.SDK
complete_responsepath skips chunk assembly when the stream result is still an awaitable, and for BedrockCustomStreamWrapperbuilds the full response from the wrapper’s accumulatedchunks(including async drain), preserving tier forstream_chunk_builderandcompletion_cost.New unit tests cover tier-priced streaming, assembled completions, and passthrough logging.
Reviewed by Cursor Bugbot for commit 5df1e04. Bugbot is set up for automated code reviews on this repo. Configure here.