Guide

How to Generate Images with Gemini 3 Pro Image via the API (Updated Feb 2026)

A step-by-step guide to generating images with Google's Gemini 3 Pro Image model using the Gemini API, with Python and Node.js examples.

By AI Coding Tools Directory2026-02-255 min read
Last reviewed: 2026-02-25
ACTD
AI Coding Tools Directory

Editorial Team

The AI Coding Tools Directory editorial team researches and reviews AI-powered development tools to help developers find the best solutions for their workflows.

The Gemini 3 Pro Image model (also known as "Nano Banana Pro") is Google's professional-grade image generation model, available through both the Gemini API and Vertex AI. It supports high-fidelity image generation up to 4K resolution, advanced text rendering, multi-image composition, and image editing.

What the Model Can Do

  • Image generation up to 4K resolution from text prompts
  • Text rendering in images with multilingual support
  • Multi-image composition with up to 14 reference images
  • Character consistency for up to 5 people across images
  • Image editing with local masks and inpainting
  • Aspect ratios: 1:1, 3:2, 2:3, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, and 21:9

Step 1 --- Get a Gemini API Key

  1. Go to Google AI Studio.
  2. Click Get API key and create or select a Google Cloud project.
  3. Copy the key (starts with AIza...). Store it securely---never commit it to version control.
export GEMINI_API_KEY="your_key_here"

Step 2 --- Install the SDK

Python:

pip install google-generativeai

Node.js:

npm install @google/generative-ai

Step 3 --- Generate an Image (Python)

import os
import google.generativeai as genai

genai.configure(api_key=os.environ["GEMINI_API_KEY"])

model = genai.GenerativeModel("gemini-3-pro-image-preview")

prompt = "A serene Japanese garden at sunset with a koi pond and wooden bridge"
response = model.generate_content([prompt])

if response.candidates:
    image_bytes = response.candidates[0].content.parts[0].inline_data.data
    with open("image.png", "wb") as f:
        f.write(image_bytes)
    print("Saved image.png")
else:
    print("No image generated")

Step 4 --- Generate an Image (Node.js)

import fs from "fs/promises";
import { GoogleGenerativeAI } from "@google/generative-ai";

const apiKey = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: "gemini-3-pro-image-preview" });

async function run() {
  const prompt =
    "Product shot of matte black wireless headphones on a gray gradient background";
  const result = await model.generateContent([prompt]);
  const data =
    result.response.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;
  if (!data) {
    console.log("No image generated");
    return;
  }
  await fs.writeFile("product.png", Buffer.from(data, "base64"));
  console.log("Saved product.png");
}

run().catch(console.error);

Step 5 --- Write Better Prompts

Good image prompts are specific. Include details about:

  • Subject: What is in the image
  • Style: Photorealistic, illustration, watercolor, etc.
  • Lighting: Natural, studio, golden hour, etc.
  • Composition: Close-up, wide shot, aerial view, etc.
  • Aspect ratio: Specify if you need a non-square output

Example of a detailed prompt:

A photorealistic close-up of a ceramic coffee mug on a rustic wooden table,
morning sunlight streaming through a window, shallow depth of field,
warm color palette, 16:9 aspect ratio

Step 6 --- Optimize for Cost and Quality

The model supports parameters for tuning the quality/cost trade-off:

  • thinking_level: Set to low for faster, cheaper generation or high for maximum quality
  • media_resolution: Choose low, medium, or high based on your needs
  • Input limits: 7 MB for direct uploads, 30 MB via Cloud Storage
  • Max images per prompt: 14

Important Considerations

  • Follow Google's usage policies for generated content
  • The model is currently in public preview---check the docs for any changes to availability or pricing
  • API keys should always be stored in environment variables or secret managers, never in code
  • Check ai.google.dev/pricing for current rate limits and costs

Sources


For more on Google's AI models, see our Gemini coverage in the directory.

Get the Weekly AI Tools Digest

New tools, comparisons, and insights delivered regularly. Join developers staying current with AI coding tools.

Frequently Asked Questions

How do I get started with Generate Images with Gemini 3 Pro Image via the API (Updated Feb 2026)?
A step-by-step guide to generating images with Google's Gemini 3 Pro Image model using the Gemini API, with Python and Node.js examples.