ShuttleAI provides an API to remove the background from images using our AI model. This guide will walk you through how to use the API to remove the background from an image.

Endpoint

POST https://api.shuttleai.com/v1/removebg

Request

To remove the background from an image, send a POST request to the endpoint with the following JSON body:

{
    "image": "data:image/png;base64,..."
}
  • image: The image to process, encoded in base64 format.

Example Request

Here is an example of how to send a request using curl:

curl -X POST https://api.shuttleai.com/v1/removebg \
    -H "Content-Type: application/json" \
    -d '{
        "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    }'

Response

The API will respond with a JSON object containing the URL of the processed image:

{
    "model": "shuttle-rbg",
    "data": {
        "url": "https://cdn.shuttleai.com/cdn/..."
    }
}
  • model: The model used for processing, which is shuttle-rbg.
  • data.url: The URL where the processed image can be accessed.

Example Response

Here is an example of a successful response:

{
    "model": "shuttle-rbg",
    "data": {
        "url": "https://cdn.shuttleai.com/cdn/processed-image.png"
    }
}

Encoding an Image in Base64

To encode an image in base64, you can use various tools and libraries. Here is an example using Python:

import base64

with open("path/to/your/image.png", "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
    print(f"data:image/png;base64,{encoded_string}")