This example demonstrates how to generate images using Google's Imagen model through the Langbase Images API.


Generate Image with Google Example

Generate Image with Google

import 'dotenv/config'; import { Langbase } from 'langbase'; const langbase = new Langbase({ apiKey: process.env.LANGBASE_API_KEY!, }); async function main() { // Check if API keys are available if (!process.env.LANGBASE_API_KEY) { console.error('❌ LANGBASE_API_KEY is not set in environment variables'); return; } if (!process.env.GOOGLE_API_KEY) { console.error('❌ GOOGLE_API_KEY is not set in environment variables'); console.log('Please add your Google API key to the .env file'); return; } const result = await langbase.images.generate({ prompt: "A peaceful zen garden with cherry blossoms and a traditional Japanese bridge", model: "google:gemini-2.5-flash-image-preview", apiKey: process.env.GOOGLE_API_KEY! }); console.log('✅ Image generated successfully!'); console.log('Image URL:', result.choices[0].message.images[0].image_url.url); } main();