class Anthropic::Helpers::Vertex::Client

def build_request(req, opts)

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

Options Hash: (**opts)
  • :timeout (Float, nil) --
  • :max_retries (Integer, nil) --
  • :extra_body (Object, nil) --
  • :extra_headers (Hash{String=>String, nil}, nil) --
  • :extra_query (Hash{String=>Array, String, nil}, nil) --
  • :idempotency_key (String, nil) --
  • :model (Anthropic::Internal::Type::Converter, Class, nil) --
  • :stream (Class, nil) --
  • :page (Class, nil) --
  • :unwrap (Symbol, Integer, Array, Proc, nil) --
  • :body (Object, nil) --
  • :headers (Hash{String=>String, Integer, Array, 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:
    Api: - private
def build_request(req, opts)
q_to_vertex_specs!(req)
t_input = super
s = request_input.fetch(:headers)
 headers.key?("authorization")
orization = Google::Auth.get_application_default(["https://www.googleapis.com/auth/cloud-platform"])
est_input.store(:headers, authorization.apply(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)
dy = request_components[:body]).is_a?(Hash)
[:anthropic_version] ||= DEFAULT_VERSION
anthropic_beta = body.delete(:"anthropic-beta"))
quest_components[:headers] ||= {}
quest_components[:headers]["anthropic-beta"] = anthropic_beta.join(",")

essages
essages?beta=true
ude?(request_components[:path]) && request_components[:method] == :post
ss body.is_a?(Hash)
ise ArgumentError.new("Expected json data to be a hash for post /v1/messages")
l = body.delete(:model)
ifier = body[:stream] ? "streamRawPredict" : "rawPredict"
est_components[:path] =
rojects/#{@project_id}/locations/#{region}/publishers/anthropic/models/#{model}:#{specifier}"

essages/count_tokens
essages/count_tokens?beta=true
ude?(request_components[:path]) &&
uest_components[:method] == :post
est_components[:path] =
rojects/#{@project_id}/locations/#{region}/publishers/anthropic/models/count-tokens:rawPredict"
uest_components[:path].start_with?("v1/messages/batches/")
e AnthropicError("The Batch API is not supported in the Vertex client yet")
t_components

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
    message = <<~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
    raise RuntimeError.new(message)
  end
  if region.to_s.empty?
    # rubocop:disable Layout/LineLength
    message = "No region was given. The client should be instantiated with the `region` argument or the `CLOUD_ML_REGION` environment variable should be set."
    # rubocop:enable Layout/LineLength
    raise ArgumentError.new(message)
  end
  @region = region
  if project_id.to_s.empty?
    # rubocop:disable Layout/LineLength
    message = "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."
    # rubocop:enable Layout/LineLength
    raise ArgumentError.new(message)
  end
  @project_id = project_id
  base_url ||= ENV.fetch(
    "ANTHROPIC_VERTEX_BASE_URL",
    @region.to_s == "global" ? "https://aiplatform.googleapis.com/v1" : "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