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
139## Summarize
140
141```typescript
142import { summarize } from "@tanstack/ai"
143import { lovableSummarize } from "@tanstack/ai-lovable"
144
145const result = await summarize({
146 adapter: lovableSummarize("google/gemini-3.7-flash"),
147 text: "The Fender Stratocaster is a versatile electric guitar.",
148})
149```
150
151## Images
152
153Generate a new image, or pass image parts to edit one. OpenAI image models also accept a mask part (`metadata.role === "mask"`).
154
155```typescript
156import { generateImage } from "@tanstack/ai"
157import { lovableImage } from "@tanstack/ai-lovable"
158
159const result = await generateImage({
160 adapter: lovableImage("openai/gpt-image-2"),
161 prompt: "a red guitar on a wooden bench",
162})
163```
164
165## Video
166
167Video jobs are async. Create a job, poll status, then fetch the MP4 URL. Clips last 4, 6, or 8 seconds. 1080p and 4K clips are always 8 seconds. 4K works only on `google/veo-3.1-fast` and `google/veo-3.1`.
168
169```typescript
170import { generateVideo } from "@tanstack/ai"
171import { lovableVideo } from "@tanstack/ai-lovable"
172
173const { jobId } = await generateVideo({
174 adapter: lovableVideo("google/veo-3.1-lite"),
175 prompt: "a red guitar on a wooden bench, slow camera push-in",
176 duration: 4,
177 size: "1280x720",
178})
179```
180
181Then poll `getVideoJobStatus` with that `jobId`. When the job is complete, the result includes the MP4 URL.
182
183Pass one image part in `prompt` to animate a still frame.
184
185## Embeddings
186
187```typescript
188import { embed } from "@tanstack/ai"
189import { lovableEmbedding } from "@tanstack/ai-lovable"
190
191const result = await embed({
192 adapter: lovableEmbedding("google/gemini-embedding-2"),
193 input: "a red guitar",
194})
195
196console.log(result.embeddings[0]?.vector)
197```
198
199## Speech
200
201```typescript
202import { generateSpeech } from "@tanstack/ai"
203import { lovableSpeech } from "@tanstack/ai-lovable"
204
205const result = await generateSpeech({
206 adapter: lovableSpeech("openai/gpt-4o-mini-tts"),
207 text: "Welcome to the guitar shop.",
208 voice: "nova",
209})
210```
211
212## Transcription
213
214```typescript
215import { generateTranscription } from "@tanstack/ai"
216import { lovableTranscription } from "@tanstack/ai-lovable"
217
218const audio = await fetch("/voice-note.mp3").then((response) => response.blob())
219
220const result = await generateTranscription({
221 adapter: lovableTranscription("openai/gpt-4o-mini-transcribe"),
222 audio,
223 language: "en",
224})
225
226console.log(result.text)
227```
228
229## Bring Your Own Key
230
231Users can paste a Lovable project key in the browser. Import `lovableByok` from `@tanstack/ai-lovable/byok`, not from the package main entry.
232
233```typescript
234import { createLovableText } from "@tanstack/ai-lovable"
235import { lovableByok } from "@tanstack/ai-lovable/byok"
236import { byokMissing, getByokKey } from "@tanstack/ai/byok/server"
237
238export async function POST(request: Request) {
239 const apiKey = getByokKey(request, lovableByok)
240 if (!apiKey) return byokMissing(lovableByok)
241
242 const adapter = createLovableText("google/gemini-3.7-flash", apiKey)
243 // ...
244}
245```
246
247See [Bring Your Own Key](../advanced/byok) for the client store and a save UI.
248
249## Models
250
251Pass a model id from the curated lists. TypeScript rejects an id that is not on a list.
252
253Chat:
254
255- Default: `google/gemini-3.7-flash`
256- Fast OpenAI: `openai/gpt-5.5`
257
258Image, video, embeddings, and speech:
259
260- Image default: `openai/gpt-image-2`
261- Video default: `google/veo-3.1-lite`
262- Embedding default: `google/gemini-embedding-2`
263- Speech default: `openai/gpt-4o-mini-tts`
264- Transcription default: `openai/gpt-4o-mini-transcribe`
265
266The curated lists are `LOVABLE_CHAT_MODELS`, `LOVABLE_IMAGE_MODELS`, `LOVABLE_VIDEO_MODELS`, `LOVABLE_EMBEDDING_MODELS`, `LOVABLE_TTS_MODELS`, and `LOVABLE_TRANSCRIPTION_MODELS`.
267
268## Errors
269
270- `429 Too Many Requests`: the workspace hit its request-per-minute limit.
271- `402 Payment Required`: the workspace is out of credits.
272
273See [Lovable AI features](https://docs.lovable.dev/features/ai) for models, credits, and rate limits.