Yesterday's Top Poster

Gemini 3.1 Flash Image Preview now available in AI Gateway

Google's Gemini 3.1 Flash Image Preview, also known as Nano Banana 2, is now available through AI Gateway. You can call this image generation model from Netlify Functions without configuring API keys; the AI Gateway provides the connection to Google for you. Example usage in a Function: import { GoogleGenAI } from '@google/genai'; export default async (request: Request) => { const url = new URL(request.url); const prompt = url.searchParams.get('prompt') || 'two happy bananas'; const ai = new GoogleGenAI({}); try { const response = await ai.models.generateContent({ model: 'gemini-3.1-flash-image-preview', contents: prompt, config: { imageConfig: { aspectRatio: '16:9', imageSize: '1K' } } }); let imagePart = null; for (const part of response.candidates[0].content.parts) { if (part.inlineData) { imagePart = part.inlineData; break; } } const bytes = Buffer.from(imagePart.data, 'base64'); const mimeType = imagePart.mimeType || 'image/png'; return new Response(bytes, { status: 200, headers: { 'Content-Type': mimeType, 'Cache-Control': 'no-store' } }); } catch (err) { return new Response(JSON.stringify({ error: String(err), prompt }), { status: 500, headers: { 'Content-Type': 'application/json' } }); } }; This model works across any function type and is compatible with other Netlify primitives such as caching and rate limiting, giving you control over request behavior across your site. Learn more in the AI Gateway documentation.

Continue reading...
 
Back
Top