Feature Overview
Send OpenAI-format edit requests toPOST https://api.laozhang.ai/v1/images/edits through LaoZhang API: upload the original image, a mask, and a prompt to change specific regions of the image. The GPT-Image-1 models are billed by tokens; prices and groups are listed under Pricing and groups in GPT-Image-1 image generation (archived).
Introduction
The Image Edit API allows you to edit specific parts of an image by providing the original image, a mask, and a text prompt. This feature is particularly suitable for:- Localized Modifications: Only modify specific regions of an image
- Content Replacement: Replace certain elements in an image
- Creative Editing: Add new elements while maintaining overall style
- Image Restoration: Repair or improve specific parts of an image
API Working Principle
Image editing requires three key elements:- Original Image: The base image to edit
- Mask Image: Specifies the region to edit (transparent areas will be edited)
- Prompt: Describes what you want to generate in the edited region
Quick Start
The examples on this page use older code:- The Python examples rely on
openai.Image.create_editfrom theopenai0.x SDK. - None of the edit requests set
model, and results are read fromurl.
model to every edit request (for example, model="gpt-image-1") and save b64_json results as described under Response Format.
Basic Configuration
Basic Editing Example
API Parameters
Request Parameters
Response Format
b64_json), never url.
Through LaoZhang API, each item in data[] can contain either b64_json or url, so handle both when saving. For code that saves either format, see Save and check the image in the GPT Image 2.5 guide.
Creating Mask Images
Using Python PIL to Create Masks
Using Circular Mask
Complete Usage Examples
Complete Python Example
Node.js Example
Practical Application Scenarios
1. Background Replacement
2. Object Removal
3. Clothing Change
4. Image Restoration
Advanced Techniques
1. Feathered Mask
Create mask with feathered edges for more natural edits:2. Multi-Region Editing
Edit multiple regions simultaneously:3. Smart Prompt Building
Best Practices
1. Image Preparation
- Format and Dimensions: The image and mask must share the same format and dimensions
- Mask Requirement: The mask must include an alpha channel
- File Size: Under 50MB
- Resolution Recommendation: Use 1024x1024 for best results
2. Mask Design
- Precise Masks: More precise masks yield better editing results
- Edge Handling: Consider using feathered edges for more natural edits
- Region Size: Avoid overly large edit regions, may affect results
3. Prompt Optimization
4. Error Handling
FAQ
Q: Why don’t edit results match expectations?
A: Check if mask is correct, ensuring transparent areas accurately cover parts to edit. Also optimize prompt for more specific descriptions.Q: Which image formats are supported?
A: The image and mask must share the same format and dimensions and be under 50MB, and the mask needs an alpha channel. See the OpenAI image generation guide for details.Q: How to achieve more natural edit results?
A: Use feathered masks and emphasize “natural blending”, “matching surrounding environment” in prompts.Q: Can multiple regions be edited simultaneously?
A: Yes, simply mark multiple transparent areas in the mask.Q: What limitations exist when editing large images?
A: Image files must be under 50MB; compress larger images before uploading.Related Resources
- GPT Image 2.5 API: generate and edit images with the current models
- Nano Banana 2 API: generate and edit images
- Nano Banana Pro image editing
- FLUX image editing
- Choose an image generation API: compare the image models on sale now
- GPT-Image-1 image generation (archived)
- OpenAI image generation guide: official notes on editing with a mask
- PIL/Pillow Documentation
- LaoZhang API Console