class Anthropic::Vertex::Client

def build_request(req, opts)

Returns:
  • (Hash{Symbol=>Object}) -

Options Hash: (**opts)
  • :timeout (Float, nil) --
  • :max_retries (Integer, nil) --
  • :extra_body (Hash{Symbol=>Object}, nil) --
  • :extra_headers (Hash{String=>String, nil}, nil) --
  • :extra_query (Hash{String=>Array, String, nil}, nil) --
  • :idempotency_key (String, nil) --
  • :model (Anthropic::Converter, Class, nil) --
  • :page (Class, nil) --
  • :unwrap (Symbol, nil) --
  • :body (Object, nil) --
  • :headers (Hash{String=>String, nil}, nil) --
  • :query (Hash{String=>Array, String, nil}, nil) --
  • :path (String, Array) --
  • :method (Symbol) --

Parameters:
  • opts (Hash{Symbol=>Object}) -- .
  • req (Hash{Symbol=>Object}) -- .

Other tags:
    Private: -
def build_request(req, opts)
q_to_vertex_specs!(req)
t_input = super
 request_input[:headers]["Authorization"]
orization = Google::Auth.get_application_default(["https://www.googleapis.com/auth/cloud-platform"])
est_input[:headers] = authorization.apply(request_input[:headers])
t_input

def fit_req_to_vertex_specs!(request_components)

Returns:
  • (Hash{Symbol=>Object}) -

Options Hash: (**request_components)
  • :model (Anthropic::Converter, Class, nil) --
  • :page (Class, nil) --
  • :unwrap (Symbol, nil) --
  • :body (Object, nil) --
  • :headers (Hash{String=>String, nil}, nil) --
  • :query (Hash{String=>Array, String, nil}, nil) --
  • :path (String, Array) --
  • :method (Symbol) --

Parameters:
  • request_components (Hash{Symbol=>Object}) -- .

Other tags:
    Private: -
def fit_req_to_vertex_specs!(request_components)
  if (body = request_components[:body]).is_a?(Hash)
    body[:anthropic_version] ||= DEFAULT_VERSION
    if (anthropic_beta = body.delete(:"anthropic-beta"))
      request_components[:headers] ||= {}
      request_components[:headers]["anthropic-beta"] = anthropic_beta.join(",")
    end
  end
  if %w[
    v1/messages
    v1/messages?beta=true
  ].include?(request_components[:path]) && request_components[:method] == :post
    unless body.is_a?(Hash)
      raise Anthropic::Error, "Expected json data to be a hash for post /v1/messages"
    end
    model = body.delete(:model)
    specifier = body[:stream] ? "streamRawPredict" : "rawPredict"
    request_components[:path] =
      "projects/#{@project_id}/locations/#{region}/publishers/anthropic/models/#{model}:#{specifier}"
  end
  if %w[
    v1/messages/count_tokens
    v1/messages/count_tokens?beta=true
  ].include?(request_components[:path]) &&
     request_components[:method] == :post
    request_components[:path] =
      "projects/#{@project_id}/locations/#{region}/publishers/anthropic/models/count-tokens:rawPredict"
  end
  if request_components[:path].start_with?("v1/messages/batches/")
    raise AnthropicError("The Batch API is not supported in the Vertex client yet")
  end
  request_components
end

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