Description
I tried using the Gemini image output, but found that when used with streamText, the response was very slow (tens of seconds to 1 minute).
To figure out where the issue was, I tried using generateText, and this time I got the result quickly (within seconds).
I also tried to call the API (/v1beta/models/gemini-2.0-flash-exp:streamGenerateContent?alt=sse) with curl directly, which also response very fast. So I guess there's something happening inside streamText
Here's the minimal test code:
Code example
import { google } from '@ai-sdk/google'
import { generateText, streamText } from 'ai'
const model = google('gemini-2.0-flash-exp')
const result = await generateText({
model,
providerOptions: {
google: { responseModalities: ['TEXT', 'IMAGE'] },
},
prompt: 'Generate an image of a black cat',
})
console.log('non stream result', result)
const streamResult = streamText({
model,
providerOptions: {
google: { responseModalities: ['TEXT', 'IMAGE'] },
},
prompt: 'Generate an image of a black cat',
})
for await (const chunk of streamResult.fullStream) {
console.log(chunk)
}
AI provider
@ai-sdk/google: 1.2.1
Additional context
Node.js 23
Description
I tried using the Gemini image output, but found that when used with streamText, the response was very slow (tens of seconds to 1 minute).
To figure out where the issue was, I tried using generateText, and this time I got the result quickly (within seconds).
I also tried to call the API (
/v1beta/models/gemini-2.0-flash-exp:streamGenerateContent?alt=sse) with curl directly, which also response very fast. So I guess there's something happening insidestreamTextHere's the minimal test code:
Code example
AI provider
@ai-sdk/google: 1.2.1
Additional context
Node.js 23