Class: Anthropic::Helpers::Bedrock::MantleClient

Inherits:
Client show all
Includes:
AWSAuth
Defined in:
lib/anthropic/helpers/bedrock/mantle_client.rb

Overview

Client for the Anthropic Bedrock Mantle API. Only the Messages API (/v1/messages) and its subpaths are supported.

Auth is resolved by the same precedence as the AWS gateway client, with Mantle-specific environment variables that fall back to the AWS equivalents:

1. `api_key` constructor arg → API key mode (x-api-key header, no SigV4)
2. `aws_access_key` + `aws_secret_access_key` args → SigV4 with explicit credentials
3. `aws_profile` arg → SigV4 with named AWS profile
4. `AWS_BEARER_TOKEN_BEDROCK` env (then `ANTHROPIC_AWS_API_KEY`) → API key mode
5. Default AWS credential chain → SigV4

Defined Under Namespace

Classes: MantleBeta

Constant Summary

Constants inherited from Client

Client::DEFAULT_INITIAL_RETRY_DELAY, Client::DEFAULT_MAX_RETRIES, Client::DEFAULT_MAX_RETRY_DELAY, Client::DEFAULT_TIMEOUT_IN_SECONDS, Client::MODEL_NONSTREAMING_TOKENS

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Client

#api_key, #auth_token

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Client

#calculate_nonstreaming_timeout

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(api_key: nil, aws_access_key: nil, aws_secret_access_key: nil, aws_session_token: nil, aws_profile: nil, aws_region: ENV["AWS_REGION"] || ENV["AWS_DEFAULT_REGION"], skip_auth: false, base_url: ENV["ANTHROPIC_BEDROCK_MANTLE_BASE_URL"], 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) ⇒ MantleClient

Creates and returns a new client for interacting with Anthropic models via Bedrock Mantle. Only the Messages API (/v1/messages) is supported.

Parameters:

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

    Anthropic API key (bypasses SigV4, uses x-api-key header)

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

    AWS access key ID for SigV4 signing

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

    AWS secret access key for SigV4 signing

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

    Optional AWS session token for temporary credentials

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

    AWS profile name (uses SigV4 with named profile)

  • aws_region (String, nil) (defaults to: ENV["AWS_REGION"] || ENV["AWS_DEFAULT_REGION"])

    AWS region for the base URL and SigV4 signing. Defaults to ‘ENV`, then `ENV`. Required in SigV4 mode.

  • skip_auth (Boolean) (defaults to: false)

    When true, skip all auth. Note: the base SDK may still send an X-Api-Key header if ANTHROPIC_API_KEY is set.

  • base_url (String, nil) (defaults to: ENV["ANTHROPIC_BEDROCK_MANTLE_BASE_URL"])

    Override the default base URL for the API. Defaults to ‘ENV`, then `bedrock-mantle.region.api.aws/anthropic`.

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • 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)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/anthropic/helpers/bedrock/mantle_client.rb', line 60

def initialize(
  api_key: nil,
  aws_access_key: nil,
  aws_secret_access_key: nil,
  aws_session_token: nil,
  aws_profile: nil,
  aws_region: ENV["AWS_REGION"] || ENV["AWS_DEFAULT_REGION"],
  skip_auth: false,
  base_url: ENV["ANTHROPIC_BEDROCK_MANTLE_BASE_URL"],
  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
)
  effective_api_key, resolved_base_url = setup_aws_auth(
    api_key: api_key,
    aws_access_key: aws_access_key,
    aws_secret_access_key: aws_secret_access_key,
    aws_session_token: aws_session_token,
    aws_profile: aws_profile,
    aws_region: aws_region,
    skip_auth: skip_auth,
    base_url: base_url,
    service_name: "bedrock-mantle",
    env_api_key: "AWS_BEARER_TOKEN_BEDROCK",
    env_api_key_fallback: "ANTHROPIC_AWS_API_KEY",
    derive_base_url: ->(region) { "https://bedrock-mantle.#{region}.api.aws/anthropic" },
    use_bearer_auth: true
  )

  super(
    api_key: effective_api_key,
    base_url: resolved_base_url,
    max_retries: max_retries,
    timeout: timeout,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay
  )

  # Only initialize supported resources
  @messages = Anthropic::Resources::Messages.new(client: self)
  @beta = MantleBeta.new(client: self)
end

Instance Attribute Details

#aws_regionString? (readonly)

Returns:

  • (String, nil)


21
22
23
# File 'lib/anthropic/helpers/bedrock/mantle_client.rb', line 21

def aws_region
  @aws_region
end

#betaAnthropic::Helpers::Bedrock::MantleClient::MantleBeta (readonly)



27
28
29
# File 'lib/anthropic/helpers/bedrock/mantle_client.rb', line 27

def beta
  @beta
end

#messagesAnthropic::Resources::Messages (readonly)



24
25
26
# File 'lib/anthropic/helpers/bedrock/mantle_client.rb', line 24

def messages
  @messages
end

Instance Method Details

#completionsObject

Completions are not supported on Bedrock Mantle. Only Messages (/v1/messages) is supported.

Raises:

  • (NotImplementedError)


105
106
107
# File 'lib/anthropic/helpers/bedrock/mantle_client.rb', line 105

def completions
  raise NotImplementedError, "Completions are not supported on Bedrock Mantle. Only Messages (/v1/messages) is supported."
end

#modelsObject

Models listing is not supported on Bedrock Mantle. Only Messages (/v1/messages) is supported.

Raises:

  • (NotImplementedError)


110
111
112
# File 'lib/anthropic/helpers/bedrock/mantle_client.rb', line 110

def models
  raise NotImplementedError, "Models listing is not supported on Bedrock Mantle. Only Messages (/v1/messages) is supported."
end