Class: ActiveAgent::Providers::Bedrock::BearerClient

Inherits:
Anthropic::Client
  • Object
show all
Defined in:
lib/active_agent/providers/bedrock/bearer_client.rb

Overview

Client for AWS Bedrock using bearer token (API key) authentication.

Subclasses Anthropic::Client directly to reuse its built-in bearer token support via the auth_token parameter, while adding Bedrock- specific request transformations (URL path rewriting, anthropic_version injection) copied from Anthropic::BedrockClient.

This avoids Anthropic::BedrockClient which requires SigV4 credentials and would fail when only a bearer token is available.

Constant Summary collapse

BEDROCK_VERSION =
"bedrock-2023-05-31"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_region:, bearer_token:, base_url: nil, max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ BearerClient

Returns a new instance of BearerClient.

Parameters:

  • aws_region (String)

    AWS region for the Bedrock endpoint

  • bearer_token (String)

    AWS Bedrock API key (bearer token)

  • base_url (String, nil) (defaults to: nil)

    Override the default Bedrock endpoint

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)
  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_agent/providers/bedrock/bearer_client.rb', line 30

def initialize(
  aws_region:,
  bearer_token:,
  base_url: nil,
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  @aws_region = aws_region

  base_url ||= "https://bedrock-runtime.#{aws_region}.amazonaws.com"

  super(
    auth_token: bearer_token,
    api_key: nil,
    base_url: base_url,
    max_retries: max_retries,
    timeout: timeout,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay
  )

  @messages = ::Anthropic::Resources::Messages.new(client: self)
  @completions = ::Anthropic::Resources::Completions.new(client: self)
  @beta = ::Anthropic::Resources::Beta.new(client: self)
end

Instance Attribute Details

#aws_regionString (readonly)

Returns:

  • (String)


21
22
23
# File 'lib/active_agent/providers/bedrock/bearer_client.rb', line 21

def aws_region
  @aws_region
end