# Background Remover API — Batch, Transparent PNG, Pay per Image (`sherwood/background-remover-batch`) Actor

Remove the background from one or many image URLs and get, for each image, a dataset item with the transparent PNG or WebP cutout URL, width and height. AI background removal in batch, optional mask, no API key, pay per image.

- **URL**: https://apify.com/sherwood/background-remover-batch.md
- **Developed by:** [Sherwood](https://apify.com/sherwood) (community)
- **Categories:** AI, Automation, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 background removeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Background Remover API — batch, transparent PNG, pay per image

Give it one image URL or a thousand, or the dataset of another Actor, and get every image with its background removed as a transparent PNG (or WebP), one dataset item per image: the cutout URL, its width and height, optionally the mask, or a clear error. Uses the BiRefNet v2 segmentation model with foreground refinement. No API key, no GPU, no subscription. **$0.005 per image** delivered, failures are free.

Built for automation and AI agents: send a list in `imageUrls`, or a single URL (or a comma-separated string) in `imageUrl`; every alias (`imageUrls`, `imageUrl`, `urls`, `images`, `startUrls`) is merged, nothing is required, and the default input runs on its own so you can see the output shape before sending your own files.

Pairs with [Image Upscaler API](https://apify.com/sherwood/image-upscaler-batch) for a complete product-photo pipeline: cut out, then enlarge. The upscaler reads this Actor's dataset directly (`datasetId`) and keeps the transparency in PNG and WebP.

### What you get

One item per image, in your dataset:

```json
{
  "index": 0,
  "inputUrl": "https://example.com/product.jpg",
  "outputUrl": "https://api.apify.com/v2/key-value-stores/abc123/records/cutout-0000.png",
  "maskUrl": null,
  "width": 1024,
  "height": 1024,
  "mode": "general",
  "format": "png",
  "model": "fal-ai/birefnet/v2",
  "durationMs": 3800,
  "status": "ok",
  "error": null
}
```

A failed image (unreachable URL, not an image, over 25 MB) comes back with `"status": "error"` and the reason in `error`. It is never charged.

### Use cases

- Cut out product photos for marketplaces, catalogs and ads, in bulk.
- Prepare portraits and avatars with clean hair edges (`mode: "portrait"`).
- Produce masks for compositing or further editing (`includeMask: true`).
- Clean up images pulled from a scraper before they reach a design pipeline.
- Give an AI agent or an n8n / Make / Zapier flow a single call that handles a whole list.

### Input

| Field | Type | Default | Notes |
|---|---|---|---|
| `imageUrls` | array | two sample images | Public JPG, PNG or WebP URLs. For a single URL or a comma-separated string, use `imageUrl`. |
| `imageUrl`, `urls`, `images`, `startUrls` | aliases | — | Merged with `imageUrls`, duplicates removed. `startUrls` accepts `{"url": "..."}` objects. |
| `datasetId` | string | — | Read the image URLs from an Apify dataset instead (see below). |
| `urlField` | string | auto | Field holding the image URL in each dataset item: `images[].url`, `photo.thumbnails[0].url`... |
| `maxImagesPerItem` | integer | `1` | Image URLs taken from each dataset item. |
| `keepFields` | array | — | Fields copied from each dataset item into its result, under `source` (SKU, ASIN, listing URL). |
| `mode` | `general`, `portrait`, `matting`, `heavy` | `general` | portrait for people, matting for hair/fur/glass edges, heavy for complex scenes (slower). |
| `outputFormat` | `png`, `webp` | `png` | Both keep transparency. |
| `includeMask` | boolean | `false` | Adds `maskUrl` (black-and-white PNG) to each item. |
| `highResolution` | boolean | `false` | Process at 2048×2048 instead of 1024×1024; finer edges on large images, about twice as slow. |
| `maxImages` | integer | `100` | Stop after this many images. |

Minimal call:

```json
{ "imageUrls": ["https://example.com/a.jpg", "https://example.com/b.png"] }
```

### Chain it after another Actor

Give `datasetId` (a dataset ID or name) and the Actor reads the image URLs from its items: the output of a product scraper or of [AI Image Generator](https://apify.com/sherwood/image-generator-batch). The image field is detected automatically (`outputUrl`, `highResolutionImages`, `imageUrls`, `images`, `displayUrl`, `thumbnailImage`...), or set it with `urlField`.

```json
{
  "datasetId": "YOUR_DATASET_ID",
  "urlField": "images[].url",
  "keepFields": ["sku", "url"]
}
```

To run it automatically after another Actor, add it on that Actor's **Integrations** tab with the input `{ "datasetId": "{{resource.defaultDatasetId}}" }`; the platform fills in the dataset of each finished run. Each result carries `sourceItemIndex`, the position of the item it came from, and the fields listed in `keepFields`.

### Pricing

- **Background removed** — $0.005 per image delivered, mask included when requested.
- Failed, unreachable or non-image URLs: free.

Set a maximum cost per run in Apify and the Actor stops cleanly when it is reached; remaining images are reported, not processed.

### Via API, n8n, Make or MCP

Call it like any Apify Actor: `POST https://api.apify.com/v2/actors/sherwood~background-remover-batch/run-sync-get-dataset-items` with the JSON input above, or add it as a tool through the Apify MCP server. Results are plain dataset items, so `get-dataset-items` returns the URLs directly.

### Limits

- Input images up to 25 MB each, served over public http(s) URLs.
- Output files live in the run's key-value store and follow your account's data retention.
- Processing time is typically 2 to 6 seconds per image; 4 images are processed in parallel.

# Actor input Schema

## `imageUrls` (type: `array`):

Public URLs of the images to process (JPG, PNG, WebP), as a list. One dataset item is returned per URL, with an index matching the input order. For a single URL, or several URLs in one comma- or newline-separated string, use imageUrl instead. Aliases merged into this list: imageUrl, urls, images, startUrls.

## `datasetId` (type: `string`):

Read the image URLs from an Apify dataset: the output of a scraper or of sherwood/image-generator-batch. When this Actor runs as an integration after another Actor, leave it empty: the dataset of the run that triggered it is used. The sample imageUrls are ignored when a dataset is given.

## `urlField` (type: `string`):

Field of each dataset item that holds the image URL. Dots for nested fields, \[] for every element of a list, \[0] for the first one: outputUrl, highResolutionImages, images\[].url, photo.thumbnails\[0].url. Several fields separated by commas are tried in order. Empty: detected automatically (outputUrl, highResolutionImages, imageUrls, images, imageUrl, image, photos, displayUrl, mainImage, thumbnailImage...).

## `maxImagesPerItem` (type: `integer`):

How many image URLs to take from each dataset item, in order. Default 1: the first one, usually the main image.

## `keepFields` (type: `array`):

Fields copied from each dataset item into its result, under source: asin, sku, url, title... Same path syntax as urlField.

## `imageUrl` (type: `string`):

A single image URL, or several URLs in one comma- or newline-separated string (they are split). Merged with imageUrls.

## `urls` (type: `array`):

Alias of imageUrls.

## `images` (type: `array`):

Alias of imageUrls.

## `startUrls` (type: `array`):

Alias of imageUrls. Accepts plain strings or {"url": "..."} objects.

## `mode` (type: `string`):

general works for products, objects and most photos. portrait is tuned for people (hair, skin edges). matting keeps semi-transparent edges (hair, glass, fur). heavy is slower and more accurate for complex scenes.

## `outputFormat` (type: `string`):

png keeps full transparency and is the safest choice. webp is smaller and also keeps transparency.

## `includeMask` (type: `boolean`):

When true, each item also carries maskUrl: a black-and-white PNG of the segmentation mask, useful for compositing.

## `highResolution` (type: `boolean`):

Process at 2048×2048 instead of 1024×1024. More accurate edges on large images, about twice as slow.

## `maxImages` (type: `integer`):

Stop after this many images. Protects against oversized lists. Default 100.

## Actor input object example

```json
{
  "imageUrls": [
    "https://storage.googleapis.com/falserverless/example_inputs/birefnet-input.jpeg",
    "https://storage.googleapis.com/falserverless/example_inputs/dog.png"
  ],
  "maxImagesPerItem": 1,
  "mode": "general",
  "outputFormat": "png",
  "includeMask": false,
  "highResolution": false,
  "maxImages": 100
}
```

# Actor output Schema

## `results` (type: `string`):

One item per input image: inputUrl, outputUrl (transparent PNG or WebP), maskUrl when requested, width, height, status and error. Sort by index to match the input order.

## `files` (type: `string`):

The cutout and mask files referenced by outputUrl and maskUrl.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "imageUrls": [
        "https://storage.googleapis.com/falserverless/example_inputs/birefnet-input.jpeg",
        "https://storage.googleapis.com/falserverless/example_inputs/dog.png"
    ],
    "mode": "general",
    "outputFormat": "png",
    "includeMask": false,
    "highResolution": false,
    "maxImages": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("sherwood/background-remover-batch").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "imageUrls": [
        "https://storage.googleapis.com/falserverless/example_inputs/birefnet-input.jpeg",
        "https://storage.googleapis.com/falserverless/example_inputs/dog.png",
    ],
    "mode": "general",
    "outputFormat": "png",
    "includeMask": False,
    "highResolution": False,
    "maxImages": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("sherwood/background-remover-batch").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "imageUrls": [
    "https://storage.googleapis.com/falserverless/example_inputs/birefnet-input.jpeg",
    "https://storage.googleapis.com/falserverless/example_inputs/dog.png"
  ],
  "mode": "general",
  "outputFormat": "png",
  "includeMask": false,
  "highResolution": false,
  "maxImages": 100
}' |
apify call sherwood/background-remover-batch --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,sherwood/background-remover-batch"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/RHJZM1FK6gqsTjWEg/builds/0tGuSeMEwXUmmB5Uv/openapi.json
