POST /api/inpaint-image
Performs inpainting operations on images using AI to either remove unwanted objects or add new ones based on a mask and prompt. This endpoint uses the Qwen Image Edit Inpaint model to make targeted edits.Authentication
This endpoint requires authentication. Include your session token in the request.Request Body
The ID of the source image to edit. Can be an original upload or a previously processed image.
Base64-encoded data URL of the mask image (PNG format). White pixels indicate areas to edit, black pixels are preserved.
Description of what to add or how to fill the masked area. For remove mode, describe how to fill the space (e.g., “clean wall”).
Edit mode:
remove to remove objects or add to add objects.If true, deletes any newer versions in the edit history before creating this edit.
Request Example
Request (Remove Mode)
Request (Add Mode)
Response
Indicates whether the inpainting completed successfully.
The URL of the edited image stored in Supabase.
The ID of the newly created image generation record for this edit.
The version number of this edit in the history chain.
Error message if the request failed.
Additional error details for debugging.
Response Examples
Status Codes
Image edited successfully.
Missing required fields (
imageId, prompt, or maskDataUrl).Source image not found in database.
Inpainting failed due to AI service error or internal error.
Processing Flow
- Validation - Verifies required fields and image existence
- Source Selection - Uses result image if available, otherwise original
- Image Preparation - Fetches source image and extracts dimensions
- Mask Processing - Decodes base64 mask and resizes to match source dimensions
- Upload to Fal.ai - Uploads both image and mask to Fal.ai storage
- AI Inpainting - Calls Qwen Image Edit Inpaint model
- Save Result - Downloads and stores the result in Supabase
- Create Version - Creates new image generation record as next version
- Update Counts - Updates project’s image counts
Edit Mode Comparison
Remove Mode
Removes objects from the masked area and fills with contextually appropriate content based on the prompt.Example: Remove furniture → prompt: “clean hardwood floor”
Add Mode
Adds new objects to the masked area based on the prompt description.Example: Add furniture → prompt: “modern gray sectional sofa”
Both modes use the same Qwen Image Edit Inpaint model. The prompt determines what appears in the masked area.
Version History
Each inpaint operation creates a new version of the image:Replace Newer Versions
When editing an older version withreplaceNewerVersions: true:
- All versions newer than the current one are deleted
- The new edit becomes the latest version
- Version numbers continue from where they left off
Mask Format
The mask must be provided as a base64-encoded PNG data URL:AI Model Configuration
This endpoint uses the Qwen Image Edit Inpaint model:Description of what to generate in the masked area.
Source image URL (uploaded to Fal.ai storage).
Mask image URL (uploaded to Fal.ai storage).
Output format for the edited image.
Optional Parameters
The model supports additional parameters (not exposed by default):num_inference_steps(default: 30) - More steps = higher qualityguidance_scale(default: 4) - Balance between prompt adherence and qualitystrength(default: 0.93) - Strength of the noising processseed- For reproducible resultsnegative_prompt- Terms to avoid in generation
Image Processing Details
Mask Resizing
Masks are automatically resized using Sharp:Storage Organization
Edited images follow this path structure:Error Handling
Common error scenarios:Usage Tips
Related Endpoints
- Process Image - Apply style transformations
- Image Status - Check processing status