fix: properly wrap Vertex AI beta streaming responses #1021
+332
−4
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
Fixes tool input parameters being lost when using Claude models via Vertex AI with streaming enabled. The Vertex AI beta messages implementation was returning plain
Streamobjects instead ofBetaMessageStreamManager, bypassing the event accumulation logic entirely.Closes #1020
Problem
When using the beta messages API with Vertex AI and streaming enabled (
stream=True), tool calls fail with validation errors because tool inputs remain empty{}.The root cause:
FirstPartyMessagesAPI.createStreaminstead ofBetaMessageStreamManagerBetaMessageStreamwas never reachedinput_json_deltaevents, but they weren't being accumulatedSolution
This PR overrides the
create()andstream()methods in/src/anthropic/lib/vertex/_beta_messages.pyto ensure:create()method wrapsStreaminBetaMessageStreamwhenstream=Truestream()method returnsBetaMessageStreamManagerfor proper event accumulationinput_json_deltaevents as intendedChanges Made
src/anthropic/lib/vertex/_beta_messages.py:Messages.create()to wrapStreaminBetaMessageStreamwhen streamingMessages.stream()to returnBetaMessageStreamManagerAsyncMessages.create()to wrapAsyncStreaminBetaAsyncMessageStreamwhen streamingAsyncMessages.stream()to returnBetaAsyncMessageStreamManagerBetaMessageStreamandBetaAsyncMessageStreamTesting
Manual Testing
Automated Tests
Test Output
Impact
Verification Checklist
pytest tests/lib/test_vertex.py)ruff check)Related Context
Example Usage After Fix