Replace Background
Replace or swap the background of any image while preserving the foreground subject using the Image Generation API.
Overview
Replace Background API
Name
Value
Input photo + prompt
│
▼
[Gemini model understands
subject vs. background]
│
▼
New background rendered
around the subject
│
▼
Output image returnedApproach
When to Use
Models
Supported Models
Model
Speed
Max Resolution
Max Source Images
Best For
Quick Start
Request Reference
Required Fields
Field
Type
Description
Optional Fields
Field
Type
Default
Description
Valid aspect_ratio Values
Payloads by Use Case
1. Simple Background Swap
2. Outdoor / Scenic Background
3. Product Photography Background
4. Background Matching a Reference Image
5. Virtual Meeting / Office Background
6. Real-World Context with Search Grounding
7. Multiple Variations in One Request
Prompt Writing Guide
Always Anchor the Subject
Describe the New Background Specifically
Specify Lighting to Match the Subject
Use Negative Instructions When Needed
Run the API
Last updated