Skip to main content
Use Nano Banana 2 and Nano Banana Pro through RunBridge AI with the Google Gen AI SDK and the Gemini generateContent API. This guide covers:
  • Text-to-image generation
  • Image-to-image editing
  • Multi-image composition
  • Saving generated images
The examples use gemini-3.1-flash-image for Nano Banana 2. The API reference also includes separate Nano Banana Pro and Lite examples.
  • Base URL: https://api.runbridge.ai
  • Install the SDK: pip install google-genai (Python) or npm install @google/genai (Node.js)

Setup

Initialize the client with RunBridge AI’s base URL:

Text-to-image generation

Generate an image from a text prompt and save it to a file.
Save the final image part: The image data is in candidates[0].content.parts, which can contain text and/or image parts. Gemini image models can also return intermediate thought parts before the final image, especially when you request both text and images or explicitly enable thinking output. Do not save the first inlineData blindly; skip parts where thought is true, then save the last remaining image part. Read its mimeType and use the matching file extension: .jpg for image/jpeg, .png for image/png, or .webp for image/webp. The examples write the returned bytes directly without converting the image format. Typical response with only the final image:
Response with a text part, an intermediate thought image, and the final image:
Use this parsing rule for every Gemini image response:

Image-to-image generation

Save a JPEG input as source.jpg in your working directory, then transform it with a text prompt. The Shell example prepares the Base64 JSON body locally before sending one API request.
  • The Python SDK accepts PIL.Image objects directly — no manual Base64 encoding needed.
  • Do not include the data:image/jpeg;base64, prefix when passing raw Base64 strings.

Multi-image composition

Generate a new image from multiple input images. RunBridge AI supports two approaches:

Method 1: Single collage image

Combine the source images into collage.jpg in your working directory, then describe the desired output.
Input collage example
Generated output

Method 2: Multiple separate images (up to 14)

Pass multiple images directly. Save three JPEG inputs as image1.jpg, image2.jpg, and image3.jpg in your working directory. Nano Banana 2 and Pro support up to 14 reference images:
Multi-image generation result

4K image generation

Specify image_config with aspect_ratio and image_size for high-resolution output:
For high-resolution requests, judge the output by the final non-thought image part. If your integration saves the first inlineData part, it may save an intermediate thought image that is lower resolution than the requested imageSize.

Multi-turn image editing (chat)

Use the SDK’s chat feature to iteratively refine images:

Tips

Specify style keywords (e.g., “cyberpunk, film grain, low contrast”), aspect ratio, subject, background, lighting, and detail level.
When using raw HTTP, do not include data:image/png;base64, prefix — use only the raw Base64 string. The Python SDK handles this automatically with PIL.Image objects.
Set "responseModalities" to ["IMAGE"] to request image-only output.
Check whether your code saved an intermediate thought image. Gemini image responses may include image parts where thought is true; these are not the final output. Skip thought: true parts and save the last image part where inlineData exists and thought is not true. If you do not need text output, request "responseModalities": ["IMAGE"] to reduce mixed text/image response handling.
For more details, see the API Reference. Official documentation: Nano Banana image generation
Last modified on October 9, 2026