class Anthropic::Client
def api_key_auth
-
(Hash{String=>String})
-
Other tags:
- Api: - private
def api_key_auth i-key" => @api_key}
def auth_headers
-
(Hash{String=>String})
-
Other tags:
- Api: - private
def auth_headers _key_auth, **bearer_auth}
def bearer_auth
-
(Hash{String=>String})
-
Other tags:
- Api: - private
def bearer_auth {} if @auth_token.nil? orization" => "Bearer #{@auth_token}"}
def calculate_nonstreaming_timeout(max_tokens, max_nonstreaming_tokens = nil)
-
(ArgumentError)
- If expected time exceeds default time or max_tokens exceeds max_nonstreaming_tokens
Returns:
-
(Float)
- The calculated timeout in seconds
Parameters:
-
max_nonstreaming_tokens
(Integer, nil
) -- The maximum tokens allowed for non-streaming -
max_tokens
(Integer
) -- The maximum number of tokens to generate
def calculate_nonstreaming_timeout(max_tokens, max_nonstreaming_tokens = nil) maximum_time = 60 * 60 # 1 hour in seconds default_time = 60 * 10 # 10 minutes in seconds expected_time = maximum_time * max_tokens / 128_000.0 if expected_time > default_time || (max_nonstreaming_tokens && max_tokens > max_nonstreaming_tokens) raise ArgumentError.new( "Streaming is strongly recommended for operations that may take longer than 10 minutes. " \ "See https://github.com/anthropics/anthropic-sdk-ruby#long-requests for more details" ) end DEFAULT_TIMEOUT_IN_SECONDS end
def initialize(
-
max_retry_delay
(Float
) -- -
initial_retry_delay
(Float
) -- -
timeout
(Float
) -- -
max_retries
(Integer
) -- Max number of retries to attempt after a failed retryable request. -
base_url
(String, nil
) -- Override the default base URL for the API, e.g., -
auth_token
(String, nil
) -- Defaults to `ENV["ANTHROPIC_AUTH_TOKEN"]` -
api_key
(String, nil
) -- Defaults to `ENV["ANTHROPIC_API_KEY"]`
def initialize( api_key: ENV["ANTHROPIC_API_KEY"], auth_token: ENV["ANTHROPIC_AUTH_TOKEN"], base_url: ENV["ANTHROPIC_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 ) base_url ||= "https://api.anthropic.com" headers = { "anthropic-version" => "2023-06-01" } @api_key = api_key&.to_s @auth_token = auth_token&.to_s super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, headers: headers ) @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