Open History to see the last commit
1---
2title: Google Vertex AI
3id: vertex-adapter
4order: 4
5description: "Run Gemini on Google Vertex AI with TanStack AI. Use regional endpoints and Google Cloud credentials via @tanstack/ai-vertex."
6keywords:
7 - tanstack ai
8 - vertex
9 - vertex ai
10 - gemini
11 - grok
12 - xai
13 - mistral
14 - google cloud
15 - regional
16 - adapter
17---
18
19The Gemini Developer API has no regional endpoint. If you need EU data residency, CMEK, or VPC-SC, you have to run Gemini on Vertex AI.
20
21`@tanstack/ai-vertex` is that path. It builds the existing Gemini adapters with Vertex auth. Request mapping, tools, and streaming stay the same.
22
23Claude on Vertex is a different package. See [Anthropic Vertex](./anthropic#claude-on-vertex).
24
25## Installation
26
27<!-- ::start:tabs variant="package-manager" mode="install" -->
28
29react: @tanstack/ai-vertex
30vue: @tanstack/ai-vertex
31solid: @tanstack/ai-vertex
32svelte: @tanstack/ai-vertex
33preact: @tanstack/ai-vertex
34angular: @tanstack/ai-vertex
35vanilla: @tanstack/ai-vertex
36octane: @tanstack/ai-vertex
37
38<!-- ::end:tabs -->
39
40## Basic usage
41
42```typescript
43import { chat } from "@tanstack/ai";
44import { vertexText } from "@tanstack/ai-vertex";
45
46const stream = chat({
47 adapter: vertexText("gemini-3.7-flash", {
48 project: "my-project",
49 location: "europe-west1",
50 }),
51 messages: [{ role: "user", content: "Hello!" }],
52});
53```
54
55Reuse one auth object for every factory:
56
57```typescript
58import { vertexImage, vertexText } from "@tanstack/ai-vertex";
59
60const auth = {
61 project: "my-project",
62 location: "europe-west1",
63};
64
65const text = vertexText("gemini-3.7-flash", auth);
66const image = vertexImage("gemini-3.1-flash-image", auth);
67```
68
69## Authentication
70
71Vertex factories accept every auth option `@google/genai` accepts. They do **not** read `GEMINI_API_KEY` or `GOOGLE_API_KEY`. Those keys are AI Studio, not Vertex.
72
73### Application Default Credentials
74
75This 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.
76
77Pass `project` and `location` on the factory, or set:
78
79```bash
80GOOGLE_CLOUD_PROJECT=my-project
81GOOGLE_CLOUD_LOCATION=europe-west1
82```
83
84`GOOGLE_VERTEX_PROJECT` and `GOOGLE_VERTEX_LOCATION` are also accepted.
85
86```typescript
87import { vertexText } from "@tanstack/ai-vertex";
88
89const adapter = vertexText("gemini-3.7-flash", {
90 project: "my-project",
91 location: "europe-west1",
92});
93```
94
95### Service account fields
96
97```typescript
98import { vertexText } from "@tanstack/ai-vertex";
99
100const adapter = vertexText("gemini-3.7-flash", {
101 project: "my-project",
102 location: "europe-west1",
103 googleAuthOptions: {
104 credentials: {
105 client_email: "sa@my-project.iam.gserviceaccount.com",
106 private_key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
107 },
108 },
109});
110```
111
112### Express API key
113
114Vertex express mode uses an API key and does not need project or location.
115
116```typescript
117import { vertexText } from "@tanstack/ai-vertex";
118
119const adapter = vertexText("gemini-3.7-flash", {
120 apiKey: "vertex-express-key",
121});
122```
123
124Or set `GOOGLE_VERTEX_API_KEY`.
125
126## Example: server and client
127
128Keep Vertex credentials on the server. The browser only talks to your route.
129
130Server:
131
132```typescript
133import { chat, toServerSentEventsResponse } from "@tanstack/ai";
134import { vertexText } from "@tanstack/ai-vertex";
135
136export async function POST(request: Request) {
137 const { messages } = await request.json();
138
139 const stream = chat({
140 adapter: vertexText("gemini-3.7-flash", {
141 project: "my-project",
142 location: "europe-west1",
143 }),
144 messages,
145 });
146
147 return toServerSentEventsResponse(stream);
148}
149```
150
151Client:
152
153```tsx
154import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
155
156export function Chat() {
157 const { messages, sendMessage } = useChat({
158 connection: fetchServerSentEvents("/api/chat"),
159 });
160
161 return (
162 <form
163 onSubmit={(event) => {
164 event.preventDefault();
165 const form = event.currentTarget;
166 const input = new FormData(form).get("text");
167 if (typeof input === "string" && input.trim()) {
168 sendMessage(input);
169 form.reset();
170 }
171 }}
172 >
173 {messages.map((message) => (
174 <div key={message.id}>
175 {message.role}:{" "}
176 {message.parts
177 .filter((part) => part.type === "text")
178 .map((part) => part.content)
179 .join("")}
180 </div>
181 ))}
182 <input name="text" />
183 <button type="submit">Send</button>
184 </form>
185 );
186}
187```
188
189`useChat` does not know this is Vertex. It only consumes the SSE stream from your server.
190
191## Other Gemini activities
192
193Every factory uses the same auth object.
194
195```typescript
196import {
197 vertexAudio,
198 vertexEmbedding,
199 vertexImage,
200 vertexSpeech,
201 vertexSummarize,
202 vertexText,
203 vertexVideo,
204} from "@tanstack/ai-vertex";
205
206const auth = { project: "my-project", location: "europe-west1" };
207
208vertexText("gemini-3.7-flash", auth);
209vertexSummarize("gemini-3.7-flash", auth);
210vertexImage("gemini-3.1-flash-image", auth);
211vertexEmbedding("gemini-embedding-001", auth);
212vertexSpeech("gemini-3.1-flash-tts-preview", auth);
213vertexAudio("lyria-3-pro-preview", auth);
214vertexVideo("veo-3.1-generate-preview", auth);
215```
216
217Model ids and provider options are the same as `@tanstack/ai-gemini`. Vertex-only image options (for example `9:21`) are not unlocked in this release.
218
219## Environment variables
220
221| Variable | Purpose |
222| --- | --- |
223| `GOOGLE_CLOUD_PROJECT` | GCP project id |
224| `GOOGLE_VERTEX_PROJECT` | Alias for the project id |
225| `GOOGLE_CLOUD_LOCATION` | Region, for example `europe-west1` |
226| `GOOGLE_VERTEX_LOCATION` | Alias for the region |
227| `GOOGLE_VERTEX_API_KEY` | Vertex express API key |
228| `GOOGLE_APPLICATION_CREDENTIALS` | Path to a service account JSON file |
229
230## API reference
231
232### `vertexText(model, config?)`
233
234Creates a Gemini chat adapter on Vertex.
235
236### `vertexSummarize(model, config?)`
237
238Creates a Gemini summarize adapter on Vertex.
239
240### `vertexImage(model, config?)`
241
242Creates a Gemini image adapter on Vertex.
243
244### `vertexEmbedding(model, config?)`
245
246Creates a Gemini embedding adapter on Vertex.
247
248### `vertexSpeech(model, config?)`
249
250Creates a Gemini text-to-speech adapter on Vertex. Experimental.
251
252### `vertexAudio(model, config?)`
253
254Creates a Gemini Lyria audio adapter on Vertex. Experimental.
255
256### `vertexVideo(model, config?)`
257
258Creates a Gemini video adapter on Vertex. Experimental. `config.allowUrlFetch` is the same opt-in as the Gemini video adapter.
259
260`config` accepts `project`, `location`, `apiKey`, `googleAuthOptions`, `httpOptions`, and the other `@google/genai` client fields. The factory always sets `vertexai: true`.
261
262## Claude on Vertex
263
264Use [`anthropicVertexText`](./anthropic#claude-on-vertex) from `@tanstack/ai-anthropic/vertex`.
265
266## Grok on Vertex
267
268Use [`grokVertexText`](./grok#grok-on-vertex) from `@tanstack/ai-grok/vertex`. Vertex Grok uses the OpenAI-compatible Responses endpoint. Use `grokVertexSummarize` from the same entry for summarize. The factory accepts only the Grok chat models in the Vertex catalog (`grok-4.3`, `grok-4.20-reasoning`, `grok-4.20-non-reasoning`, `grok-4.1-fast-reasoning`, `grok-4.1-fast-non-reasoning`).
269
270## Mistral on Vertex
271
272Use [`mistralVertexText`](./mistral#mistral-on-vertex) from `@tanstack/ai-mistral/vertex`. Vertex Mistral uses the publisher `rawPredict` path. It is regional only (`us-central1` or `europe-west4`). The factory accepts only the Mistral chat models in the Vertex catalog (`mistral-medium-3`, `mistral-small-2503`, `codestral-2`).