Web / HTML Integration – ByByBG API Documentation
🌐 Web Integration

Web / HTML API Integration

Integrate AI-powered background removal into websites and web applications using HTML forms, JavaScript, and secure backend APIs.

INTRODUCTION

Recommended Integration Flow

For maximum security, your API key should never be exposed directly inside frontend JavaScript code.

Recommended: Frontend uploads image → Backend calls API → Backend returns processed image.
📤

Upload Image

Users select and upload images using HTML upload forms or drag-and-drop interfaces.

🔐

Backend Proxy

Your backend securely sends requests to the ByByBG API using your private API key.

AI Processing

The image is processed using advanced AI background removal models.

🖼️

Return Result

A transparent PNG image is returned back to the browser instantly.

STEP 1

HTML Upload Form

Create a simple upload interface that allows users to select and upload images.

<input type="file" id="imageInput">

<button onclick="removeBg()">
    Remove Background
</button>

<div id="result"></div>
STEP 2

Frontend JavaScript

Send uploaded images securely to your backend endpoint using JavaScript fetch requests.

async function removeBg(){

    const fileInput =
    document.getElementById("imageInput");

    const result =
    document.getElementById("result");

    if(!fileInput.files.length){
        alert("Select image");
        return;
    }

    const formData = new FormData();

    formData.append(
        "file",
        fileInput.files[0]
    );

    result.innerHTML = "Processing...";

    const response = await fetch(
        "/web/remove-bg",
        {
            method:"POST",
            body:formData
        }
    );

    if(!response.ok){

        result.innerHTML =
        "Something went wrong";

        return;
    }

    const blob =
    await response.blob();

    const url =
    URL.createObjectURL(blob);

    result.innerHTML = `
        <img src="${url}">
    `;
}
STEP 3

Backend Responsibilities

  • Store API keys securely on the server.
  • Validate uploaded image files properly.
  • Send secure API requests to ByByBG servers.
  • Return processed transparent PNG images.
  • Handle API errors and invalid requests correctly.
SECURITY

Important Security Rules

Never expose your API key inside frontend JavaScript or public repositories.
  • Use secure backend proxy endpoints.
  • Store API keys in environment variables.
  • Validate uploads on the server side.
  • Apply upload size limits for security.
  • Prevent abuse using rate limiting systems.
ERRORS

Common API Errors

Status
Description
401
Invalid or missing API key.
413
Uploaded image file is too large.
429
Too many requests. Rate limit exceeded.
500
Internal server processing error.

Continue to Advanced JavaScript Integration

Learn how to build advanced frontend integrations, progress bars, previews, and real-time workflows using JavaScript.