Dev.to WebDev 🛠 Dev 👁 0 📖 5 min read

Switching from the remove.bg API before Dec 1

remove.bg's standalone website and self-service API close on December 1, 2026 at 9:00 CET, according to their FAQ. Background removal moves into Canva, the self-service API moves to Leonardo.Ai, unused pay-as-you-go cred

remove.bg's standalone website and self-service API close on December 1, 2026 at
9:00 CET, according to their FAQ. Background removal moves into Canva, the
self-service API moves to Leonardo.Ai, unused pay-as-you-go credits expire that day,
and enterprise API contracts continue. If you have a script, a Shopify job or a
Zapier step calling api.remove.bg, it needs a new home this week.

You have a few options: move to Leonardo.Ai (the official successor), pick another
background-removal API, or run an open-source model yourself. This post covers one
option that needs almost no code change. Disclosure: I build it.

AirGallery has an endpoint that accepts remove.bg's request format. The same path,
the same X-Api-Key header, the same image_file / image_url / image_file_b64
parameters, and the same response and error shapes. Below is the diff, the
differences that matter, and what it costs.

The diff

- POST https://api.remove.bg/v1.0/removebg
+ POST https://airgallery.com/v1.0/removebg

- X-Api-Key: <your remove.bg key>
+ X-Api-Key: ag_...   (an AirGallery API key with the "ai" scope)

That's it for most integrations. Keys start with ag_ and are shown once when you
create them.

curl

# Before
curl -H "X-Api-Key: $REMOVEBG_API_KEY" \
  -F "[email protected]" -F "size=auto" \
  -f https://api.remove.bg/v1.0/removebg -o no-bg.png

# After
curl -H "X-Api-Key: $AIRGALLERY_API_KEY" \
  -F "[email protected]" -F "size=auto" \
  -f https://airgallery.com/v1.0/removebg -o no-bg.png

image_url and image_file_b64 work too, as multipart, urlencoded or JSON bodies.

JavaScript (Node 18+)

import { readFile, writeFile } from "node:fs/promises";

const API_URL = "https://airgallery.com/v1.0/removebg"; // was https://api.remove.bg/v1.0/removebg
const API_KEY = process.env.AIRGALLERY_API_KEY;         // was REMOVEBG_API_KEY

async function removeBackground(path) {
  const form = new FormData();
  const bytes = await readFile(path);
  form.append("image_file", new Blob([bytes], { type: "image/jpeg" }), "photo.jpg");
  form.append("size", "auto");

  const res = await fetch(API_URL, {
    method: "POST",
    headers: { "X-Api-Key": API_KEY },
    body: form,
  });

  if (!res.ok) {
    const body = await res.json().catch(() => ({}));
    const err = body.errors?.[0] ?? {};
    const e = new Error(err.title ?? `HTTP ${res.status}`);
    e.status = res.status;
    e.code = err.code; // e.g. "insufficient_credits", "auth_failed"
    throw e;
  }

  console.log(
    "credits:", res.headers.get("X-Credits-Charged"),
    "size:", res.headers.get("X-Width"), "x", res.headers.get("X-Height"),
  );
  return Buffer.from(await res.arrayBuffer());
}

await writeFile("no-bg.png", await removeBackground("photo.jpg"));

Python

This is the requests example from remove.bg's docs with a new URL and key, plus a
retry on 429:

import os, time, requests

API_URL = "https://airgallery.com/v1.0/removebg"  # was https://api.remove.bg/v1.0/removebg
API_KEY = os.environ["AIRGALLERY_API_KEY"]        # was REMOVEBG_API_KEY

def remove_bg(path, retries=3):
    for _ in range(retries):
        with open(path, "rb") as f:
            res = requests.post(
                API_URL,
                files={"image_file": f},
                data={"size": "auto"},
                headers={"X-Api-Key": API_KEY},
                timeout=120,
            )
        if res.ok:
            return res.content
        if res.status_code == 429:
            time.sleep(int(res.headers.get("Retry-After", 10)))
            continue
        try:
            err = res.json()["errors"][0]
        except Exception:
            err = {}
        raise RuntimeError(f"{res.status_code} {err.get('code')}: {err.get('title')}")
    raise RuntimeError("still rate limited after retries")

with open("no-bg.png", "wb") as out:
    out.write(remove_bg("photo.jpg"))

Response format

By default you get the PNG bytes back, with X-Credits-Charged, X-Width and
X-Height headers. Send Accept: application/json and you get remove.bg's JSON
shape instead:

{
  "data": {
    "result_b64": "iVBORw0KGgo...",
    "foreground_top": 0,
    "foreground_left": 0,
    "foreground_width": 1024,
    "foreground_height": 768
  }
}

The foreground_* fields describe the whole output image, not a tight bounding box
around the subject. If your code crops with them, crop on the alpha channel instead.

Errors

Errors use remove.bg's shape, { "errors": [{ "title": "...", "code": "..." }] }:

Status code What to do
400 missing_source, invalid_parameters No image, or an unsupported option (see below)
401 / 403 auth_failed Missing or wrong key, or the key lacks the ai scope
402 insufficient_credits Top up; don't retry
413 file_too_large See the size limits below
422 unknown_foreground No clear subject found
429 rate_limit_exceeded Back off and retry
5xx server_error Retry once, then log it

Credits are refunded automatically when a call fails, so a 4xx or 5xx doesn't cost
anything.

What's different (read this before you switch)

  • Output size. Cutouts come back at up to 1024 px on the long side. If you rely on remove.bg's full-resolution output for print or zoomable product images, this isn't a drop-in for you.
  • How the cutout is made. It uses an image model rather than a classic segmentation matte. Run 20 or so of your own images through it first, especially ones with fine hair, printed text or logos, and compare.
  • Unsupported options. bg_image_url and JPG/ZIP output return a 400. format must be auto or png. size, type, crop and channels are accepted and ignored. bg_color works (a hex like 81d4fa or a color name).
  • Request size. airgallery.com accepts request bodies up to 4.5 MB. For bigger files (up to 25 MB), use the second URL listed in the docs, or send image_url.
  • Rate limit. 10 requests per minute per IP on this endpoint. Fine for a store that adds a few products a day, too slow for a one-off backfill of 50,000 images.
  • Latency. Each call is a model call. Set a generous client timeout.

Pricing

One credit per image. Credit packs are $5 for 50, $15 for 200 and $35 for 500, so
$0.07 to $0.10 per image depending on the pack. There's no subscription, credits
don't expire, and new accounts get 10 free credits, which is enough to test the diff
on real images.

I'm not going to quote remove.bg's or Leonardo.Ai's prices here because they vary by
plan and volume. Compare against your last invoice. If you process thousands of
images a month at full resolution, a volume plan elsewhere will probably suit you
better. If you process tens or hundreds and want the existing code to keep working,
this is the shortest path.

Migration checklist

  1. Create a key with the ai scope and put it in an env var.
  2. Change the URL and key.
  3. Run a sample of your real images and check edges and size.
  4. Handle 402 (out of credits) separately from other errors so a pipeline stops instead of retrying.
  5. Remove any bg_image_url or format=jpg usage.

The same key also works for the other tools (upscaling, restoration and so on) and
for image generation, but you don't need any of that to replace remove.bg.

Docs, including the large-upload URL: https://airgallery.com/api#removebg

Questions about edge cases are welcome in the comments.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.