class Anthropic::Vertex::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/"`
  • project_id (String, nil) -- Enforce the GCP Project ID to use. If unset, the project_id may be set with the ANTHROPIC_VERTEX_PROJECT_ID environment variable.
  • region (String, nil) -- Enforce the GCP Region to use. If unset, the region may be set with the CLOUD_ML_REGION environment variable.
def initialize(
  region: ENV["CLOUD_ML_REGION"],
  project_id: ENV["ANTHROPIC_VERTEX_PROJECT_ID"],
  base_url: nil,
  max_retries: DEFAULT_MAX_RETRIES,
  timeout: DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: DEFAULT_MAX_RETRY_DELAY
)
  begin
    require("googleauth")
  rescue LoadError
    raise <<~MSG
      In order to access Anthropic models on Vertex you must require the `googleauth` gem.
      You can install it by adding the following to your Gemfile:
          gem "googleauth"
      and then running `bundle install`.
      Alternatively, if you are not using Bundler, simply run:
          gem install googleauth
    MSG
  end
  if region.to_s.empty?
    raise ArgumentError,
          "No region was given. The client should be instantiated with the `region` argument or the `CLOUD_ML_REGION` environment variable should be set."
  end
  @region = region
  if project_id.to_s.empty?
    raise ArgumentError,
          "No project_id was given and it could not be resolved from credentials. The client should be instantiated with the `project_id` argument or the `ANTHROPIC_VERTEX_PROJECT_ID` environment variable should be set."
  end
  @project_id = project_id
  base_url ||= ENV.fetch("ANTHROPIC_VERTEX_BASE_URL", "https://#{@region}-aiplatform.googleapis.com/v1")
  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)
  @beta = Anthropic::Resources::Beta.new(client: self)
end