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 with @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 Vertex adapter runs Gemini on Vertex AI. Use it when you need a regional endpoint, CMEK, or VPC-SC.
20
21`@tanstack/ai-vertex` gives you the Gemini adapters with Vertex auth. Request mapping, tools, and streaming stay the same as in [`@tanstack/ai-gemini`](./gemini).
22
23## 1. Install
24
25<!-- ::start:tabs variant="package-manager" mode="install" -->
26
27react: @tanstack/ai-vertex
28vue: @tanstack/ai-vertex
29solid: @tanstack/ai-vertex
30svelte: @tanstack/ai-vertex
31preact: @tanstack/ai-vertex
32angular: @tanstack/ai-vertex
33vanilla: @tanstack/ai-vertex
34octane: @tanstack/ai-vertex
35
36<!-- ::end:tabs -->
37
38## 2. Set the credentials
39
40Vertex uses Google Cloud credentials. It does **not** read `GEMINI_API_KEY` or `GOOGLE_API_KEY`, because those keys are for AI Studio.
41
421. Sign in with `gcloud auth application-default login`, or set `GOOGLE_APPLICATION_CREDENTIALS` to a service account JSON file.
432. Set the project and the region:
44
45```bash
46GOOGLE_CLOUD_PROJECT=my-project
47GOOGLE_CLOUD_LOCATION=europe-west1
48```
49
50You 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](#authentication).
51
52## 3. Stream a chat from the server
53
54Keep the Vertex credentials on the server. The browser only talks to your route.
55
56```typescript
57import {
58 chat,
59 chatParamsFromRequest,
60 toServerSentEventsResponse,
61} from "@tanstack/ai";
62import { vertexText } from "@tanstack/ai-vertex";
63
64export async function POST(request: Request) {
65 const { messages, threadId, runId } = await chatParamsFromRequest(request);
66
67 const stream = chat({
68 adapter: vertexText("gemini-3.7-flash", {
69 project: "my-project",
70 location: "europe-west1",
71 }),
72 messages,
73 threadId,
74 runId,
75 });
76
77 return toServerSentEventsResponse(stream);
78}
79```
80
81## 4. Render the chat
82
83`useChat` does not know that this is Vertex. It reads the stream from your route, the same as for every provider:
84
85```tsx
86import { useState } from "react";
87import { useChat, fetchServerSentEvents } from "@tanstack/ai-react";
88
89export function Chat() {
90 const [input, setInput] = useState("");
91 const { messages, sendMessage } = useChat({
92 connection: fetchServerSentEvents("/api/chat"),
93 threadId: "support-chat",
94 });
95
96 return (
97 <form
98 onSubmit={(event) => {
99 event.preventDefault();
100 sendMessage(input);
101 setInput("");
102 }}
103 >
104 {messages.map((message) => (
105 <p key={message.id}>
106 {message.parts
107 .map((part) => (part.type === "text" ? part.content : ""))
108 .join("")}
109 </p>
110 ))}
111 <input value={input} onChange={(event) => setInput(event.target.value)} />
112 </form>
113 );
114}
115```
116
117For Vue, Solid, Svelte, Angular, and the other frameworks, see [Quick Start](../getting-started/quick-start#3-render-the-chat).
118
119You now have Gemini on Vertex, in the region that you chose.
120
121## Other Gemini activities
122
123Each factory takes the same auth object:
124
125```typescript
126import {
127 vertexAudio,
128 vertexEmbedding,
129 vertexImage,
130 vertexSpeech,
131 vertexSummarize,
132 vertexText,
133 vertexVideo,
134} from "@tanstack/ai-vertex";
135
136const auth = { project: "my-project", location: "europe-west1" };
137
138vertexText("gemini-3.7-flash", auth);
139vertexSummarize("gemini-3.7-flash", auth);
140vertexImage("gemini-3.1-flash-image", auth);
141vertexEmbedding("gemini-embedding-001", auth);
142vertexSpeech("gemini-3.1-flash-tts-preview", auth);
143vertexAudio("lyria-3-pro-preview", auth);
144vertexVideo("veo-3.1-generate-preview", auth);
145```
146
147- `vertexSpeech`, `vertexAudio`, and `vertexVideo` are experimental.
148- `vertexText` ignores [`wrapFetch`](../advanced/middleware#change-the-http-requests-of-a-call), because the `@google/genai` SDK does not take a custom fetch.
149
150## Models and options
151
152The model ids and the provider options are the same as in [`@tanstack/ai-gemini`](./gemini#models-and-options). Image options that only Vertex has (for example `9:21`) do not work in this release.
153
154## Advanced
155
156### Authentication
157
158Vertex factories accept every auth option that `@google/genai` accepts.
159
160#### Application Default Credentials
161
162This 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:
163
164```typescript
165import { vertexText } from "@tanstack/ai-vertex";
166
167const adapter = vertexText("gemini-3.7-flash", {
168 project: "my-project",
169 location: "europe-west1",
170});
171```
172
173#### Service account fields
174
175```typescript
176import { vertexText } from "@tanstack/ai-vertex";
177
178const adapter = vertexText("gemini-3.7-flash", {
179 project: "my-project",
180 location: "europe-west1",
181 googleAuthOptions: {
182 credentials: {
183 client_email: "sa@my-project.iam.gserviceaccount.com",
184 private_key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
185 },
186 },
187});
188```
189
190#### Express API key
191
192Vertex express mode uses an API key. It needs no project and no location.
193
194```typescript
195import { vertexText } from "@tanstack/ai-vertex";
196
197const adapter = vertexText("gemini-3.7-flash", {
198 apiKey: "vertex-express-key",
199});
200```
201
202You can also set `GOOGLE_VERTEX_API_KEY`.
203
204### Environment variables
205
206| Variable | Purpose |
207| --- | --- |
208| `GOOGLE_CLOUD_PROJECT` | GCP project id |
209| `GOOGLE_VERTEX_PROJECT` | Alias for the project id |
210| `GOOGLE_CLOUD_LOCATION` | Region, for example `europe-west1` |
211| `GOOGLE_VERTEX_LOCATION` | Alias for the region |
212| `GOOGLE_VERTEX_API_KEY` | Vertex express API key |
213| `GOOGLE_APPLICATION_CREDENTIALS` | Path to a service account JSON file |
214
215### Claude on Vertex
216
217Use [`anthropicVertexText`](./anthropic-advanced#claude-on-vertex) from `@tanstack/ai-anthropic/vertex`.
218
219### Grok on Vertex
220
221Use [`grokVertexText`](./grok#grok-on-vertex) from `@tanstack/ai-grok/vertex`.
222
223- Vertex Grok uses the OpenAI-compatible Responses endpoint.
224- For summarize, use `grokVertexSummarize` from the same entry.
225- 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`, and `grok-4.1-fast-non-reasoning`.
226
227### Mistral on Vertex
228
229Use [`mistralVertexText`](./mistral#mistral-on-vertex) from `@tanstack/ai-mistral/vertex`.
230
231- Vertex Mistral uses the publisher `rawPredict` path.
232- It is regional only: `us-central1` or `europe-west4`.
233- The factory accepts only the Mistral chat models in the Vertex catalog: `mistral-medium-3`, `mistral-small-2503`, and `codestral-2`.
234
235### API reference
236
237| Factory | Creates |
238| --- | --- |
239| `vertexText(model, config?)` | Gemini chat adapter on Vertex |
240| `vertexSummarize(model, config?)` | Gemini summarize adapter on Vertex |
241| `vertexImage(model, config?)` | Gemini image adapter on Vertex |
242| `vertexEmbedding(model, config?)` | Gemini embedding adapter on Vertex |
243| `vertexSpeech(model, config?)` | Gemini text-to-speech adapter on Vertex. Experimental |
244| `vertexAudio(model, config?)` | Gemini Lyria audio adapter on Vertex. Experimental |
245| `vertexVideo(model, config?)` | Gemini video adapter on Vertex. Experimental. `config.allowUrlFetch` is the same opt-in as on the Gemini video adapter |
246
247`config` accepts `project`, `location`, `apiKey`, `googleAuthOptions`, `httpOptions`, and the other `@google/genai` client fields. The factory always sets `vertexai: true`.