class

Anthropic::Bedrock::Client

Inherits Anthropic::Client < Reference < Object

Anthropic Messages client that targets Amazon Bedrock Runtime.

Rewrites canonical /v1/messages calls to Bedrock's /model/{modelId}/invoke (and stream variant) and authenticates with AWS SigV4 (or an optional Bedrock bearer token).

client = Anthropic::Bedrock::Client.new(
  aws_profile: "anthropic-cr-bedrock",
  aws_region: "us-east-1",
)

message = client.messages.create(
  model: "us.anthropic.claude-haiku-4-5-20251001-v1:0",
  max_tokens: 256,
  messages: [{role: "user", content: "Hello from Bedrock!"}],
)
puts message.text

Prefer inference profile model IDs (us.anthropic.* / global.anthropic.*) for current Claude models — bare anthropic.* on-demand IDs often fail.

Not supported on Bedrock yet (matches official SDKs): Message Batches, token counting, and the Models list endpoint.

Constants

DEFAULT_VERSION = "bedrock-2023-05-31"

Constructors

new(aws_access_key : String | Nil = nil, aws_secret_key : String | Nil = nil, aws_session_token : String | Nil = nil, aws_region : String | Nil = nil, aws_profile : String | Nil = nil, api_key : String | Nil = nil, base_url : String | Nil = nil, timeout : Time::Span = 600.seconds, max_retries : Int32 = DEFAULT_MAX_RETRIES, initial_retry_delay : Float64 = DEFAULT_INITIAL_DELAY, max_retry_delay : Float64 = DEFAULT_MAX_DELAY, default_headers : Hash(String, String) = {} of String => String, middleware : Array = [] of Middleware)

Create a Bedrock client.

Pass AWS credentials explicitly, via aws_profile, or rely on the resolver chain (env → shared credentials → aws login cache → IAM Identity Center SSO → IMDS). Alternatively pass api_key / set AWS_BEARER_TOKEN_BEDROCK for bearer-token auth (mutually exclusive with AWS credentials).

Source

Instance methods

aws_region
Source
beta

Bedrock exposes only beta.messages (not Managed Agents APIs).

Source
models

Bedrock does not support the Models API the same way as the public API.

Source
post_stream(path : String, body, extra_headers : Hash(String, String) | Nil = nil, &)

Streaming against Bedrock uses invoke-with-response-stream and returns AWS Event Stream framing. This rewrites the path, SigV4-signs, and transcodes application/vnd.amazon.eventstream bodies into SSE so MessageStream / messages.stream work unchanged.

Source
use_sig_v4?
Source