A well-designed mobile flow makes background removal feel responsive even when the actual work takes several seconds. A good upload flow manages file size, network changes, progress, and retries without exposing your API credentials.
Validate before uploading
Check the selected file type, dimensions, and size on the device. Resize oversized camera originals when your product does not need their full resolution, but keep enough detail for clean subject edges. Client-side checks save bandwidth and provide faster feedback.
Upload to your backend
The mobile app should send the file to your authenticated backend. Your backend stores the original and calls the background removal API with the secret API key. Never embed the provider key in the application bundle: mobile apps can be inspected after installation.
Give the user clear states
- Uploading: show transfer progress and allow cancellation.
- Processing: confirm that the upload is complete and the image is being analyzed.
- Ready: preview the transparent result and offer export or share actions.
- Retry: explain whether the issue is the file, network, or service.
Handle interrupted connections
Mobile networks can change between Wi-Fi and cellular while a request is in flight. Give each job a stable ID, persist its status on the server, and let the app refresh that status after reconnecting. This is more reliable than assuming the original request remains active.
Cache results by asset
Hash the original file and processing options so reopening an editor does not submit the same image again. Store the transparent result behind a short-lived signed URL or an authenticated media endpoint, depending on your privacy requirements.
Keep the first version simple
Start with one upload endpoint and one processing job. Add background colors, shadows, and generated backgrounds after the core removal path is reliable. The same output can support the web, mobile, and admin interfaces when it is stored as a reusable asset.
A reference architecture
The sections above describe the pieces. Put together, a production mobile flow usually looks like this:
- The user picks or captures a photo. The app normalizes orientation, resizes if needed, and checks format and size.
- The app uploads the file to your backend over an authenticated request and receives a job ID immediately.
- The backend stores the original, records the job as
pending, and hands it to a background worker. - The worker calls the background removal API with your secret key and stores the transparent PNG.
- The app polls the job endpoint or receives a push notification, then downloads the result from your storage.
Splitting upload from processing is what makes the reconnect and retry behavior possible. The upload request finishes quickly, and the slower processing step lives on the server where the network is stable.
Prepare the photo on the device
Phone cameras produce files that need a little care before they reach the API.
| Check | Why it matters | What to do |
|---|---|---|
| File format | The API accepts JPEG, PNG, WebP, BMP, and GIF. Many phones save photos as HEIC by default. | Convert HEIC to JPEG on the device or on your backend before calling the API. |
| File size | The limit is 10 MB per image. Full-resolution camera originals can approach or exceed that. | Downscale to the resolution your product actually displays or exports. |
| Orientation | Many cameras store rotation as an EXIF tag instead of rotating the pixels. If the tag is lost, the result comes back sideways. | Apply the rotation to the pixels before upload, or normalize it on the server. |
| Metadata | EXIF can include GPS coordinates the user did not intend to share. | Strip location data unless your product needs it. |
The processing worker
The worker is where API responses turn into job states the app can display. This Python example maps each status code to one of the user-facing states from earlier.
import requests
API_URL = "https://fapihub.com/v2/rembg/"
API_KEY = "YOUR_API_KEY" # load from your secret store, never ship it in the app
def process_job(job):
with open(job.original_path, "rb") as image_file:
response = requests.post(
API_URL,
headers={"ApiKey": API_KEY},
files={"image": image_file},
timeout=60,
)
if response.status_code == 200:
job.save_result(response.content) # transparent PNG bytes
job.set_status("ready")
return
if response.status_code == 429:
delay = int(response.headers.get("Retry-After", 5))
job.schedule_retry(delay) # app keeps showing "Processing"
return
if response.status_code >= 500:
job.schedule_retry(job.next_backoff()) # not counted against quota
return
error = response.json().get("error", {})
job.set_status("failed", code=error.get("code"), request_id=error.get("request_id"))
Store the request_id from error responses on the job. If a user reports a problem, you can match their job to the exact API request when you contact support.
Turn API errors into useful messages
The retry state works best when the app knows what actually went wrong. A simple mapping:
| API response | What the user should see |
|---|---|
400 invalid_image | "This photo could not be processed. Try a different image." Offer the photo picker again. |
401 invalid_api_key | A generic "Something went wrong on our side." This is a configuration problem, so alert your team instead of the user. |
402 insufficient_credits | Depends on your business model. Either upgrade your plan before it happens or show your own in-app limit message. |
429 rate_limit_exceeded | Nothing new. Keep the job in "Processing" and retry after the Retry-After delay. |
| 5xx | Nothing at first. Retry with backoff, and only show an error after several failed attempts. |
Show and export the result
Preview the transparent PNG over a checkerboard or a neutral color so users can see the cutout edges. Then offer exports that match how people use photos on a phone:
- Transparent PNG for stickers, design apps, and anything that will be layered later.
- JPEG on a solid color for messaging and social sharing, where transparency is often flattened to black or white anyway. Composite on the server, or call
/v2/rembg/color/with abgcolorsuch as"(255, 255, 255, 255)". - Mask if your editor lets users refine edges with a brush. The
/v2/rembg/mask/endpoint returns a black and white subject mask you can edit and reapply. Our image mask API guide explains the workflow.
Estimate monthly usage
Consumer apps are harder to forecast than batch jobs, so model it from active users. Suppose 2,000 monthly active users each process five photos: that is 10,000 requests. That is more than the Pro plan's 7,500 and comfortably inside Ultra's 52,000 at $79 per month. The same volume on Per Usage credits ($10 per 1,000 requests) would cost $100, so the monthly plan wins once usage is steady. Per Usage still makes sense before launch, when volume is unpredictable and you want requests that never expire.
The result cache from earlier reduces this number, because reopening an image does not trigger another request. Compare options on the pricing section, and see the mobile apps use case for more product ideas.
Frequently asked questions
Can my app call the API directly without a backend?
You should not. Calling the API from the app means shipping your API key in the bundle, where it can be extracted. Route requests through your own backend, which also gives you a place to enforce per-user limits.
Does the API accept HEIC photos from iPhones?
HEIC is not in the list of accepted formats, which are JPEG, PNG, WebP, BMP, and GIF. Convert HEIC photos to JPEG on the device or on your server before sending them.
Do failed requests count against my quota?
Successful requests and 4xx client errors count. 5xx server errors do not. That is another reason to validate format and size on the device: a rejected file still uses a request.
Does this work with React Native, Flutter, or native apps?
Yes. The app only talks to your backend, and the backend makes a standard multipart HTTP request. Any client framework that can upload a file works. For backend code samples, see the Python integration guide.