Guide

Remove image backgrounds and write alt text with AI

Cut out a product photo and have alt text written for uploads, from your server. Both need the AI add-on.

Images guide · in this guide

  • What you need
  • Remove a background
  • Write alt text for uploads

Published

What you need

Both of these need the AI add-on, which spends AI credits. Without it the calls answer 402 ai_addon_required. Check the add-on page for what each costs.

Both calls need your private key, so make them from your server. OpenAI's models do the work.

Remove a background

removeBackground makes a new file with a transparent background and leaves the original alone. It answers at once with the edit queued, and waitForImageEdit polls until it is done. The result is a new file with its own ID.

cutout.ts
import { Fileboy } from "@cd2/fileboy-node"

const fileboy = Fileboy({
  publicKey: process.env.FILEBOY_PUBLIC_KEY!,
  privateKey: process.env.FILEBOY_PRIVATE_KEY!,
})

export async function cutOut(fileId: string) {
  const queued = await fileboy.removeBackground(fileId, {
    format: "webp", // or "png"; both keep transparency
    prompt: "the product and its shadow", // optional hint of what to keep
  })
  const edit = await fileboy.waitForImageEdit(queued.id)
  if (edit.status !== "completed") {
    throw new Error(`The edit failed: ${edit.error ?? "unknown"}`)
  }
  return edit.resultFileId! // store this ID; show it like any image
}

It is a regeneration by an AI model, not a pixel-exact cut-out: faces, text and fine detail can change. Look at the result before you use it for a product listing. A failed edit costs no credits.

To avoid polling, listen for the file.edit_completed and file.edit_failed webhooks instead.

Write alt text for uploads

Turn on AI image data for the app, with the alt text switch, in the dashboard (or aiImageDescriptions in the app settings). From then on every image you upload is described in a sentence or two. It is off until you turn it on, and the same call can also read text, add tags and moderate images.

The description is the file's public altText, so your server can read it when it builds a page. Build the image URL with public: true: on a client made with the private key, the Node library otherwise adds a short-lived private-key token to it, which would then sit in your page:

product.ts
const file = await fileboy.fetchFileData(photoId)
const alt = file.altText ?? "" // null until the description is made, a few seconds after upload

const src = fileboy.buildImageUrl(photoId, {
  public: true, // a client with the private key would add a short-lived token to the URL
  transforms: [{ type: "resize", width: 800 }, { type: "format", format: "webp" }],
})
// <img src={src} alt={alt} />

The description is made in the background after the upload. To analyse an image uploaded before you turned it on, or to correct a description (your edit is kept when the image is analysed again):

await fileboy.analyzeFile(photoId)

const analysis = await fileboy.getFileAnalysis(photoId) // private key
analysis.status // "pending", "processing" or "done"
analysis.description // "A green shop sign reading OPEN above a glass door."

await fileboy.updateFileAnalysis(photoId, { description: "Our shop on Market Street" })

The description comes from whatever is in the image, so escape it in a page as you would any user input, and read it before relying on it for accessibility: a model can get a picture wrong.

Checked against the current libraries in November 2026. Found something that no longer works? Tell us.

Still choosing a tool?

Fileboy is small on purpose. This comparison says where it fits and where another option is the better call.

Get a key and run this code

Create a free app, copy your keys into the example and run it. The free plan needs no card.