class Anthropic::Helpers::Bedrock::Client

def initialize(

Parameters:
  • max_retry_delay (Float) -- The maximum number of seconds to wait before retrying a request
  • initial_retry_delay (Float) -- The number of seconds to wait before retrying a request
  • timeout (Float) -- The number of seconds to wait for a response before timing out
  • max_retries (Integer) -- The maximum number of times to retry a request if it fails
  • base_url (String, nil) -- Override the default base URL for the API, e.g., `"https://api.example.com/v2/"`
  • aws_profile (String, nil) -- Optional AWS profile to use for authentication. Overrides the credential provider chain
  • aws_session_token (String, nil) -- Optional AWS session token to use for authentication. Overrides profile and credential provider chain
  • aws_secret_key (String, nil) -- Optional AWS secret access key to use for authentication. Overrides profile and credential provider chain
  • aws_access_key (String, nil) -- Optional AWS access key to use for authentication. Overrides profile and credential provider chain
  • aws_region (String, nil) -- Enforce the AWS Region to use. If unset, the region is set according to the
def initialize(
  aws_region: nil,
  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_access_key: nil,
  aws_secret_key: nil,
  aws_session_token: nil,
  aws_profile: nil
)
  begin
    require("aws-sdk-bedrockruntime")
  rescue LoadError
    message = <<~MSG
      In order to access Anthropic models on Bedrock you must require the `aws-sdk-bedrockruntime` gem.
      You can install it by adding the following to your Gemfile:
          gem "aws-sdk-bedrockruntime"
      and then running `bundle install`.
      Alternatively, if you are not using Bundler, simply run:
          gem install aws-sdk-bedrockruntime
    MSG
    raise RuntimeError.new(message)
  end
  @aws_region, @aws_credentials = resolve_region_and_credentials(
    aws_region: aws_region,
    aws_secret_key: aws_secret_key,
    aws_access_key: aws_access_key,
    aws_session_token: aws_session_token,
    aws_profile: aws_profile
  )
  @signer = Aws::Sigv4::Signer.new(
    service: "bedrock",
    region: @aws_region,
    credentials: @aws_credentials
  )
  base_url ||= ENV.fetch(
    "ANTHROPIC_BEDROCK_BASE_URL",
    "https://bedrock-runtime.#{@aws_region}.amazonaws.com"
  )
  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    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