Skip to main content

Module vertex

Module vertex 

Source
Available on crate feature 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}:rawPredict

Auth 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., from gcloud auth print-access-token).

  • Application Default Credentials (VertexCredentials::from_adc): uses gcp_auth to obtain a token via Application Default Credentials (service-account key file, GCE metadata server, gcloud CLI, or the GOOGLE_APPLICATION_CREDENTIALS environment variable). This path requires an active Tokio runtime because token refresh is async; it calls Handle::current().block_on(...) inside sign().

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§

VertexCredentials
Credential source for Vertex AI authentication.
VertexSigner
Vertex AI bearer-token signer.