Class VertexAIClient

java.lang.Object
com.tnsai.llm.providers.AbstractLLMClient
com.tnsai.llm.providers.VertexAIClient
All Implemented Interfaces:
com.tnsai.llm.LLMClient

public class VertexAIClient extends AbstractLLMClient
Google Cloud Vertex AI LLM client (enterprise Gemini).

Vertex AI is the enterprise variant of the Gemini API — same underlying models, but hosted in customer-owned GCP projects with GCP IAM auth, regional quotas, and enterprise SLAs. The wire format is the native Gemini generateContent shape (contents[].parts[], systemInstruction, generationConfig) — distinct from the OpenAI-shaped providers in the rest of this module.

The endpoint URL is regional and project-scoped: https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{PROJECT}/locations/{LOCATION}/publishers/google/models/{MODEL}:generateContent. Both LOCATION and PROJECT are caller-supplied; this client derives the base URL from the configured location when no explicit VERTEX_AI_BASE_URL is provided.

Supported models

  • gemini-2.0-flash-001 — frontier multimodal flash tier
  • gemini-2.0-pro-001 — higher-quality general purpose
  • gemini-1.5-pro-002 — long-context (1M-2M token) tier
  • gemini-1.5-flash-002 — cheap / fast

The catalog evolves; check cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini.

Auth (v1 scope)

v1 takes a pre-fetched OAuth access token via VERTEX_AI_API_KEY. Two practical sources:

  • Development: gcloud auth print-access-token — gives a 1-hour-lived token tied to the user's gcloud login.
  • Production: a sidecar / workload-identity helper that refreshes the token from a service-account JSON file (or GKE metadata server) and writes it where this client can read it.

The framework does not yet implement Application Default Credentials (ADC) end-to-end — that's a follow-up issue (service-account JWT signing, GCE metadata-server probe, gcloud config fallback) because it pulls in google-auth-library-java or hand-rolled JWT crypto. Until then, callers manage token refresh themselves.

Configuration via environment variables:

  • VERTEX_AI_API_KEY — Required. A pre-fetched OAuth access token (see above).
  • VERTEX_AI_PROJECT_ID — Required. The GCP project ID hosting the Vertex AI endpoint.
  • VERTEX_AI_LOCATION — Optional. The GCP region (us-central1, europe-west4, etc.). Defaults to us-central1.
  • VERTEX_AI_BASE_URL — Optional. Fully overrides the host (useful for proxies / private endpoints). If unset, derived from VERTEX_AI_LOCATION.
See Also: