Remove an image's background
Cut the subject out of a photo with one API call. The result is a transparent PNG in your brand library, with a link you can use in renders. Costs and limits.
POST /v1/images/remove-background cuts the subject out of a picture and saves it as a PNG with a
transparent background. The PNG goes into your workspace’s brand library, and the
answer gives you its link. Use the link as the value of an image layer in a render.
In the app, the same tool is Remove background in the brand library and the editor.
Send a picture
Send the picture’s link as JSON, or upload the file as multipart/form-data in a field named file.
name is optional in both: it names the new PNG in the brand library.
# A link to the picture
curl https://api.jamframe.com/v1/images/remove-background \
-H "Authorization: Bearer $JAMFRAME_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "url": "https://example.com/photos/product.jpg", "name": "Product shot" }'
# Or upload the file
curl https://api.jamframe.com/v1/images/remove-background \
-H "Authorization: Bearer $JAMFRAME_API_KEY" \
-F "[email protected]" \
-F "name=Product shot"const res = await fetch("https://api.jamframe.com/v1/images/remove-background", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.JAMFRAME_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com/photos/product.jpg",
name: "Product shot",
}),
});
const cutout = await res.json();
console.log(cutout.url, cutout.creditsCharged);import os
import requests
headers = {"Authorization": f"Bearer {os.environ['JAMFRAME_API_KEY']}"}
# A link to the picture
res = requests.post(
"https://api.jamframe.com/v1/images/remove-background",
headers=headers,
json={"url": "https://example.com/photos/product.jpg", "name": "Product shot"},
)
# Or upload the file
with open("product.jpg", "rb") as f:
res = requests.post(
"https://api.jamframe.com/v1/images/remove-background",
headers=headers,
files={"file": f},
data={"name": "Product shot"},
)
print(res.json()["url"])The picture must be:
- PNG, JPEG, GIF (the first frame is used) or WebP. SVG doesn’t work.
- At most 10 MB and about 50 megapixels.
- For
url: a publichttporhttpslink. A base64data:image/…URL works too.
The answer
The answer looks like this (asset is shortened):
{
"url": "https://cdn.jamframe.com/workspaces/ws_123/images/as_456.png",
"width": 2537,
"height": 1897,
"method": "local",
"model": "u2net",
"scaled": false,
"creditsCharged": 1,
"asset": {
"id": "as_456",
"kind": "image",
"name": "Product shot (no background)",
"url": "https://cdn.jamframe.com/workspaces/ws_123/images/as_456.png",
"mimeType": "image/png",
"tags": ["ai", "cutout"]
}
}
| Field | What it is |
|---|---|
url |
The link to the transparent PNG. It keeps working as long as the image stays in your brand library. |
width, height |
The PNG’s size in pixels. |
method |
local or model. See Cost. |
model |
The model that made the cut-out. |
scaled |
true when the picture was made smaller. Pictures over 4096 pixels on a side are cut out at 4096, and a PNG over 10 MB is made smaller to fit. |
asset |
The new image in your brand library. Its name is your name (or the file name) followed by “(no background)”. |
creditsCharged |
The AI credits this call used. |
The answer is not wrapped in data, unlike render answers.
Use the result in a render
Send url as the value of an image layer’s key:
{
"templateId": "YOUR_TEMPLATE_ID",
"modifications": {
"photo": "https://cdn.jamframe.com/workspaces/ws_123/images/as_456.png"
}
}
Cost
method |
How it works | AI credits |
|---|---|---|
local |
The usual way. JamFrame’s own servers cut the subject out. The original pixels are kept, and only the background is made transparent. | 1 |
model |
Used only when the usual way can’t run. An AI image model draws the subject again, so small text can change. | 4 |
These are AI credits, separate from render credits. A call that fails is refunded. See Credits.
Limits
- Each workspace can remove 120 backgrounds per 10 minutes. More answer
429 RATE_LIMITED. This counts on top of your per-minute limit. - When the servers are busy, you can also get
429 RATE_LIMITEDwithdetail.retryAfter(in seconds). Wait that long and try again.
Errors
| Status | error |
What to do |
|---|---|---|
400 |
VALIDATION_ERROR |
The link couldn’t be downloaded, or the file is too large or not a supported image. Read message. |
402 |
AI_CREDITS_EXCEEDED |
Your AI credits for this period are used up. |
413 |
VALIDATION_ERROR |
The upload is far too large. Keep pictures under 10 MB. |
429 |
RATE_LIMITED |
Too many calls, or the servers are busy. Wait and try again. |
502 |
AI_BAD_OUTPUT |
The cut-out failed for this picture. Try another picture. |
503 |
AI_UNAVAILABLE |
Background removal can’t run right now. Try later. |
504 |
AI_TIMEOUT |
It took too long. Try a smaller picture. |
See Errors for every other code.
Related
- Where the PNG is kept: Brand library
- Make images with AI in the app: AI images
- How AI credits work: Credits
Last updated
Still stuck?
Email [email protected] and a real person will reply. Tell us the template you were using and what you expected to happen.