Skip to main content
Version: 1.11.0-beta

Nanobanana Model

The Nanobanana model (google/nano-banana) is a powerful Replicate-based AI model that supports image generation, combination, and editing capabilities. It uses a unified architecture where all operations are handled through a prompt and optional image inputs, but the SDK provides separate methods for clarity and type safety.

Features

  • Image Generation: Create images from text prompts with optional reference images
  • Image Combination: Combine 2-10 images with a text prompt
  • Image Editing: Edit existing images with text prompts

Image Generation

Using JSON

const client = new ImagineoAIClient(apiUrl, { apiKey: 'your-api-key' });

// Generate image with Nanobanana
const result = await client.images.generate({
prompt: "A beautiful sunset over mountains",
model_type: "nanobanana",
reference_image_url: "https://example.com/reference.jpg" // optional
});

Parameters

  • prompt (string, required): Text description of the image to generate
  • model_type (string, required): Must be set to "nanobanana"
  • reference_image_url (string, optional): URL of reference image for style guidance

Image Combination

Using JSON

// Method 1: Using the generic combine method
const result = await client.images.combine({
prompt: "Blend these images into a cohesive scene",
model: "nanobanana",
reference_urls: [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg",
"https://example.com/image3.jpg"
]
});

// Method 2: Using the dedicated nanobanana.json method
const result = await client.images.combine.nanobanana.json({
prompt: "Blend these images into a cohesive scene",
image_urls: [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg",
"https://example.com/image3.jpg"
],
// Or use run_ids from previous generations
run_ids: ["run_123", "run_456"]
});

Using FormData

// Using the dedicated nanobanana.formData method
const result = await client.images.combine.nanobanana.formData({
prompt: "Combine these images creatively",
files: [file1, file2, file3], // File or Blob objects
// Can also mix with URLs and run IDs
image_urls: ["https://example.com/extra.jpg"],
run_ids: ["run_789"]
});

Parameters

For the generic combine method:

  • prompt (string, required): Text description for combining images
  • model (string, required): Must be set to "nanobanana"
  • reference_urls (array, optional): Array of 2-10 image URLs
  • run_ids (array, optional): Array of 2-10 run IDs from previous generations

For combine.nanobanana.json:

  • prompt (string, required): Text description for combining images
  • image_urls (array, optional): Array of image URLs
  • run_ids (array, optional): Array of run IDs from previous generations

For combine.nanobanana.formData:

  • prompt (string, required): Text description for combining images
  • files (array, optional): Array of File/Blob objects
  • image_urls (array, optional): Array of image URLs
  • run_ids (array, optional): Array of run IDs from previous generations

Note: Total images from all sources must be between 2-10 for combination.

Image Editing

Using JSON

// Edit an image with Nanobanana
const result = await client.images.edit.nanobanana.json({
prompt: "Add a rainbow to the sky",
image_url: "https://example.com/original.jpg",
// OR use a previous run
original_run_id: "run_12345"
});

Using FormData

// Edit an image with file upload
const result = await client.images.edit.nanobanana.formData({
prompt: "Transform this into a watercolor painting",
file: imageFile // File or Blob object
});

Parameters

For JSON method:

  • prompt (string, required): Text description of the edit
  • image_url (string, optional): URL of the image to edit
  • original_run_id (string, optional): ID of a previous run to edit

For FormData method:

  • prompt (string, required): Text description of the edit
  • file (File/Blob, optional): Image file to edit
  • image_url (string, optional): URL of the image to edit
  • original_run_id (string, optional): ID of a previous run to edit

Note: At least one of file, image_url, or original_run_id must be provided.

Response Format

All Nanobanana operations return a standard GenerateImageOutput object:

{
success: boolean;
run_id: string;
status: string;
created_at: string;
prompt: string;
images?: Array<{
url: string;
width: number;
height: number;
}>;
error?: string;
}

Error Handling

try {
const result = await client.images.generate({
prompt: "A scenic landscape",
model_type: "nanobanana"
});
console.log("Generated image:", result);
} catch (error) {
console.error("Generation failed:", error.message);
}

Technical Architecture

Under the hood, Nanobanana uses a unified API where all operations are determined by:

  • Generation: No images provided (or optional reference images)
  • Edit: Exactly 1 image provided
  • Combine: 2-10 images provided

The backend automatically routes to the appropriate operation based on the number of images, while the SDK maintains separate methods for better developer experience and type safety.

Model Capabilities

Nanobanana excels at:

  • Style Transfer: Using reference images to guide generation style
  • Creative Combinations: Blending multiple images intelligently
  • Prompt-Based Editing: Making specific changes based on text descriptions
  • Batch Processing: Handling multiple reference images efficiently

Best Practices

  1. Image Quality: Use high-quality reference images for better results
  2. Clear Prompts: Be specific and descriptive in your prompts
  3. File Sizes: Keep uploaded files under 10MB for optimal performance
  4. Rate Limiting: Implement appropriate delays between requests
  5. Error Handling: Always wrap API calls in try-catch blocks

Examples

Complete Generation Example

import { ImagineoAIClient } from '@imagineoai/javascript';

const client = new ImagineoAIClient(apiUrl, {
apiKey: process.env.IMAGINEOAI_API_KEY
});

async function generateWithNanobanana() {
try {
// Simple generation
const simple = await client.images.generate({
prompt: "A futuristic cityscape at night",
model_type: "nanobanana"
});

// With reference image
const withReference = await client.images.generate({
prompt: "A futuristic cityscape at night",
model_type: "nanobanana",
reference_image_url: "https://example.com/style-reference.jpg"
});

console.log("Generated images:", { simple, withReference });
} catch (error) {
console.error("Generation failed:", error);
}
}

Complete Combination Example

async function combineImagesWithNanobanana() {
// Method 1: Using the generic combine with model parameter
const genericResult = await client.images.combine({
prompt: "Create a panoramic view from these images",
model: "nanobanana",
reference_urls: [
"https://example.com/left.jpg",
"https://example.com/center.jpg",
"https://example.com/right.jpg"
]
});

// Method 2: Using dedicated nanobanana.json method
const jsonResult = await client.images.combine.nanobanana.json({
prompt: "Create a panoramic view from these images",
image_urls: [
"https://example.com/left.jpg",
"https://example.com/center.jpg",
"https://example.com/right.jpg"
]
});

// Method 3: Using formData with file uploads
const fileInput = document.getElementById('multiFileInput');
const files = Array.from(fileInput.files);

const formDataResult = await client.images.combine.nanobanana.formData({
prompt: "Merge these uploaded images seamlessly",
files: files // 2-10 files
});

// Method 4: Mixing different sources
const mixedResult = await client.images.combine.nanobanana.formData({
prompt: "Combine all these sources",
files: [file1, file2],
image_urls: ["https://example.com/extra.jpg"],
run_ids: ["run_123", "run_456"]
});
}

Complete Edit Example

async function editWithNanobanana() {
// Edit from URL
const urlEdit = await client.images.edit.nanobanana.json({
prompt: "Add snow to this scene",
image_url: "https://example.com/landscape.jpg"
});

// Edit from file upload
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];

const fileEdit = await client.images.edit.nanobanana.formData({
prompt: "Convert to black and white with high contrast",
file: file
});

// Edit from previous generation
const runEdit = await client.images.edit.nanobanana.json({
prompt: "Make it more vibrant and colorful",
original_run_id: "run_abc123"
});
}

See Also