The Vertex adapter runs Gemini on Vertex AI. Use it when you need a regional endpoint, CMEK, or VPC-SC.
@tanstack/ai-vertex gives you the Gemini adapters with Vertex auth. Request mapping, tools, and streaming stay the same as in @tanstack/ai-gemini.
npm i @tanstack/ai-vertexpnpm add @tanstack/ai-vertexyarn add @tanstack/ai-vertexbun add @tanstack/ai-vertexVertex uses Google Cloud credentials. It does not read GEMINI_API_KEY or GOOGLE_API_KEY, because those keys are for AI Studio.
GOOGLE_CLOUD_PROJECT=my-project
GOOGLE_CLOUD_LOCATION=europe-west1You can also pass project and location on each factory, as in the next step. For a service account in code or an express API key, see Authentication.
Keep the Vertex credentials on the server. The browser only talks to your route.
import {
chat,
chatParamsFromRequest,
toServerSentEventsResponse,
} from "@tanstack/ai";
import { vertexText } from "@tanstack/ai-vertex";
export async function POST(request: Request) {
const { messages, threadId, runId } = await chatParamsFromRequest(request);
const stream = chat({
adapter: vertexText("gemini-3.7-flash", {
project: "my-project",
location: "europe-west1",
}),
messages,
threadId,
runId,
});
return toServerSentEventsResponse(stream);
}useChat does not know that this is Vertex. It reads the stream from your route, the same as for every provider:
import { useState } from "react";
import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
export function Chat() {
const [input, setInput] = useState("");
const { messages, sendMessage } = useChat({
connection: fetchServerSentEvents("/api/chat"),
threadId: "support-chat",
});
return (
<form
onSubmit={(event) => {
event.preventDefault();
sendMessage(input);
setInput("");
}}
>
{messages.map((message) => (
<p key={message.id}>
{message.parts
.map((part) => (part.type === "text" ? part.content : ""))
.join("")}
</p>
))}
<input value={input} onChange={(event) => setInput(event.target.value)} />
</form>
);
}For Vue, Solid, Svelte, Angular, and the other frameworks, see Quick Start.
You now have Gemini on Vertex, in the region that you chose.
Each factory takes the same auth object:
import {
vertexAudio,
vertexEmbedding,
vertexImage,
vertexSpeech,
vertexSummarize,
vertexText,
vertexVideo,
} from "@tanstack/ai-vertex";
const auth = { project: "my-project", location: "europe-west1" };
vertexText("gemini-3.7-flash", auth);
vertexSummarize("gemini-3.7-flash", auth);
vertexImage("gemini-3.1-flash-image", auth);
vertexEmbedding("gemini-embedding-001", auth);
vertexSpeech("gemini-3.1-flash-tts-preview", auth);
vertexAudio("lyria-3-pro-preview", auth);
vertexVideo("veo-3.1-generate-preview", auth);The model ids and the provider options are the same as in @tanstack/ai-gemini. Image options that only Vertex has (for example 9:21) do not work in this release.
Vertex factories accept every auth option that @google/genai accepts.
This is the usual Google Cloud path. Sign in with gcloud auth application-default login, or set GOOGLE_APPLICATION_CREDENTIALS to a service account JSON file. Then pass project and location on the factory, or set them in the environment:
import { vertexText } from "@tanstack/ai-vertex";
const adapter = vertexText("gemini-3.7-flash", {
project: "my-project",
location: "europe-west1",
});import { vertexText } from "@tanstack/ai-vertex";
const adapter = vertexText("gemini-3.7-flash", {
project: "my-project",
location: "europe-west1",
googleAuthOptions: {
credentials: {
client_email: "sa@my-project.iam.gserviceaccount.com",
private_key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
},
},
});Vertex express mode uses an API key. It needs no project and no location.
import { vertexText } from "@tanstack/ai-vertex";
const adapter = vertexText("gemini-3.7-flash", {
apiKey: "vertex-express-key",
});You can also set GOOGLE_VERTEX_API_KEY.
| Variable | Purpose |
|---|---|
| GOOGLE_CLOUD_PROJECT | GCP project id |
| GOOGLE_VERTEX_PROJECT | Alias for the project id |
| GOOGLE_CLOUD_LOCATION | Region, for example europe-west1 |
| GOOGLE_VERTEX_LOCATION | Alias for the region |
| GOOGLE_VERTEX_API_KEY | Vertex express API key |
| GOOGLE_APPLICATION_CREDENTIALS | Path to a service account JSON file |
Use anthropicVertexText from @tanstack/ai-anthropic/vertex.
Use grokVertexText from @tanstack/ai-grok/vertex.
Use mistralVertexText from @tanstack/ai-mistral/vertex.
| Factory | Creates |
|---|---|
| vertexText(model, config?) | Gemini chat adapter on Vertex |
| vertexSummarize(model, config?) | Gemini summarize adapter on Vertex |
| vertexImage(model, config?) | Gemini image adapter on Vertex |
| vertexEmbedding(model, config?) | Gemini embedding adapter on Vertex |
| vertexSpeech(model, config?) | Gemini text-to-speech adapter on Vertex. Experimental |
| vertexAudio(model, config?) | Gemini Lyria audio adapter on Vertex. Experimental |
| vertexVideo(model, config?) | Gemini video adapter on Vertex. Experimental. config.allowUrlFetch is the same opt-in as on the Gemini video adapter |
config accepts project, location, apiKey, googleAuthOptions, httpOptions, and the other @google/genai client fields. The factory always sets vertexai: true.