How the Worker works

The request path, Cloudflare bindings, and image data handling.

Your backend
  | POST image
  v
nobg Worker (Hono)
  | IP quotas, validation, monthly budget
  v
Cloudflare Images binding
  | segment: foreground
  v
Transparent PNG or WebP returned to your backend

Request lifecycle

  1. Assign a request ID and disable response caching.
  2. Validate Cloudflare’s client IP and reserve a request in its minute counter.
  3. Read the upload with a bounded body size and parse multipart fields.
  4. Validate the image signature, declared format, file size, and pixel count.
  5. Reserve the IP’s daily allowance, then a slot in the shared monthly budget.
  6. Send the bytes through the Images binding using segment: "foreground".
  7. Return the binary image with a download filename.

The service uses the Cloudflare Images binding to process uploaded bytes without a public image URL. Background removal uses foreground segmentation.

Data handling

nobg does not save uploads or outputs to R2, D1, KV, or Cloudflare Images storage. It buffers a bounded upload for validation and returns the processed stream with Cache-Control: no-store. Cloudflare processes the bytes under its service policies.

Unexpected application errors log an event name and request ID. These logs do not include image bytes, filenames, raw IPs, or provider error messages. Cloudflare may record platform request metadata through observability.

Quota records contain counts and expiry times. Object names use hashed IPs. Alarms remove expired records, and stored counters survive Worker restarts and deployments. See quota settings.

Deployment contents

apps/api/src/index.ts contains the handler. apps/api/wrangler.jsonc declares its Images and Durable Object bindings. packages/contracts supplies formats, limits, and error types used by the handler and OpenAPI document.

This is a single Worker deployment. There is no dependency on the documentation website at runtime.