TutorialUpdated 2026

How to Integrate a Background Removal API (Step by Step)

A practical, copy-paste tutorial for integrating a car background removal API into your app: getting an API key, authentication, your first call, parsing the response, downloading results, and production-grade error handling and retries.

13 min read

This guide is part of the AutoBackgrounding API documentation series. See live endpoints, rate limits, and per-image pricing from on the API pricing & docs page.

View API Pricing & Docs

This is the hands-on companion to our complete API guide. If you want to know exactly how to integrate a background removal API — from zero to a working, production-ready call — this walkthrough takes you through every step using the AutoBackgrounding API (from 5¢ per image).

Prerequisites

  • A server-side environment (Node.js, Python, PHP, or anything that can make HTTPS requests).
  • An AutoBackgrounding account and API key (covered in Step 1).
  • A publicly accessible vehicle image URL, or a local file to upload.

Step 1: Get Your API Key

Sign up and open your dashboard to generate an API key. Keys are secret credentials — store them in an environment variable, never in source control or client-side code. Grab your key from the API pricing & docs page.

bash
"tok-comment"># Store your key as an environment variable
AUTOBG_API_KEY=sk_live_your_key_here

Step 2: Authenticate

Every request includes an Authorization header with your key as a bearer token. That's the entire auth model — no OAuth dance, no signing.

http
Authorization: Bearer sk_live_your_key_here
Content-Type: application/json

Step 3: Make Your First Call

Send a single vehicle image to POST /v1/process. Here it is in three languages — pick yours:

curl https:"tok-comment">//api.autobackgrounding.com/v1/process \
  -H "Authorization: Bearer $AUTOBG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "image_url": "https:">//example.com/lot-photo.jpg",
    "background": "studio_white"
  }'

Step 4: Handle the Response

The API responds with JSON. A successful result looks like this:

json
{
  "id": "job_8f2a1c",
  "status": "completed",
  "output_url": "https:">//cdn.autobackgrounding.com/out/8f2a1c.png",
  "credits_used": 1
}

Read status first. If it's completed, use output_url. If it's failed, inspect the error and note that failed jobs consume zero credits.

Step 5: Download & Store the Output

Don't hotlink the returned URL in production — download the processed image and store it in your own bucket (S3, Vercel Blob, GCS, etc.), then reference your copy.

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

const img = await fetch(data.output_url);
const buffer = Buffer.from(await img.arrayBuffer());
await writeFile("./processed/8f2a1c.png", buffer);
"tok-comment">// Or upload the buffer to S3 / Vercel Blob here

Step 6: Error Handling & Retries

Production integrations must handle transient failures. Retry 5xx and 429 (rate limited) responses with exponential backoff; treat other 4xx codes as permanent. Use your own reference ID so retries stay idempotent.

async function processWithRetry(payload, attempts = 4) {
  for (let i = 0; i < attempts; i++) {
    const res = await fetch("https:">//api.autobackgrounding.com/v1/process", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.AUTOBG_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(payload),
    });

    if (res.ok) return res.json();

    "tok-comment">// Retry only on rate limit or server errors
    if (res.status === 429 || res.status >= 500) {
      const wait = 2 ** i * 500; "tok-comment">// 500ms, 1s, 2s, 4s
      await new Promise((r) => setTimeout(r, wait));
      continue;
    }

    "tok-comment">// Permanent error
    throw new Error(`API error ${res.status}: ${await res.text()}`);
  }
  throw new Error("Exhausted retries");
}

Next Steps

You now have a working, resilient single-image integration. From here:

Get your API key and the full endpoint reference on the API pricing & docs page — pricing starts at 5¢ per image.

Frequently Asked Questions

How do I authenticate with a background removal API?

AutoBackgrounding uses bearer token authentication. You include an Authorization header with the value 'Bearer YOUR_API_KEY' on every request. Keep the key server-side and never expose it in client-side code.

What's the minimum code to remove a car's background via API?

A single POST request to /v1/process with your API key and an image_url is enough. The API returns a JSON object containing output_url, which points to the processed image. Full examples in cURL, Node.js, and Python are included in this guide.

How should I handle API errors and rate limits?

Check the HTTP status code: retry 5xx and 429 responses with exponential backoff, and treat 4xx (except 429) as permanent errors to log and surface. Use your own reference ID to keep retries idempotent so you never double-charge for the same image.

Should I call the API from the browser or my server?

Always call it from your server. This keeps your API key secret, lets you handle retries and storage reliably, and avoids exposing usage to end users.

Start Building With the Car Background Removal API

Automotive-trained background removal from just 5¢ per image. Get an API key and process your first vehicle photo in minutes.

Continue the Series