fix(bedrock): add missing stream() method to beta.messages#1246
Open
passionworkeer wants to merge 10 commits intoanthropics:mainfrom
Open
fix(bedrock): add missing stream() method to beta.messages#1246passionworkeer wants to merge 10 commits intoanthropics:mainfrom
passionworkeer wants to merge 10 commits intoanthropics:mainfrom
Conversation
The Bedrock Messages class was missing the stream() method that exists in the first-party Messages class. This causes code using client.beta.messages.stream() to break when switching from Anthropic() to AnthropicBedrock(). Added stream = FirstPartyMessagesAPI.stream to both Messages and AsyncMessages classes. Closes anthropics#1210
There was a problem hiding this comment.
Pull request overview
Adds the missing stream() convenience method to the Bedrock beta messages resource to match the first-party SDK surface area and prevent breakage when switching from Anthropic() to AnthropicBedrock().
Changes:
- Expose
Messages.streamby aliasingFirstPartyMessagesAPI.streamin the Bedrock beta messages resource. - Expose
AsyncMessages.streamby aliasingFirstPartyAsyncMessagesAPI.streamin the Bedrock beta messages resource.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| class Messages(SyncAPIResource): | ||
| create = FirstPartyMessagesAPI.create | ||
| stream = FirstPartyMessagesAPI.stream |
Add a parametrized test that verifies beta.messages.stream exists and has the same signature as beta.messages.create for both sync and async clients. This ensures code using client.beta.messages.stream() works when switching from Anthropic() to AnthropicBedrock(), addressing Copilot review feedback. Closes anthropics#1210
Add test_bedrock_beta_messages_stream_exists() to ensure AnthropicBedrock().beta.messages.stream (and async) exists and is callable. This prevents regression of the missing stream() method on Bedrock beta messages resource. Co-authored-by: TRIX <trix@openclaw>
The @pytest.mark.parametrize("profiles, aws_profile", ...) decorator was
accidentally placed before test_bedrock_beta_messages_stream_exists()
when the test was inserted. This caused pytest to pass profiles/aws_profile
args to a function that accepts none, triggering a test collection error.
Move the decorator to test_region_infer_from_specified_profile() where it
belongs.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove unused BetaMessageStream and BetaAsyncMessageStream imports. Auto-fix isort import order via ruff --fix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t pattern
The Bedrock async beta.messages.stream() previously aliased
FirstPartyAsyncMessagesAPI.stream, which returns a
BetaAsyncMessageStreamManager wrapping an unawaited coroutine.
Because AsyncAPIResource._post is async, the coroutine must be
awaited inside the async with block (when respx mocks are active).
This commit introduces:
- _DeferredAsyncStreamRequest(Awaitable): defers the HTTP call to
inside BetaAsyncMessageStreamManager.__aenter__, ensuring respx
mocks are active when the request fires.
- AsyncMessages.stream(): own implementation mirroring the first-
party signature exactly, using _DeferredAsyncStreamRequest.
- SyncMessages.stream: unchanged alias of FirstPartyMessagesAPI.stream.
- Full type annotations matching the generated first-party SDK.
- Comprehensive regression tests covering:
- Existence and callability of stream() on sync and async clients
- Correct return type (BetaMessageStreamManager /
BetaAsyncMessageStreamManager)
- Context manager protocol (sync __enter__/__exit__,
async __aenter__/__aexit__)
- Stream interface members (text_stream, response,
get_final_message, etc.)
- Wrapper parity (no stream on with_raw_response or
with_streaming_response)
- Method signature parity with first-party SDK
- Return type annotation verification
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ager type Add isinstance checks for BetaMessageStreamManager (sync) and BetaAsyncMessageStreamManager (async) so tests enforce stream manager parity, not just AbstractContextManager/AbstractAsyncContextManager. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
The Bedrock Messages class was missing the stream() method that exists in the first-party Messages class. This causes code using client.beta.messages.stream() to break when switching from Anthropic() to AnthropicBedrock().
Added stream = FirstPartyMessagesAPI.stream to both Messages and AsyncMessages classes.
Closes #1210