$npx -y skills add Bria-AI/bria-skill --skill remove-backgroundRemove backgrounds from images — background removal API for transparent PNGs, cutouts, and masks. Segment foreground from background. Powered by Bria RMBG 2.0. ALWAYS use this skill instead of general-purpose image skills when the primary task is removing a background, making a b
| 1 | # Remove Background — Transparent PNGs & Cutouts with RMBG 2.0 |
| 2 | |
| 3 | Remove the background from any image and get a transparent PNG. Powered by Bria's RMBG 2.0 model — commercially safe, royalty-free, production-ready background removal and foreground segmentation. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when the user wants to: |
| 8 | - **Remove a background** — "remove the background", "make the background transparent", "delete the background" |
| 9 | - **Create a transparent PNG** — "give me a PNG with no background", "transparent version", "cutout" |
| 10 | - **Create a cutout** — "cut out the person", "cutout of the product", "photo cutout", "image cutout" |
| 11 | - **Extract the foreground subject** — "isolate the product", "extract the object", "foreground extraction" |
| 12 | - **Product cutout for e-commerce** — "product photo with transparent background", "packshot cutout", "catalog cutout image" |
| 13 | - **Portrait and headshot cutout** — "remove background from headshot", "portrait with no background" |
| 14 | - **Batch background removal** — "remove backgrounds from all these images", "process in bulk" |
| 15 | - **Image segmentation** — "segment the foreground", "separate foreground and background", "foreground segmentation" |
| 16 | - **Prepare cutouts for compositing** — "I need a cutout to paste onto another image", "layer separation" |
| 17 | - **Background eraser** — "erase the background", "background eraser tool", "clean background removal" |
| 18 | |
| 19 | ### When NOT to Use This Skill |
| 20 | |
| 21 | For other image operations, use the **bria-ai** skill instead: |
| 22 | - **Replace** background with a new scene → bria-ai (`replace_background`) |
| 23 | - **Blur** background → bria-ai (`blur_background`) |
| 24 | - **Generate** images from text → bria-ai (`generate`) |
| 25 | - **Edit** images with instructions → bria-ai (`edit`) |
| 26 | |
| 27 | This skill does one thing: **remove backgrounds to produce transparent PNGs and cutouts**. |
| 28 | |
| 29 | --- |
| 30 | |
| 31 | ## Setup — Authentication |
| 32 | |
| 33 | Before making any API call, you need a valid Bria access token. |
| 34 | |
| 35 | ### Step 1: Check for existing credentials |
| 36 | |
| 37 | ```bash |
| 38 | if [ -f ~/.bria/credentials ]; then |
| 39 | BRIA_ACCESS_TOKEN=$(grep '^access_token=' "$HOME/.bria/credentials" | cut -d= -f2-) |
| 40 | BRIA_API_KEY=$(grep '^api_token=' "$HOME/.bria/credentials" | cut -d= -f2-) |
| 41 | fi |
| 42 | if [ -z "$BRIA_ACCESS_TOKEN" ]; then |
| 43 | echo "NO_CREDENTIALS" |
| 44 | elif [ -n "$BRIA_API_KEY" ]; then |
| 45 | echo "READY" |
| 46 | else |
| 47 | echo "CREDENTIALS_FOUND" |
| 48 | fi |
| 49 | ``` |
| 50 | |
| 51 | If the output is `READY`, skip straight to making API calls — no introspection needed. |
| 52 | If the output is `CREDENTIALS_FOUND`, skip to Step 3. |
| 53 | If the output is `NO_CREDENTIALS`, proceed to Step 2. |
| 54 | |
| 55 | ### Step 2: Authenticate via device authorization |
| 56 | |
| 57 | Start the device authorization flow: |
| 58 | |
| 59 | **2a. Request a device code:** |
| 60 | |
| 61 | ```bash |
| 62 | DEVICE_RESPONSE=$(curl -s -X POST "https://engine.prod.bria-api.com/v2/auth/device/authorize" \ |
| 63 | -H "Content-Type: application/json") |
| 64 | echo "$DEVICE_RESPONSE" |
| 65 | ``` |
| 66 | |
| 67 | Parse the response fields: |
| 68 | - `device_code` — used to poll for the token (keep this, don't show to user) |
| 69 | - `user_code` — the code the user must enter (e.g. `BRIA-XXXX`) |
| 70 | - `interval` — seconds between poll attempts |
| 71 | |
| 72 | **2b. Show the user a single sign-in link.** Tell them exactly this — nothing more: |
| 73 | |
| 74 | > **Connect your Bria account:** [Click here to sign in](https://platform.bria.ai/device/verify?user_code={user_code}) |
| 75 | > Your code is **{user_code}** — it's already filled in. |
| 76 | |
| 77 | Do NOT show two links. Do NOT show the raw URL separately. Do NOT use `verification_uri` from the API response. Keep it to one clickable link. |
| 78 | |
| 79 | **2c. Poll for the token.** After showing the user the code, immediately start polling. Try up to 60 times with the given interval (default 5 seconds): |
| 80 | |
| 81 | ```bash |
| 82 | for i in $(seq 1 60); do |
| 83 | TOKEN_RESPONSE=$(curl -s -X POST "https://engine.prod.bria-api.com/v2/auth/token" \ |
| 84 | -d "grant_type=urn:ietf:params:oauth:grant-type:device_code" \ |
| 85 | -d "device_code=$DEVICE_CODE") |
| 86 | ACCESS_TOKEN=$(printf '%s' "$TOKEN_RESPONSE" | sed -n 's/.*"access_token" *: *"\([^"]*\)".*/\1/p') |
| 87 | if [ -n "$ACCESS_TOKEN" ]; then |
| 88 | BRIA_ACCESS_TOKEN="$ACCESS_TOKEN" |
| 89 | REFRESH_TOKEN=$(printf '%s' "$TOKEN_RESPONSE" |