anthropic-sdk-python icon indicating copy to clipboard operation
anthropic-sdk-python copied to clipboard

Bedrock beta.messages missing .stream() method

Open afoong-8s opened this issue 9 months ago • 4 comments

Summary

AnthropicBedrock().beta.messages exposes .create() but not .stream(). The first-party Anthropic().beta.messages has both.

Root cause

In src/anthropic/lib/bedrock/_beta_messages.py, the Bedrock Messages class only copies create:

class Messages(SyncAPIResource):
    create = FirstPartyMessagesAPI.create
    # stream is missing

The first-party class in resources/beta/messages/messages.py has both create and stream.

Impact

Any code using client.beta.messages.stream(...) breaks when switching from Anthropic() to AnthropicBedrock(). Streaming itself works fine on Bedrock — create(stream=True) returns events correctly. It's just the convenience .stream() method that's missing from the class definition.

Expected fix

class Messages(SyncAPIResource):
    create = FirstPartyMessagesAPI.create
    stream = FirstPartyMessagesAPI.stream

(Same for AsyncMessages.)

Since this file is Stainless-generated, the fix likely needs to happen in the generator config.

SDK version

anthropic==0.80.0

afoong-8s avatar Feb 26 '26 22:02 afoong-8s

Confirmed

Looking at the code:

First-party (resources/beta/messages/messages.py):

class Messages(SyncAPIResource):
    def create(self, ...) -> BetaMessage: ...
    @overload
    def stream(self, ...) -> BetaMessageStreamManager: ...

Bedrock (lib/bedrock/_beta_messages.py):

class Messages(SyncAPIResource):
    create = FirstPartyMessagesAPI.create
    # stream is not aliased

The suggested fix is correct — just add the alias:

stream = FirstPartyMessagesAPI.stream

Since Bedrock's underlying create(stream=True) returns the same event types, the stream() helper should work identically. The method manager (BetaMessageStreamManager) handles the event iteration/context management, which is provider-agnostic.

Workaround until fixed:

from anthropic import AnthropicBedrock
from anthropic.resources.beta.messages import Messages as FirstPartyMessages

client = AnthropicBedrock()
# Manually bind the stream method
client.beta.messages.stream = FirstPartyMessages.stream.__get__(client.beta.messages)

(Hacky but works for parity testing.)

xXMrNidaXx avatar Feb 28 '26 11:02 xXMrNidaXx

This is a straightforward fix! I can submit a PR to add the missing stream() method to Bedrock Messages class.

The fix is simple - just add stream = FirstPartyMessagesAPI.stream alongside the existing create assignment, both for Sync and Async classes.

passionworkeer avatar Mar 14 '26 17:03 passionworkeer

A2ABench has an accepted answer for this imported thread.

  • Thread: https://a2abench-api.web.app/q/cmmpnaa7q00mc1401opglb1x2
  • Accepted at: 2026-03-25T18:10:58.483Z
  • Accepted answer agent: ai village
  • Answer preview: "No matching threads were found for this query."

khalidsaidi avatar Mar 25 '26 18:03 khalidsaidi

Thanks, this is fixed in v0.122.0 (https://github.com/anthropics/anthropic-sdk-python/commit/6eca7bb19f968856b5652d5471e3ca9fc3fe8641). AnthropicBedrock().beta.messages now exposes stream, parse and tool_runner.

tomer-ant avatar Aug 17 '26 20:08 tomer-ant