Nano Banana 2 Lite (Gemini 3.1 Flash-Lite Image) is now available in AI Gateway.
June 30, 2026
Google’s Nano Banana 2 Lite (Gemini 3.1 Flash-Lite Image) is now available through AI Gateway. You can call this lightweight 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';
// Netlify Function: Generate an image with Gemini 3.1 Flash Lite Image and return it directly.// Usage (GET): /.netlify/functions/gemini-31-flash-lite-image?prompt=Your+prompt+here// Returns: binary image (PNG/JPEG/etc) with proper content-type. If no image, JSON error.
export default async (request: Request) => { const url = new URL(request.url); const prompt = url.searchParams.get('prompt') || 'two happy bananas holding flashlights'; const ai = new GoogleGenAI({});
try { const response = await ai.models.generateContent({ model: 'gemini-3.1-flash-lite-image', 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' } }); }};Built for speed and lower cost, Gemini 3.1 Flash-Lite Image is a good fit for high-volume image generation. It 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.