Hey everyone! I’ve seen that Gemini supports structured output, but I cannot find info about if this works with stream responses. So for example in this code, is there any way I can specify the structure of response?
const handleGemini = async (prompt: string, res: Response) => {
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY!);
const model = genAI.getGenerativeModel({ model: "gemini-2.5-pro-exp-03-25" });
const result = await model.generateContentStream([{ text: prompt }]);
for await (const chunk of result.stream) {
const text = chunk.text();
if (text) {
res.write(text);
}
}
return res.end();
};