Bria.ai image API — generate from text prompts, edit with natural language, remove backgrounds for transparent PNGs, and create product lifestyle shots. Auth...
---
name: bria-ai
description: >
Bria.ai image API — generate from text prompts, edit with natural language,
remove backgrounds for transparent PNGs, and create product lifestyle shots.
Authenticates via OAuth device flow, caches credentials in ~/.bria/credentials,
calls 20+ endpoints. Commercially safe, royalty-free.
Triggers on: remove background, transparent PNG, cutout, generate image, create banner,
edit photo, product photography, upscale, restyle, inpainting, outpainting,
lifestyle shot, background replacement, object removal, photo restoration.
license: MIT
homepage: https://bria.ai
metadata:
author: Bria AI
version: "1.3.0"
openclaw:
requires:
env:
- BRIA_API_KEY
anyBins:
- curl
config:
- ~/.bria/credentials
primaryEnv: BRIA_API_KEY
homepage: https://bria.ai
emoji: "\U0001F5BC"
---
# Bria — AI Image Generation, Editing & Background Removal
Commercially safe, royalty-free image generation and editing through 20+ API endpoints.
For additional endpoint details, see the [Bria API reference for agents](https://docs.bria.ai/llms.txt).
## When to Use This Skill
- **Generate images** — "create an image of...", "make me a banner", "generate a hero image", "I need a product photo"
- **Edit images** — "change the background", "make it look like winter", "add a vase to the table", "remove the person"
- **Remove/replace backgrounds** — "make the background transparent", "cut out the product", "replace with a studio background"
- **Product photography** — "create a lifestyle shot", "place this product in a kitchen scene", "e-commerce packshot"
- **Enhance/transform** — "upscale this image", "make it higher resolution", "restyle as oil painting", "change the lighting"
---
## Setup — Authentication
### Step 1: Check for existing credentials
```bash
if [ -f ~/.bria/credentials ]; then
BRIA_ACCESS_TOKEN=$(grep '^access_token=' "$HOME/.bria/credentials" | cut -d= -f2-)
BRIA_API_KEY=$(grep '^api_token=' "$HOME/.bria/credentials" | cut -d= -f2-)
fi
if [ -z "$BRIA_ACCESS_TOKEN" ]; then
echo "NO_CREDENTIALS"
elif [ -n "$BRIA_API_KEY" ]; then
echo "READY"
else
echo "CREDENTIALS_FOUND"
fi
```
- `READY` → skip to making API calls
- `CREDENTIALS_FOUND` → skip to Step 3
- `NO_CREDENTIALS` → proceed to Step 2
### Step 2: Authenticate via device flow
Source the auth helper and run `bria_auth`:
```bash
source ~/.agents/skills/bria-ai/references/code-examples/bria_auth.sh
bria_auth
```
`bria_auth` will print `SIGN_IN_URL=...` and `USER_CODE=...`. Show the user exactly this — nothing more:
> **Connect your Bria account:** [Click here to sign in]({SIGN_IN_URL})
> Your code is **{USER_CODE}** — it's already filled in.
Then wait; `bria_auth` polls automatically and prints `AUTHENTICATED` when done.
If it prints an error, the code expired — run `bria_auth` again.
**Do not proceed with any API call until authentication is confirmed.**
### Step 3: Verify billing status and resolve API key
```bash
source ~/.agents/skills/bria-ai/references/code-examples/bria_auth.sh
bria_introspect
```
Interpret output:
- `BILLING_ERROR: ...` — relay the message to the user verbatim and **stop**. Do not make any API calls.
- `TOKEN_EXPIRED` — tell the user their session expired and restart from Step 2.
- `READY` — `BRIA_API_KEY` is now cached in `~/.bria/credentials`. Proceed.
---
## Decision Tree — Which Endpoint to Use
```
Transparent PNG / cutout / remove background?
→ /v2/image/edit/remove_background
Generate image from scratch (text → image)?
→ /v2/image/generate
Edit existing image with text instruction?
→ /v2/image/edit (use --key images)
Change / replace / blur background?
→ /v2/image/edit/replace_background (prompt: "blur" or describe new bg)
Place product in a lifestyle scene?
→ /v1/product/lifestyle_shot_by_text
Upscale / increase resolution?
→ /v2/image/edit/increase_resolution (scale: 2 or 4)
Anything else (restyle, relight, reseason, restore, colorize, sketch, blend, outpaint)?
→ See references/capabilities.md for the full endpoint list
```
---
## How to Call Any Endpoint
```bash
source ~/.agents/skills/bria-ai/references/code-examples/bria_client.sh
# Generate (no image input)
RESULT=$(bria_call /v2/image/generate "" '"prompt": "your description", "aspect_ratio": "16:9", "sync": true')
# Remove background
RESULT=$(bria_call /v2/image/edit/remove_background "/path/to/local/image.png")
# Replace background
RESULT=$(bria_call /v2/image/edit/replace_background "https://example.com/img.jpg" '"prompt": "sunset beach"')
# Edit image (uses images array — pass --key images)
RESULT=$(bria_call /v2/image/edit "/path/to/image.png" --key images '"instruction": "make it look warmer"')
# Upscale
RESULT=$(bria_call /v2/image/edit/increase_resolution "https://example.com/img.jpg" '"scale": 4')
# Lifestyle shot
RESULT=$(bria_call /v1/product/lifestyle_shot_by_text "/path/to/product.png" '"scene_description": "modern kitchen countertop"')
echo "$RESULT"
```
**Calling convention:** `bria_call <endpoint> <image_or_empty> [--key <json_key>] [extra JSON fields...]`
- Pass a URL, local file path, or `""` for endpoints without image input
- Use `--key images` when the endpoint expects an `images` array instead of `image`
- Returns the result image URL on success, or prints an error to stderr
**Generation options:** Aspect ratios `1:1`, `16:9`, `4:3`, `9:16`, `3:4`. Resolution `1MP` (default) or `4MP` (more detail, +30s). Pass `"sync": true` for single images.
> **Advanced**: For precise control over generation, use the **vgl** skill for structured VGL JSON prompts.
---
## Common Failures
- **`bria_call` returns empty / no URL** → `BRIA_API_KEY` was not set. Run Step 3 (`bria_introspect`) to cache it.
- **Async job times out** → Some endpoints take 60–90s. If `bria_call` reports a timeout, retry once; the job may have been queued.
- **ERROR 401** → API key is stale. Delete `~/.bria/credentials` and re-authenticate from Step 2.
- **`BILLING_ERROR`** → Relay message to user verbatim, do not retry API calls.
- **Local file not found** → Pass the absolute path; `bria_client.sh` handles base64 encoding automatically.
- **`/v2/image/edit` returns wrong result** → Confirm `--key images` flag is present; this endpoint requires the images array format.
---
## Resources
- **[Capabilities & Prompt Recipes](references/capabilities.md)** — Full endpoint table, use-case recipes, and prompt engineering tips
- **[API Endpoints Reference](references/api-endpoints.md)** — Complete parameter documentation for all 20+ endpoints
- **[Shell Client (bria_client.sh)](references/code-examples/bria_client.sh)** — `bria_call` helper: auth, base64, JSON, polling
- **[Auth Helper (bria_auth.sh)](references/code-examples/bria_auth.sh)** — `bria_auth` and `bria_introspect` functions
- **[Full API docs for agents (llms.txt)](https://docs.bria.ai/llms.txt)** — Agent-ready Bria API reference
## Related Skills
- **vgl** — Structured VGL JSON prompts for precise, deterministic control over FIBO image generation
- **image-utils** — Classic image manipulation (resize, crop, composite, watermarks) for post-processing
don't have the plugin yet? install it then click "run inline in claude" again.
broke down setup and api calls into explicit numbered steps with clear input/output contracts, added decision tree logic as explicit if-else points, documented edge cases (rate limits, auth expiry, empty results, timeouts, network failures), clarified inputs section with env vars and external dependencies, and added explicit outcome signals so users know when the skill succeeded.
Commercially safe, royalty-free image generation and editing through 20+ API endpoints. Generate images from text, edit existing images with natural language, remove or replace backgrounds, upscale resolution, and create product lifestyle shots.
Use this skill to generate, edit, and transform images via Bria's API. Reach for it when a user asks to create an image from scratch ("make me a banner"), edit an existing image ("remove the person"), remove or replace backgrounds ("make it transparent", "put it in a kitchen"), upscale or enhance photos, restyle images, or create product lifestyle shots. The skill handles OAuth authentication, credential caching, and wraps 20+ API endpoints with a simple call interface. All outputs are commercially safe and royalty-free.
access_token= and api_token= lines. Created during device flow auth. Delete to force re-authentication.which curl.Run this check to avoid unnecessary re-auth:
if [ -f ~/.bria/credentials ]; then
BRIA_ACCESS_TOKEN=$(grep '^access_token=' "$HOME/.bria/credentials" | cut -d= -f2-)
BRIA_API_KEY=$(grep '^api_token=' "$HOME/.bria/credentials" | cut -d= -f2-)
fi
if [ -z "$BRIA_ACCESS_TOKEN" ]; then
echo "NO_CREDENTIALS"
elif [ -n "$BRIA_API_KEY" ]; then
echo "READY"
else
echo "CREDENTIALS_FOUND"
fi
Output interpretation:
READY → Both tokens cached. Skip to Step 4 (make API calls).CREDENTIALS_FOUND → Access token found but API key missing. Jump to Step 3 (bria_introspect).NO_CREDENTIALS → No cached tokens. Proceed to Step 2 (device flow auth).Source the auth helper and trigger device flow:
source ~/.agents/skills/bria-ai/references/code-examples/bria_auth.sh
bria_auth
What bria_auth does:
SIGN_IN_URL=<url> and USER_CODE=<6-char code>.Connect your Bria account: Click here to sign in Your code is {USER_CODE} , it's already filled in.
AUTHENTICATED and exits 0. Credentials are now in ~/.bria/credentials.Do not proceed to Step 3 until bria_auth prints AUTHENTICATED and exits cleanly (code 0).
If the device code expires (typically 15 minutes), re-run bria_auth to get a new code.
Run the introspection helper:
source ~/.agents/skills/bria-ai/references/code-examples/bria_auth.sh
bria_introspect
Output interpretation:
BILLING_ERROR: <message> → Relay the message to the user verbatim. Do not proceed to Step 4. Do not retry.TOKEN_EXPIRED → Tell the user: "Your Bria session expired. Reconnecting..." and go back to Step 2.READY → Billing confirmed. BRIA_API_KEY is now cached in ~/.bria/credentials. Proceed to Step 4.Source the client helper and invoke bria_call:
source ~/.agents/skills/bria-ai/references/code-examples/bria_client.sh
# Example: Generate image from text
RESULT=$(bria_call /v2/image/generate "" '"prompt": "your description", "aspect_ratio": "16:9", "sync": true')
# Example: Remove background
RESULT=$(bria_call /v2/image/edit/remove_background "/path/to/local/image.png")
# Example: Replace background
RESULT=$(bria_call /v2/image/edit/replace_background "https://example.com/img.jpg" '"prompt": "sunset beach"')
# Example: Edit image (note --key images flag)
RESULT=$(bria_call /v2/image/edit "/path/to/image.png" --key images '"instruction": "make it look warmer"')
# Example: Upscale
RESULT=$(bria_call /v2/image/edit/increase_resolution "https://example.com/img.jpg" '"scale": 4')
# Example: Lifestyle shot
RESULT=$(bria_call /v1/product/lifestyle_shot_by_text "/path/to/product.png" '"scene_description": "modern kitchen countertop"')
echo "$RESULT"
Calling convention: bria_call <endpoint> <image_or_empty> [--key <json_key>] [extra JSON fields...]
--key images only for /v2/image/edit (wraps image in an images array). Omit for other endpoints.'"scale": 4', '"prompt": "..."').Returns: On success, prints the result image URL to stdout. On failure, prints error message to stderr and returns empty.
Check the output:
if [ -z "$RESULT" ]; then
# bria_call printed an error to stderr
echo "Image generation failed. Check the error above."
exit 1
else
# $RESULT is the image URL (expires in 24 hours)
echo "Image ready: $RESULT"
fi
Important: All generated/edited image URLs expire after 24 hours. Download and store locally if you need to keep them.
Which endpoint do I use?
/v2/image/edit/remove_background. Pass the image (local or URL)./v2/image/generate. Pass empty string "" as the image argument. Include "sync": true for single images, omit for batch/async jobs./v2/image/edit. Pass the image and --key images flag. Include "instruction": "..."./v2/image/edit/replace_background. Pass the image and a prompt like "blur" or "sunset beach"./v1/product/lifestyle_shot_by_text. Pass the product image (local or URL) and "scene_description": "..."./v2/image/edit/increase_resolution. Pass the image and "scale": 2 or "scale": 4. Higher scale takes longer.references/capabilities.md for the full endpoint table and matching use case.What if the API key is missing after Step 3?
If bria_call returns empty and stderr shows "API_KEY not set", re-run Step 3 (bria_introspect) to ensure the token is cached. If that fails, delete ~/.bria/credentials and restart from Step 2.
What if the image URL is a local file?
bria_client.sh detects local paths (anything not starting with http:// or https://), reads the file, base64-encodes it, and includes it in the request. Pass the absolute path. Relative paths like ./image.png work but absolute (~/... or /home/...) is safer.
What if authentication times out or the device code expires?
The device code is valid for ~15 minutes. If polling times out, re-run bria_auth to get a fresh code. The user will see a new sign-in link. If Step 2 completes but Step 3 (bria_introspect) fails with TOKEN_EXPIRED, the access token has expired; go back to Step 2.
What if the request fails with HTTP 401?
API key is stale or invalid. Delete ~/.bria/credentials and re-authenticate from Step 2.
What if the request times out (60s+)?
Async jobs (especially upscale 4x) can take 60-90s. bria_client.sh has a built-in timeout. If it times out, the job may still be queued on Bria's side. Retry the call once. Do not retry more than twice.
What if the result is empty but no error was printed?
The endpoint may have returned an empty or null result. Check the endpoint docs in references/api-endpoints.md. For generation endpoints, ensure "sync": true is set; otherwise the job is async and you need to poll for the result (advanced).
What if the user has no active Bria subscription?
Step 3 (bria_introspect) will return BILLING_ERROR: <reason>. Relay the message to the user verbatim and stop. Do not attempt API calls.
Success output: A single image URL (string), valid for 24 hours. Example: https://api.bria.ai/v2/results/abc123def456.jpg.
File location: Not applicable. Images are hosted on Bria's CDN and returned as URLs. To persist, download the image within 24 hours and store locally.
Data format: Image URLs are direct HTTPS links. No JSON wrapper. No pagination. One request = one image (for sync=true).
Error output: Error messages printed to stderr. Examples:
ERROR 401: Invalid API KeyERROR 400: Missing required field "prompt"TIMEOUT: Job did not complete within 60 secondsBILLING_ERROR: Account suspendedOn success, bria_call exits 0 and prints the URL to stdout. On failure, it exits non-zero and prints the error to stderr.
The user knows the skill worked when:
AUTHENTICATED, exits cleanly, and ~/.bria/credentials now contains both access_token= and api_token= lines.READY and does not raise a BILLING_ERROR.BRIA_API_KEY was not set or expired. Run Step 3 (bria_introspect) to cache or refresh it.--key images flag is present. This endpoint requires the images array format.'"prompt": "..."', not '"prompt": ...'). The outer single quotes protect the inner double quotes from shell expansion.Credits: Original skill authored by Bria AI. Enriched for Implexa quality standards.