Class: Anthropic::Helpers::GoogleCloud::Client
- Inherits:
-
Client
- Object
- Internal::Transport::BaseClient
- Client
- Anthropic::Helpers::GoogleCloud::Client
- Defined in:
- lib/anthropic/helpers/google_cloud/client.rb,
sig/anthropic/helpers/google_cloud/client.rbs
Overview
Client for Claude Platform on Google Cloud — the first-party Anthropic API served through the Google Cloud gateway.
This is distinct from VertexClient, which targets the
:rawPredict publisher-model API (publisher model IDs, messages
only). This client speaks the full first-party Anthropic API: requests
pass through the gateway unchanged — standard /v1/* paths, standard
model names, the complete API surface. The deprecated text Completions
endpoint is intentionally not exposed.
Constant Summary collapse
- SCOPE =
OAuth2 scope required to call the gateway.
"https://www.googleapis.com/auth/cloud-platform"- URL_TEMPLATE =
Gateway base URL template; override via
base_urlorANTHROPIC_GOOGLE_CLOUD_BASE_URL. "https://claude.googleapis.com/v1alpha" \ "/projects/%<project>s/locations/%<location>s/workspaces/%<workspace_id>s/invoke"
- Anthropic =
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
- #location ⇒ String? readonly
- #project ⇒ String? readonly
- #workspace_id ⇒ String? readonly
Attributes inherited from Client
#api_key, #auth_token, #beta, #credentials, #files, #messages, #models, #skills, #token_cache, #webhook_key
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #middleware, #requester, #timeout
Instance Method Summary collapse
-
#completions ⇒ bot
The deprecated text Completions endpoint is not supported on the Google Cloud gateway.
-
#initialize(project: ENV["ANTHROPIC_GOOGLE_CLOUD_PROJECT"] || ENV["GOOGLE_CLOUD_PROJECT"], location: ENV["ANTHROPIC_GOOGLE_CLOUD_LOCATION"] || "global", workspace_id: ENV["ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID"], base_url: ENV["ANTHROPIC_GOOGLE_CLOUD_BASE_URL"], google_credentials: nil, token_provider: nil, skip_auth: false, 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, middleware: nil) ⇒ Client
constructor
Creates a new client for the Anthropic API on the Google Cloud gateway.
Methods inherited from Client
#calculate_nonstreaming_timeout, #retry_request?
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #retry_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(project: ENV["ANTHROPIC_GOOGLE_CLOUD_PROJECT"] || ENV["GOOGLE_CLOUD_PROJECT"], location: ENV["ANTHROPIC_GOOGLE_CLOUD_LOCATION"] || "global", workspace_id: ENV["ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID"], base_url: ENV["ANTHROPIC_GOOGLE_CLOUD_BASE_URL"], google_credentials: nil, token_provider: nil, skip_auth: false, 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, middleware: nil) ⇒ Client
Creates a new client for the Anthropic API on the Google Cloud gateway.
Authentication uses Google credentials by precedence (unless
skip_auth is true):
1. `token_provider` — a callable returning a GCP access token, called
per attempt
2. `google_credentials` — a `googleauth` credentials object (anything
responding to `#apply`), refreshed by the library as needed
3. Application Default Credentials (`Google::Auth.get_application_default`)
with the `cloud-platform` scope
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/anthropic/helpers/google_cloud/client.rb', line 89 def initialize( project: ENV["ANTHROPIC_GOOGLE_CLOUD_PROJECT"] || ENV["GOOGLE_CLOUD_PROJECT"], location: ENV["ANTHROPIC_GOOGLE_CLOUD_LOCATION"] || "global", workspace_id: ENV["ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID"], base_url: ENV["ANTHROPIC_GOOGLE_CLOUD_BASE_URL"], google_credentials: nil, token_provider: nil, skip_auth: false, 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, middleware: nil ) if skip_auth && (token_provider || google_credentials) raise ArgumentError.new( "`skip_auth` is mutually exclusive with `token_provider` and `google_credentials`; " \ "`skip_auth` disables authentication entirely." ) end @skip_auth = skip_auth @token_provider = token_provider @authorization = google_credentials # Resolve credentials eagerly so the client is thread-safe (no lazy # ADC race) and so the credentials' project can backfill `project` # before the base URL is derived. if !skip_auth && token_provider.nil? && google_credentials.nil? require_googleauth @authorization = Google::Auth.get_application_default([SCOPE]) end if project.nil? && @authorization.respond_to?(:project_id) project = @authorization.project_id end @project = project # The kwarg default doesn't fire on an explicitly-passed nil — coerce # so nil can't reach the derived URL (matches the other SDKs). @location = location || ENV["ANTHROPIC_GOOGLE_CLOUD_LOCATION"] || "global" if workspace_id.nil? && !skip_auth raise ArgumentError.new( "No workspace ID was given. Set the `workspace_id` argument or the " \ "`ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID` environment variable." ) end @workspace_id = workspace_id base_url = nil if base_url.to_s.empty? base_url ||= derive_base_url # No first-party credential is ever passed up, and # {#resolve_default_credentials?} keeps the parent from discovering # one; `base_url` is always resolved by this point, so the parent's # `ANTHROPIC_BASE_URL` fallback never applies. The parent wires up # every resource; {#completions} withholds the one the gateway does # not serve. super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, middleware: middleware ) end |
Instance Attribute Details
#location ⇒ String? (readonly)
29 30 31 |
# File 'lib/anthropic/helpers/google_cloud/client.rb', line 29 def location @location end |
#project ⇒ String? (readonly)
26 27 28 |
# File 'lib/anthropic/helpers/google_cloud/client.rb', line 26 def project @project end |
#workspace_id ⇒ String? (readonly)
32 33 34 |
# File 'lib/anthropic/helpers/google_cloud/client.rb', line 32 def workspace_id @workspace_id end |
Instance Method Details
#completions ⇒ bot
The deprecated text Completions endpoint is not supported on the Google Cloud gateway.
167 168 169 170 171 |
# File 'lib/anthropic/helpers/google_cloud/client.rb', line 167 def completions raise NotImplementedError.new( "The deprecated text Completions API is not supported on the Google Cloud gateway." ) end |