fix: properly wrap Vertex AI beta streaming responses#1021
Closed
matthicksj wants to merge 1 commit intoanthropics:mainfrom
Closed
fix: properly wrap Vertex AI beta streaming responses#1021matthicksj wants to merge 1 commit intoanthropics:mainfrom
matthicksj wants to merge 1 commit intoanthropics:mainfrom
Conversation
Fixes tool input parameters being lost when using Claude models via Vertex AI with streaming enabled. Both create(stream=True) and stream() methods now properly handle event accumulation. The Vertex beta messages implementation was returning plain Stream objects instead of BetaMessageStream/BetaMessageStreamManager, bypassing the event accumulation logic entirely. This fix overrides create() and stream() methods in /src/anthropic/lib/vertex/_beta_messages.py to: - Wrap create(stream=True) responses in BetaMessageStream - Return BetaMessageStreamManager from stream() - Apply same fixes to async implementations Fixes #1020
justinlietz93
pushed a commit
to justinlietz93/anthropic-sdk-python
that referenced
this pull request
Sep 1, 2025
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
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