Class VertexAIClient
- All Implemented Interfaces:
com.tnsai.llm.LLMClient
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 tous-central1.VERTEX_AI_BASE_URL— Optional. Fully overrides the host (useful for proxies / private endpoints). If unset, derived fromVERTEX_AI_LOCATION.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionVertexAIClient(String model) VertexAIClient(String model, float temperature) VertexAIClient(String model, float temperature, Float topP, Integer maxTokens) VertexAIClient(String model, float temperature, Integer maxTokens) VertexAIClient(String baseUrl, String model, float temperature, Float topP, Integer maxTokens, String apiKey, String projectId, String location) -
Method Summary
Modifier and TypeMethodDescriptioncom.tnsai.llm.ChatResponsechat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) streamChat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) Methods inherited from class com.tnsai.llm.providers.AbstractLLMClient
getBaseUrl, getCallTimeoutMs, getMaxTokens, getModel, getTemperature, getTopPMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.llm.LLMClient
chat, chat, chat, chat, chat, getCapabilities, getProviderName, listModels, streamChat, streamChat, streamChatWithHandler, streamChatWithHandler, streamChatWithSpec, streamChatWithSpec
-
Constructor Details
-
VertexAIClient
-
VertexAIClient
-
VertexAIClient
-
VertexAIClient
-
VertexAIClient
-
-
Method Details
-
chat
-
streamChat
-