Node.js + PixelPanda API

Remove Background with Node.js

Remove image backgrounds from your Node.js backend. Complete examples for Express, Next.js, and serverless functions.

$ npm install form-data

Node.js examples — copy and go

Each example is self-contained. Copy the one that matches your use case.

Quick start

Basic background removal from a Node.js script.

const fs = require("fs");
const FormData = require("form-data");

const API_KEY = "pk_live_your_api_key";

async function removeBackground(imagePath) {
    const form = new FormData();
    form.append("file", fs.createReadStream(imagePath));

    const response = await fetch(
        "https://pixelpanda.ai/api/v1/remove-background",
        {
            method: "POST",
            headers: {
                "Authorization": `Bearer ${API_KEY}`,
                ...form.getHeaders()
            },
            body: form
        }
    );

    return await response.json();
}

const result = await removeBackground("product.jpg");
console.log(result.image_url);  // Transparent PNG URL

Express middleware

Add background removal to your Express API.

const express = require("express");
const multer = require("multer");
const FormData = require("form-data");

const app = express();
const upload = multer({ limits: { fileSize: 10 * 1024 * 1024 } });

app.post("/api/remove-bg", upload.single("image"), async (req, res) => {
    if (!req.file) return res.status(400).json({ error: "No image" });

    const form = new FormData();
    form.append("file", req.file.buffer, {
        filename: req.file.originalname,
        contentType: req.file.mimetype
    });

    try {
        const response = await fetch(
            "https://pixelpanda.ai/api/v1/remove-background",
            {
                method: "POST",
                headers: {
                    "Authorization": `Bearer ${process.env.PIXELPANDA_API_KEY}`,
                    ...form.getHeaders()
                },
                body: form
            }
        );

        const data = await response.json();
        res.json(data);
    } catch (err) {
        res.status(500).json({ error: err.message });
    }
});

app.listen(3000);

Response format

Every successful request returns this JSON. The image_url is a permanent link to the transparent PNG.

{
    "success": true,
    "image_url": "https://pub-xxx.r2.dev/results/abc123.png",
    "credits_remaining": 199
}
FieldTypeDescription
successbooleantrue if background was removed successfully
image_urlstringURL to the transparent PNG result (permanent, hosted on CDN)
credits_remainingintegerHow many credits are left on your account

Error codes

CodeMeaning
200Success — image_url contains the transparent PNG
401Unauthorized — invalid or missing API key
402Payment required — out of credits
429Rate limited — too many requests

Common issues

form.getHeaders is not a function
Make sure you're using the form-data npm package, not the browser's built-in FormData. Install it: npm install form-data.
fetch is not defined
Node.js 18+ has built-in fetch. For older versions, install node-fetch: npm install node-fetch.

Common questions

Yes. See the JavaScript page for a Next.js API route example. Works with both Pages Router and App Router.
Yes. The API is a stateless HTTP POST — perfect for AWS Lambda, Vercel Functions, or Cloudflare Workers.
Node.js 18+ has built-in fetch(). For older versions, npm install node-fetch.
1 credit per image (~$0.029). Start with the $10 Impulse pack (50 credits, one-time, no subscription) or subscribe at $7.99/week for 280 credits/week (cancel anytime).

Start removing backgrounds with Node.js

280 credits/week for $7.99. Copy the code above and go.

Get Your API Key