Skip to content

Background Remove API ​

Remove the background from an image and receive the processed image as Base64. Two endpoints are available:

EndpointUse when
POST /v2/removeBackgroundOutput quality is more important than processing speed.
POST /v2/removeBackgroundFastLower latency is more important for your workflow.

This API removes a background only. It does not crop an image to a passport or visa specification. Use the Passport Photo API when you need a complete ID-photo workflow.

API endpoint ​

Use the region configured for your account:

  • https://api-us.idphotoapp.com — US region
  • https://api-eu.idphotoapp.com — EU region

Send credentials from your server. Do not expose your API secret in browser or mobile application code.

Request ​

Both endpoints use the same request model.

FieldTypeRequiredDescription
apiKeystringYesYour API key.
apiSecretstringYesYour API secret.
imageBase64stringYesBase64-encoded input image. Include a valid image data URI prefix.
outputFormatstringYesJPEG or PNG. Use PNG when the output must preserve transparency.
outputTypestringYesOutput representation configured for this endpoint. Use IMAGE_BASE64.
json
{
  "apiKey": "your-api-key",
  "apiSecret": "your-api-secret",
  "imageBase64": "data:image/jpeg;base64,...",
  "outputFormat": "PNG",
  "outputType": "IMAGE_BASE64"
}

Response ​

json
{
  "output": "iVBORw0KGgoAAAANSUhEUgAA..."
}

output contains the processed image as Base64. Decode it as binary data before saving it. When requesting PNG, save the result with a .png extension.

Python example ​

python
import base64
import os

import requests

base_url = "https://api-us.idphotoapp.com"

with open("portrait.jpg", "rb") as image_file:
    image_base64 = base64.b64encode(image_file.read()).decode("ascii")

response = requests.post(
    f"{base_url}/v2/removeBackground",
    json={
        "apiKey": os.environ["IDPHOTO_API_KEY"],
        "apiSecret": os.environ["IDPHOTO_API_SECRET"],
        "imageBase64": f"data:image/jpeg;base64,{image_base64}",
        "outputFormat": "PNG",
        "outputType": "IMAGE_BASE64",
    },
    timeout=120,
)
response.raise_for_status()

with open("portrait-no-background.png", "wb") as output_file:
    output_file.write(base64.b64decode(response.json()["output"]))

Usage notes ​

  • Prefer a single-person image with the complete head and shoulders visible.
  • Use PNG if transparent background pixels are required; JPEG does not support transparency.
  • Fine hair, motion blur, transparent objects, and backgrounds similar to the subject may reduce edge quality.
  • Do not automatically retry a timed-out request until your application has determined whether a result was created.