Open History to see the last commit
1---
2title: Lovable AI Gateway
3id: lovable-adapter
4description: "Use one Lovable API key to call Google and OpenAI models through Lovable AI Gateway. Chat, embeddings, image, video, speech, and transcription all work with @tanstack/ai-lovable."
5keywords:
6 - tanstack ai
7 - lovable
8 - ai gateway
9 - adapter
10 - chat
11 - responses
12 - embeddings
13 - image generation
14 - video generation
15 - tts
16 - transcription
17---
18
19Install `@tanstack/ai-lovable`. Then call `lovableText` with a model id such as `google/gemini-3.7-flash`.
20
21Lovable AI Gateway sits in front of Google and OpenAI models. You use one project key. You do not set up a provider account.
22
23## Installation
24
25<!-- ::start:tabs variant="package-manager" mode="install" -->
26
27react: @tanstack/ai-lovable
28vue: @tanstack/ai-lovable
29solid: @tanstack/ai-lovable
30svelte: @tanstack/ai-lovable
31preact: @tanstack/ai-lovable
32angular: @tanstack/ai-lovable
33vanilla: @tanstack/ai-lovable
34octane: @tanstack/ai-lovable
35
36<!-- ::end:tabs -->
37
38## Auth
39
40Set `LOVABLE_API_KEY`. Lovable creates this key for each Cloud project.
41
42```bash
43export LOVABLE_API_KEY="..."
44```
45
46You can also pass the key to a `create*` factory:
47
48```typescript
49import { createLovableText } from "@tanstack/ai-lovable"
50
51const adapter = createLovableText(
52 "google/gemini-3.7-flash",
53 process.env.LOVABLE_API_KEY!,
54)
55```
56
57The adapter sends `Authorization: Bearer`, `Lovable-API-Key`, and `X-Lovable-AIG-SDK: tanstack-ai`. Calls go to `https://ai.gateway.lovable.dev/v1`.
58
59## Chat
60
61The default adapter uses the OpenAI Responses API. Model ids use the `google/` or `openai/` form.
62
63**Server.** An endpoint that streams the reply over SSE:
64
65```typescript
66import { chat, toServerSentEventsResponse } from "@tanstack/ai"
67import { lovableText } from "@tanstack/ai-lovable"
68
69export async function POST(request: Request) {
70 const { messages } = await request.json()
71
72 const stream = chat({
73 adapter: lovableText("google/gemini-3.7-flash"),
74 messages,
75 })
76
77 return toServerSentEventsResponse(stream)
78}
79```
80
81**Client.** The same `useChat` hook as every other provider:
82
83```tsx
84import { useState } from "react"
85import { fetchServerSentEvents, useChat } from "@tanstack/ai-react"
86
87export function Chat() {
88 const [input, setInput] = useState("")
89
90 const { messages, sendMessage, isLoading } = useChat({
91 connection: fetchServerSentEvents("/api/chat"),
92 })
93
94 return (
95 <div>
96 {messages.map((message) => (
97 <div key={message.id}>
98 <strong>{message.role}</strong>
99 {message.parts.map((part, index) =>
100 part.type === "text" ? <p key={index}>{part.content}</p> : null,
101 )}
102 </div>
103 ))}
104
105 <form
106 onSubmit={(event) => {
107 event.preventDefault()
108 if (!input.trim() || isLoading) return
109 sendMessage(input)
110 setInput("")
111 }}
112 >
113 <input value={input} onChange={(event) => setInput(event.target.value)} />
114 <button type="submit" disabled={isLoading}>
115 Send
116 </button>
117 </form>
118 </div>
119 )
120}
121```
122
123## Chat Completions
124
125Pass `{ api: "chat" }` when the model must talk to Chat Completions. The default is Responses.
126
127```typescript
128import { chat } from "@tanstack/ai"
129import { lovableText } from "@tanstack/ai-lovable"
130
131const stream = chat({
132 adapter: lovableText("openai/gpt-5.5", { api: "chat" }),
133 messages: [{ role: "user", content: "Hello" }],
134})
135```
136
137`api: "responses"` is the same as the default. `api: "chat-completions"` is the same as `api: "chat"`.
138
139Need a header on each request, or a log of each model call? The chat adapters on this page support [`wrapFetch`](../advanced/middleware#change-the-http-requests-of-a-call).
140
141## Reasoning
142
143Set `reasoning` on `chat()`. The types take the levels of each model:
144
145```typescript
146import { chat } from "@tanstack/ai"
147import { lovableText } from "@tanstack/ai-lovable"
148
149const stream = chat({
150 adapter: lovableText("openai/gpt-5.6-sol"),
151 messages: [{ role: "user", content: "Plan a database migration." }],
152 reasoning: "xhigh",
153})
154```
155
156- Responses (the default) sends `reasoning.effort`. Chat Completions sends `reasoning_effort`.
157- Neither takes `budgetTokens`.
158- The OpenAI and Gemini models take the same levels as on [OpenAI](./openai#reasoning) and [Gemini](./gemini#reasoning).
159
160## Summarize
161
162```typescript
163import { summarize } from "@tanstack/ai"
164import { lovableSummarize } from "@tanstack/ai-lovable"
165
166const result = await summarize({
167 adapter: lovableSummarize("google/gemini-3.7-flash"),
168 text: "The Fender Stratocaster is a versatile electric guitar.",
169})
170```
171
172## Images
173
174Generate a new image, or pass image parts to edit one. OpenAI image models also accept a mask part (`metadata.role === "mask"`).
175
176```typescript
177import { generateImage } from "@tanstack/ai"
178import { lovableImage } from "@tanstack/ai-lovable"
179
180const result = await generateImage({
181 adapter: lovableImage("openai/gpt-image-2"),
182 prompt: "a red guitar on a wooden bench",
183})
184```
185
186## Video
187
188Video jobs are async. Create a job, poll status, then fetch the MP4 URL. Clips last 4, 6, or 8 seconds. You can write `4`, `"4"`, or `"4s"` (same forms for 6 and 8).
189
1901080p and 4K clips are always 8 seconds. `"8s"` counts as 8 seconds. 4K works only on `google/veo-3.1-fast` and `google/veo-3.1`.
191
192```typescript
193import { generateVideo } from "@tanstack/ai"
194import { lovableVideo } from "@tanstack/ai-lovable"
195
196const { jobId } = await generateVideo({
197 adapter: lovableVideo("google/veo-3.1-lite"),
198 prompt: "a red guitar on a wooden bench, slow camera push-in",
199 duration: "4s",
200 size: "1280x720",
201})
202```
203
204Then poll `getVideoJobStatus` with that `jobId`. When the job is complete, the result includes the MP4 URL.
205
206Pass one image part in `prompt` to animate a still frame.
207
208## Embeddings
209
210```typescript
211import { embed } from "@tanstack/ai"
212import { lovableEmbedding } from "@tanstack/ai-lovable"
213
214const result = await embed({
215 adapter: lovableEmbedding("google/gemini-embedding-2"),
216 input: "a red guitar",
217})
218
219console.log(result.embeddings[0]?.vector)
220```
221
222## Speech
223
224```typescript
225import { generateSpeech } from "@tanstack/ai"
226import { lovableSpeech } from "@tanstack/ai-lovable"
227
228const result = await generateSpeech({
229 adapter: lovableSpeech("openai/gpt-4o-mini-tts"),
230 text: "Welcome to the guitar shop.",
231 voice: "nova",
232})
233```
234
235## Transcription
236
237```typescript
238import { generateTranscription } from "@tanstack/ai"
239import { lovableTranscription } from "@tanstack/ai-lovable"
240
241const audio = await fetch("/voice-note.mp3").then((response) => response.blob())
242
243const result = await generateTranscription({
244 adapter: lovableTranscription("openai/gpt-4o-mini-transcribe"),
245 audio,
246 language: "en",
247})
248
249console.log(result.text)
250```
251
252## Bring Your Own Key
253
254Users can paste a Lovable project key in the browser. Import `lovableByok` from `@tanstack/ai-lovable/byok`, not from the package main entry.
255
256```typescript
257import { createLovableText } from "@tanstack/ai-lovable"
258import { lovableByok } from "@tanstack/ai-lovable/byok"
259import { byokMissing, getByokKey } from "@tanstack/ai/byok/server"
260
261export async function POST(request: Request) {
262 const apiKey = getByokKey(request, lovableByok)
263 if (!apiKey) return byokMissing(lovableByok)
264
265 const adapter = createLovableText("google/gemini-3.7-flash", apiKey)
266 // ...
267}
268```
269
270See [Bring Your Own Key](../advanced/byok) for the client store and a save UI.
271
272## Models
273
274Pass a model id from the curated lists. TypeScript rejects an id that is not on a list.
275
276Chat:
277
278- Default: `google/gemini-3.7-flash`
279- Fast OpenAI: `openai/gpt-5.5`
280
281Image, video, embeddings, and speech:
282
283- Image default: `openai/gpt-image-2`
284- Video default: `google/veo-3.1-lite`
285- Embedding default: `google/gemini-embedding-2`
286- Speech default: `openai/gpt-4o-mini-tts`
287- Transcription default: `openai/gpt-4o-mini-transcribe`
288
289The curated lists are `LOVABLE_CHAT_MODELS`, `LOVABLE_IMAGE_MODELS`, `LOVABLE_VIDEO_MODELS`, `LOVABLE_EMBEDDING_MODELS`, `LOVABLE_TTS_MODELS`, and `LOVABLE_TRANSCRIPTION_MODELS`.
290
291## Errors
292
293- `429 Too Many Requests`: the workspace hit its request-per-minute limit.
294- `402 Payment Required`: the workspace is out of credits.
295
296See [Lovable AI features](https://docs.lovable.dev/features/ai) for models, credits, and rate limits.