Skip to content

Remove an image's background

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

This page has 2 commands: Remove image background (POST /v2/files/removeBackground) and Get results of image background removal job (GET /v2/files/removeBackground). Use this method to remove background from images. Each call needs a bearer token and counts towards your hourly API limit.

After reading this you will know

  • How to remove an image's background
  • Which parameters each of the 2 commands takes
  • Sample code in 9 languages and a sample answer

Every command on this page needs a bearer token and counts towards your hourly limit.

POSThttps://api.sirv.com/v2/files/removeBackground

Use this method to remove background from images.

The answer gives the ID of the job. Check its progress with Get results of image background removal job.

Request body (JSON)

FieldTypeRequiredExampleDescription
filenamestringYes/REST API Examples/filename.jpgPath of the image, starting with /.
overwritebooleanNofalseOverwrite original image or not
formatstringNopngOutput image format. One of: png, jpg, original.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/removeBackground', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' },
body: JSON.stringify({
"filename": "/REST API Examples/filename.jpg",
"overwrite": false,
"format": "png"
}),
});
console.log(res.status, await res.text());

Example response

{
"id": "string"
}

Get results of image background removal job

Section titled “Get results of image background removal job”
GEThttps://api.sirv.com/v2/files/removeBackground

Use this method to get results of the job created with POST /v2/files/removeBackground.

Query parameters

NameTypeRequiredExampleDescription
idstringYesJob ID returned from POST /files/removeBackground

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/removeBackground?id=JOB_ID', {
method: 'GET',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Example response

{
"progress": 0
}
Back to top