Documentation

Guides and API reference for uploads, image transforms and video.

npm install @cd2/fileboy-react
API https://api.fileboy.io

AI image edits

Remove an image's background, or upscale it, with an OpenAI image model. Each edit makes a new file beside the original, which is never changed. Paid plans only.

Needs the AI add-on (£9/month with 375 AI credits, then 2.5p a credit). Without it, starting this answers 402 ai_addon_required and automatic runs are skipped; anything already made stays. Cost in AI credits: ai background removal: 2 credits, plus 1, 6 or 22 a megapixel of output at low, medium or high quality (8 credits for a 1024×1024 image at medium quality); ai upscaling: 2 credits, plus 1, 6 or 22 a megapixel of output at low, medium or high quality (26 credits for a 2048×2048 image at medium quality). See the AI add-on.

What it really does

Both edits are made by OpenAI's GPT Image model gpt-image-2.5-sunburst, through its image edits endpoint. The model doesn't cut out or enlarge your pixels: it looks at the image and draws a new one. That is what makes it good at hair, glass and soft edges, and it also means:

  • It isn't pixel-exact. A background removal isn't a precise matte of the original, and an upscale isn't super-resolution of it. Faces, hands, text, logos, patterns and fine detail can come out changed. Check the result before you use it for anything that must match the original, like a product's label.
  • It works at the model's sizes. Both sides are multiples of 16, the total is between about 0.66 and 3.7 megapixels (2560 × 1440), and the shape is between 1:3 and 3:1. Fileboy picks the nearest of those sizes to your image's shape and tells you what it chose (width, height, and aspectAdjusted when your image was wider or taller than 3:1).
  • It isn't a URL transform. An edit takes from about ten seconds to a minute or two and costs money, so it is never made by someone loading a URL. You ask for it from your server (or the dashboard), and get the new file when it is done. Resize, crop and convert the new file with image transforms like any other.
  • The model can refuse an image or prompt it judges unsafe (see errors below).

Remove a background

POST /files/{id}/remove-background asks for the main subject on a transparent background. The new image keeps your image's shape at its own size, up to a long edge of 1536 px. Every field is optional:

  • format: png (the default) or webp, the two that keep transparency.
  • quality: low, medium (the default) or high.
  • prompt: a hint of what to keep, up to 500 characters, like "the product and its shadow" or "both people".

Upscale

POST /files/{id}/upscale asks for the same image at a higher resolution. Fields, all optional:

  • longEdge: 1536, 2048 (the default) or 2560. The result keeps your image's shape, within 3.7 megapixels: a 3:2 image at 2560 comes out at 2336 × 1568, a square one at 1920 × 1920. An image that would come out no larger is refused with 422 already_large_enough.
  • quality: low, medium (the default) or high.
  • format: png (the default), webp or jpeg.

Asking for an edit

The edit routes need your app's private key, or a scoped key with the images:edit scope: public keys and upload tokens are refused. Reading edits back (GET /image-edits/{id} and GET /files/{id}/edits) needs files:read. In the dashboard, an image's page has both edits, with what each will cost.

1
2
3
4
5
6
7
8
9
10
11
# Remove the background (the answer is 202, with the edit)
curl -X POST https://api.fileboy.io/files/FILE_ID/remove-background -H "Authorization: token SIGNED_TOKEN" -H "Content-Type: application/json" -d '{ "quality": "medium", "format": "png", "prompt": "the product and its shadow" }'

# Upscale to a long edge of 2048 px
curl -X POST https://api.fileboy.io/files/FILE_ID/upscale -H "Authorization: token SIGNED_TOKEN" -H "Content-Type: application/json" -d '{ "longEdge": 2048, "quality": "high" }'

# Read an edit, until its status is completed or failed
curl https://api.fileboy.io/image-edits/EDIT_ID -H "Authorization: token SIGNED_TOKEN"

# A file's edits, and the edit that made it
curl https://api.fileboy.io/files/FILE_ID/edits -H "Authorization: token SIGNED_TOKEN"

The answer is 202 with the edit. Its status goes from queued to processing to completed (with resultFileId, the new file) or failed (with error and message).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  "data": {
    "id": "8d1b5c3e-2f4a-4b6c-9d8e-7f6a5b4c3d2e",
    "operation": "remove-background",
    "status": "completed",
    "sourceFileId": "2a860257-ecf9-424a-846e-00ab68e2fd58",
    "resultFileId": "5c0e9a14-8b7d-4f62-a3e1-9d8c7b6a5f40",
    "format": "png",
    "quality": "medium",
    "prompt": "the product and its shadow",
    "longEdge": null,
    "width": 1536,
    "height": 1024,
    "sourceWidth": 3000,
    "sourceHeight": 2000,
    "aspectAdjusted": false,
    "credits": 11,
    "model": "gpt-image-2.5-sunburst",
    "error": null,
    "message": null,
    "attempts": 1,
    "createdAt": "2026-11-23T10:00:00Z",
    "startedAt": "2026-11-23T10:00:01Z",
    "finishedAt": "2026-11-23T10:00:34Z"
  }
}

With the Node SDK (Ruby, Python and PHP have the same methods):

1
2
3
4
5
6
7
8
9
10
11
12
import { Fileboy } from "@cd2/fileboy-node"

const fileboy = Fileboy({ publicKey, privateKey })

const edit = await fileboy.removeBackground(fileId, { quality: "medium" })
// Poll until it is done (or listen for file.edit_completed)
const done = await fileboy.waitForImageEdit(edit.id)
if (done.status === "completed") {
  console.log("New file:", done.resultFileId, done.width, done.height)
} else {
  console.log("Failed:", done.error, done.message)
}

What can be edited

  • JPEG, PNG, WebP, BMP, TIFF and HEIC images up to 50 MB, within the size the image service decodes. BMP, TIFF and HEIC are converted to PNG first. Others answer 415 unsupported_image.
  • The image is turned upright and, when it is larger, shrunk to a long edge of 2048 px before it is sent. Its name and metadata are never sent.
  • A file the virus scan found infected is refused (409 file_infected), and so is one held back until it is scanned (file_scan_pending, file_scan_failed). So is an image AI moderation flagged (409 file_flagged). These are checked again just before the image is sent.
  • The new file counts towards your plan's file limit, so an app at its limit is refused (403 limit_reached).

The new file

The new file is stored in the same app and folder as the original, as readable as it (a file that needs a signed URL stays so), and named after it, like shoe (background removed).png or shoe (upscaled 2048x1360).png. Its metadata links it to the original: derivedFrom (the original's id), operation and imageEditId. The original is never changed or replaced. Its page in the dashboard says what it was made from.

Cost in AI credits

Each edit spends AI credits, worked out from its quality and the size it makes: 2 credits, plus 1 (low), 6 (medium) or 22 (high) per megapixel of output, rounded up. For example:

  • 1024 × 1024: 3 credits at low, 8 at medium, 24 at high.
  • 1536 × 1024: 4 at low, 11 at medium, 35 at high.
  • 2560 × 1440: 6 at low, 24 at medium, 80 at high.

A credit stands for about US$0.01 of what OpenAI charges us. OpenAI doesn't publish a per-image price for this model, so the rates come from its published prices for the model before it, rounded up: an estimate, not an exact pass-through. The edit's credits says what it cost, and the dashboard shows the cost before you ask.

  • Credits are counted when you ask for the edit. A failed edit gives them back: you pay for none.
  • Pro: 200 credits an hour and 1,000 a month for each of background removal and upscaling. Max: 1,000 an hour and 5,000 a month for each. The Free plan doesn't include AI image edits (403 plan_limit).
  • An edit that would take you past a limit is refused with 429 rate_limited, saying how many credits are left; a cheaper quality may still fit. The hourly limit resets at the top of each UTC hour, the monthly cap on the 1st.
  • See what you have used on the app's Usage page (AI usage and limits), or with GET /usage/ai, where backgroundRemoval and upscale have "unit": "credits".

Webhooks

When an edit is done, Fileboy sends file.uploaded for the new file and then file.edit_completed, about the new file, with the edit. When one fails for good it sends file.edit_failed, about the original, with the edit's error and message. Both are file events, so file filters apply to them, and they can be replayed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
  "id": "0f4e2c1a-9b3d-4a57-8c61-2d7e9f0b1a23",
  "type": "file.edit_completed",
  "created": "2026-11-23T10:00:34Z",
  "appId": "APP_ID",
  "resource": {
    "id": "5c0e9a14-8b7d-4f62-a3e1-9d8c7b6a5f40",
    "name": "shoe (background removed).png",
    "originalFilename": "shoe (background removed).png",
    "mime": "image/png",
    "fileSize": 812345,
    "metadata": {
      "derivedFrom": "2a860257-ecf9-424a-846e-00ab68e2fd58",
      "operation": "remove-background",
      "imageEditId": "8d1b5c3e-2f4a-4b6c-9d8e-7f6a5b4c3d2e"
    },
    "createdAt": "2026-11-23T10:00:34Z",
    "edit": {
      "id": "8d1b5c3e-2f4a-4b6c-9d8e-7f6a5b4c3d2e",
      "operation": "remove-background",
      "status": "completed",
      "sourceFileId": "2a860257-ecf9-424a-846e-00ab68e2fd58",
      "resultFileId": "5c0e9a14-8b7d-4f62-a3e1-9d8c7b6a5f40",
      "width": 1536,
      "height": 1024,
      "format": "png",
      "quality": "medium",
      "credits": 11,
      "model": "gpt-image-2.5-sunburst"
    }
  }
}

Errors

When you ask for an edit:

  • 403 plan_limit: your plan doesn't include AI image edits. 429 rate_limited: not enough credits left this hour or month.
  • 400 invalid_format, invalid_quality, invalid_prompt or invalid_longEdge: an option isn't one listed above.
  • 409 ai_not_configured: the Fileboy server has no OpenAI key (self-hosted).
1
2
3
4
5
HTTP/1.1 403 Forbidden
{ "error": "plan_limit", "message": "AI image editing isn't part of this app's plan. Upgrade to use it" }

HTTP/1.1 429 Too Many Requests
{ "error": "rate_limited", "message": "This edit costs 24 AI credits, and this app has 10 of its 200 for this hour left. Try again after 15:00 UTC, or at a lower quality" }

An edit that fails has one of these error codes. OpenAI being busy (rate limited), its server errors and timeouts are tried again, up to 4 times over about half an hour (openai_busy or openai_error while it waits). These are final:

  • moderation_blocked: OpenAI's safety system refused the image or the prompt. It isn't tried again: the same image would be refused again.
  • openai_quota or openai_refused: a problem with the server's OpenAI account that its operator has to fix.
  • openai_error: OpenAI refused the request, or kept failing.
  • file_infected, file_scan_failed, file_flagged, source_deleted, unreadable_image, image_too_large and limit_reached: something changed about the file or the app while the edit waited.
  • result_limit_reached: the app reached its file limit while the model made the image, so it couldn't be stored. The image was made and paid for, so unlike the others this one keeps its credits.
Fileboy uses OpenAI as the processor for AI image edits: the image (never its name or metadata) and the prompt are sent to OpenAI's API, whose terms say what it keeps and for how long. Don't edit images you can't share with a processor.

Related guides