Class: Anthropic::Helpers::AWS::Client
- Inherits:
-
Client
- Object
- Internal::Transport::BaseClient
- Client
- Anthropic::Helpers::AWS::Client
- Includes:
- Anthropic::Helpers::AWSAuth
- Defined in:
- lib/anthropic/helpers/aws/client.rb
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
- #aws_region ⇒ String? readonly
- #workspace_id ⇒ String? readonly
Attributes inherited from Client
#api_key, #auth_token, #beta, #completions, #credentials, #messages, #models, #token_cache
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
-
#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"], workspace_id: ENV["ANTHROPIC_AWS_WORKSPACE_ID"], skip_auth: false, base_url: ENV["ANTHROPIC_AWS_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) ⇒ Client
constructor
Creates and returns a new client for interacting with Anthropic models via the AWS gateway.
Methods inherited from Client
#calculate_nonstreaming_timeout, #retry_request?
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #retry_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"], workspace_id: ENV["ANTHROPIC_AWS_WORKSPACE_ID"], skip_auth: false, base_url: ENV["ANTHROPIC_AWS_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) ⇒ Client
Creates and returns a new client for interacting with Anthropic models via the AWS gateway.
AWS credentials are resolved in priority order:
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. `ANTHROPIC_AWS_API_KEY` env var → API key mode (only when no platform auth args given)
5. Default AWS credential chain (env vars → shared config → instance profile) → SigV4
When ‘skip_auth` is true, all auth is skipped and workspace_id is not required.
56 57 58 59 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 103 104 105 106 107 108 |
# File 'lib/anthropic/helpers/aws/client.rb', line 56 def initialize( # rubocop:disable Lint/MissingSuper 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"], workspace_id: ENV["ANTHROPIC_AWS_WORKSPACE_ID"], skip_auth: false, base_url: ENV["ANTHROPIC_AWS_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, workspace_id: workspace_id, skip_auth: skip_auth, base_url: base_url, service_name: "aws-external-anthropic", env_api_key: "ANTHROPIC_AWS_API_KEY", env_workspace_id: "ANTHROPIC_AWS_WORKSPACE_ID", derive_base_url: ->(region) { "https://aws-external-anthropic.#{region}.api.aws" } ) @api_key = effective_api_key @auth_token = nil @credentials = nil @token_cache = nil # Skip Anthropic::Client#initialize and bind BaseClient#initialize directly: # the parent's initializer runs OIDC/credential-provider resolution that does # not apply here. Anthropic::Internal::Transport::BaseClient.instance_method(:initialize).bind(self).call( base_url: resolved_base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, headers: {"anthropic-version" => "2023-06-01"} ) @completions = Anthropic::Resources::Completions.new(client: self) @messages = Anthropic::Resources::Messages.new(client: self) @models = Anthropic::Resources::Models.new(client: self) @beta = Anthropic::Resources::Beta.new(client: self) end |
Instance Attribute Details
#aws_region ⇒ String? (readonly)
10 11 12 |
# File 'lib/anthropic/helpers/aws/client.rb', line 10 def aws_region @aws_region end |
#workspace_id ⇒ String? (readonly)
13 14 15 |
# File 'lib/anthropic/helpers/aws/client.rb', line 13 def workspace_id @workspace_id end |