vertex only.Expand description
Google Cloud Vertex AI support: a RequestSigner that attaches an
OAuth2 bearer token so requests are authenticated against the Vertex AI
Anthropic endpoint.
The URL shape for Vertex AI is:
https://{region}-aiplatform.googleapis.com/v1/projects/{project}/locations/{region}/publishers/anthropic/models/{model}:rawPredictAuth is a standard Authorization: Bearer {token} header where the token
is a Google OAuth2 access token.
§Credential sources
Two credential sources are supported:
-
Static token (
VertexCredentials::from_token): supply a token string directly. Useful for tests and short-lived scripts where you already have a token (e.g., fromgcloud auth print-access-token). -
Application Default Credentials (
VertexCredentials::from_adc): usesgcp_authto obtain a token via Application Default Credentials (service-account key file, GCE metadata server,gcloudCLI, or theGOOGLE_APPLICATION_CREDENTIALSenvironment variable). This path requires an active Tokio runtime because token refresh is async; it callsHandle::current().block_on(...)insidesign().
VertexCredentials::from_env checks VERTEX_ACCESS_TOKEN first (static
token), then falls back to GOOGLE_APPLICATION_CREDENTIALS (ADC).
§Set up the client
use std::sync::Arc;
use claude_api::{Client, vertex::{VertexCredentials, VertexSigner}};
let creds = VertexCredentials::from_env()
.expect("VERTEX_ACCESS_TOKEN or GOOGLE_APPLICATION_CREDENTIALS must be set");
let region = std::env::var("VERTEX_REGION").unwrap_or_else(|_| "us-east5".into());
let project = std::env::var("VERTEX_PROJECT").expect("VERTEX_PROJECT must be set");
let client = Client::builder()
.signer(Arc::new(VertexSigner::new(creds)))
.base_url(format!(
"https://{region}-aiplatform.googleapis.com/v1/projects/{project}/locations/{region}/publishers/anthropic"
))
.build()?;Gated on the vertex feature.
Structs§
- Vertex
Credentials - Credential source for Vertex AI authentication.
- Vertex
Signer - Vertex AI bearer-token signer.