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, #messages, #models
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
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"], 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:
api_keyconstructor arg → API key mode (x-api-key header, no SigV4)aws_access_key+aws_secret_access_keyargs → SigV4 with explicit credentialsaws_profilearg → SigV4 with named AWS profileANTHROPIC_AWS_API_KEYenv var → API key mode (only when no platform auth args given)- 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 |
# File 'lib/anthropic/helpers/aws/client.rb', line 56 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"], 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" } ) 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 ) 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 |