ERNIE-iRAG Edit: Baidu's Official Image Editing API Complete Guide — Erase, Repaint, and Variation
Summary: Baidu Qianfan platform has officially launched the ERNIE-iRAG-Edit image editing model API, supporting three core features: erase (object removal), repaint (inpainting), and variation (style transfer), priced at ¥0.14/image (~$0.02/image). While this isn't the open-source ERNIE-Image editing model the community has been waiting for, it fills the long-standing image editing gap in the ERNIE ecosystem through API service. This article covers everything from basic API calls to best practices for all three editing modes, with comparisons against community alternatives like FLUX Kontext.
The Editing Feature Finally Arrives
The ERNIE-Image community's anticipation for editing capabilities has been building since May 2026. A Reddit post asking "when will the ERNIE editing model be released" gathered 279 upvotes, becoming a focal point of community discussion. While the open-source ERNIE-Image editing model is still in development, Baidu has preemptively released editing capabilities through the ERNIE-iRAG-Edit API on the Qianfan platform — as an API service rather than an open-source model.
Key details:
- Model: ERNIE-iRAG-Edit (Baidu's proprietary image editing model)
- API price: ¥0.14/image (~$0.02/image)
- Endpoint:
POST /v2/images/edits - Auth: API Key (BCE V3 signature)
- Supported models:
ernie-irag-edit,qwen-image-edit
Three Core Editing Modes
ERNIE-iRAG-Edit provides three fundamental editing capabilities, each suited for different editing scenarios.
1. Erase (Object Removal)
Removes objects selected by a mask from the image.
Parameters:
feature:"erase"image: Original image URL or Base64mask: Mask image (white pixels = remove area, black pixels = keep area)prompt: Optional (can be omitted in erase mode)
Output size rule: Maintains original aspect ratio. Short edge < 512 → preserved at 512; long edge > 1280 → cropped to 1280. For example, a 500×1000 input produces a 512×1024 output.
Use cases:
- Removing bystanders or distractions from photos
- Clearing unwanted background elements from product shots
- Erasing watermarks or decorative elements
2. Repaint (Inpainting)
Redraws the masked region based on a text prompt, ideal for local modifications.
Parameters:
feature:"repaint"image: Original imagemask: Mask image (white pixels = repaint area)prompt: Required, describing the new content
Use cases:
- Changing a person's clothing or hairstyle
- Replacing specific background elements
- Enriching local details (adding decorations, adjusting colors)
- Subject replacement (e.g., cat → dog)
3. Variation (Style Transfer)
Generates a new image referencing both the prompt and source image, maintaining background, clothing, and pose characteristics.
Parameters:
feature:"variation"image: Reference image (no mask needed)prompt: Required, describing the desired variation
Output size rule: Maintains aspect ratio, scaled to total pixels of 1,048,576 (1024×1024), edges as multiples of 16, max edge ≤ 1440.
Use cases:
- Generating different scene photos while keeping character features
- Product image scene variations (same product, different backgrounds)
- Stylized versions maintaining original composition
API Call Guide
Python Example
import requests
import json
def edit_image(api_key, feature, image_url, prompt="", mask_url=None):
"""
ERNIE-iRAG-Edit API call
Parameters:
api_key: Baidu Qianfan API Key
feature: "erase" / "repaint" / "variation"
image_url: Original image URL
prompt: Positive prompt (optional for erase)
mask_url: Mask image URL (not needed for variation)
"""
url = "https://qianfan.baidubce.com/v2/images/edits"
payload = {
"model": "ernie-irag-edit",
"image": image_url,
"feature": feature,
}
if prompt:
payload["prompt"] = prompt
if mask_url and feature in ["erase", "repaint"]:
payload["mask"] = mask_url
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
response = requests.post(url, headers=headers, json=payload)
return response.json()
Example: Erase object
result = edit_image(
api_key="your-api-key",
feature="erase",
image_url="https://example.com/original.jpg",
mask_url="https://example.com/mask.jpg"
)
Example: Repaint object
result = edit_image(
api_key="your-api-key",
feature="repaint",
image_url="https://example.com/original.jpg",
prompt="Change to blue jeans",
mask_url="https://example.com/leg-mask.jpg"
)
Example: Generate variation
result = edit_image(
api_key="your-api-key",
feature="variation",
image_url="https://example.com/product.jpg",
prompt="Place the product in a natural outdoor scene with sunshine"
)
Base64 Upload
For images not available at public URLs, use Base64 encoding:
import base64
def image_to_base64(image_path):
with open(image_path, "rb") as f:
return f"data:image/png;base64,{base64.b64encode(f.read()).decode()}"
Call with Base64
image_b64 = image_to_base64("local_image.png")
result = edit_image(
api_key="your-api-key",
feature="repaint",
image_url=image_b64,
prompt="New description",
mask_url=image_to_base64("local_mask.png")
)
Limitations and Considerations
| Limitation | Detail |
|---|---|
| Prompt length | ≤ 220 characters (Chinese/English) |
| Image formats | PNG / JPG / JPEG / WEBP / BMP / ICO |
| File size | ≤ 10MB |
| Aspect ratio | ≤ 4:1 |
| Min dimensions | Single edge ≥ 128px (recommended > 512px) |
| URL validity | Returned URLs expire after 24 hours |
| Concurrency | High-frequency calls may timeout — limit concurrency |
| Batch size | Max n=4 per request (qwen-image-edit: n=1 only) |
ERNIE-iRAG-Edit vs Community Alternatives
| Feature | ERNIE-iRAG-Edit API | FLUX Kontext | ComfyUI Inpainting |
|---|---|---|---|
| Access | API call | Open-source model | Local ComfyUI |
| Price | ¥0.14/image | Own GPU | Own GPU |
| Erase | ✅ | ✅ | ✅ |
| Repaint | ✅ | ✅ | ✅ |
| Variation | ✅ | ❌ | Requires setup |
| Chinese | ✅ Excellent | ⚠️ Moderate | Model-dependent |
| Setup | Zero deployment | GPU environment | ComfyUI config |
| Best for | Quick integration, no GPU | Deep customization | Advanced workflows |
The biggest advantage of ERNIE-iRAG-Edit API is zero deployment cost and excellent Chinese editing capability. If your need is to quickly integrate image editing into an application or handle Chinese prompt editing tasks, the API approach is the most direct choice.
Relationship with ERNIE-Image
It's important to note that ERNIE-iRAG-Edit is an independent image editing model on Baidu's Qianfan platform, separate from the open-source ERNIE-Image 8B DiT model. However, both belong to the ERNIE ecosystem and share a common technical lineage.
The open-source ERNIE-Image editing model the community expects is still under development. When it's released, developers will have more choices: API for quick integration, open-source for deep customization.
Pricing Analysis
| Operation | Price | Use Case |
|---|---|---|
| erase | ¥0.14/image | Remove unwanted elements |
| repaint | ¥0.14/image | Local modifications, style adjustment |
| variation | ¥0.14/image | Scene variations, stylized versions |
For batch editing at 100 images/day:
- Daily cost: ¥14 (~$2)
- Monthly cost: ¥420 (~$60)
Compared to self-hosted GPU editing services (typically ¥1000+/month for GPU costs), the API approach has a clear cost advantage for small-to-medium scale scenarios.
Sources: Baidu Qianfan developer documentation, qianfan.cloud.baidu.com, Baidu Intelligent Cloud official announcements