Deploy the API Worker

Configure and deploy nobg with IP quotas, then check your endpoint.

Run the commands below from the repository root. They deploy the API Worker in apps/api.

1. Prepare your account and checkout

You need Node.js 22.14 or newer, pnpm 11, Git, and access to the repository, which is currently private. Use the pnpm version pinned in the root package.json.

git clone https://github.com/akshitkrnagpal/nobg.git
cd nobg
pnpm install --frozen-lockfile

Your Cloudflare account needs Workers access and the Images access required for background removal. Review requirements and costs. Installing dependencies and running local checks do not call the paid Images service.

Log in and confirm the account you will deploy into:

pnpm --filter @nobg/api exec wrangler login
pnpm --filter @nobg/api exec wrangler whoami

2. Configure the Worker

Open apps/api/wrangler.jsonc and review these settings:

SettingWhat to do
nameKeep nobg-api or choose a name that does not conflict with another Worker in your account.
routesRemove the supplied api.nobg.akshit.io route to use your workers.dev URL, or replace it with a hostname in your own Cloudflare zone.
images.bindingKeep IMAGES, the binding name used by the handler.
durable_objects and migrationsKeep the supplied QUOTAS binding and SQLite class migration.
vars.ALLOWED_ORIGINSSet your frontend origin if you want a browser demo, or use an empty string for server-only use.
Quota variablesDefaults are 5 requests/minute and 20 image attempts/day per IP, plus 10,000 image attempts/month across the service.
vars.MAX_UPLOAD_BYTESKeep 10485760 for a 10 MiB file limit, or adjust it within the supported range.

Keep main, compatibility_flags, and both binding names as supplied. If Wrangler can access multiple accounts, add your intended account_id to this file. See Worker configuration for the full settings.

3. Check and deploy

pnpm --filter @nobg/api typecheck
pnpm --filter @nobg/api test
pnpm --filter @nobg/api build
pnpm --filter @nobg/api run deploy

The build command bundles the API with Wrangler’s --dry-run option. The deploy command publishes it. Tests use mocked Images responses.

Wrangler prints a URL such as https://nobg-api.YOUR-SUBDOMAIN.workers.dev. Save that URL. The upload endpoint is public and requires no API key.

Use the filtered deploy command above. The repository’s root pnpm run deploy command publishes the documentation website.

4. Check the endpoint without processing an image

Set NOBG_URL to the URL Wrangler printed, with no trailing slash:

export NOBG_URL="https://nobg-api.YOUR-SUBDOMAIN.workers.dev"
curl --fail-with-body "$NOBG_URL/api/health"

Expect:

{ "status": "ok", "service": "nobg", "version": "0.1.0" }

This confirms the Worker responds. It does not verify quota storage, the Images binding, or paid-service access.

To check the upload route without processing an image:

curl --include --request POST "$NOBG_URL/api/v1/remove-background"

Expect 400 invalid_request because the body is missing. This checks the IP minute counter without calling Images. It uses one request from the minute allowance.

5. Process an image when you are ready

This step calls Cloudflare Images and may incur charges. You can stop after the checks above until your account has the required access.

With photo.jpg in your working directory:

curl --fail-with-body \
  "$NOBG_URL/api/v1/remove-background" \
  -F "image=@photo.jpg" \
  --output nobg.png

A successful response contains PNG bytes. On failure, the saved body is JSON describing the error. Inspect it before treating the file as an image. Add -F "format=webp" and use a .webp output filename for WebP.

See code examples to integrate your backend, configuration to add a domain, or operations to maintain the Worker.