Troubleshooting
On this page, you will find some common questions or issues you might encounter when integrating the Photoroom API, along with their answer.
Q: Why do I get the error "Unauthorized" when calling the API?
"Unauthorized" when calling the API?{"error":{"message":"Unauthorized"}}Q: Can I send my image in Base64 format?
const removeBackground = async (base64Image) => {
const options = {
method: "POST",
headers: {
"x-api-key": YOUR_API_KEY,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
image_file_b64: base64Image.split(",")[1],
}),
};
fetch("https://sdk.photoroom.com/v1/segment", options)
.then((response) => response.json())
.then((response) => {
console.log(response);
})
.catch((err) => console.error(err));
};import requests
import json
import base64
def encode_image_to_base64(image_path):
"""Reads an image file and converts it to a base64-encoded string."""
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
def remove_background(base64_image, api_key):
url = "https://sdk.photoroom.com/v1/segment"
headers = {
"x-api-key": api_key,
"Content-Type": "application/json",
"Accept": "application/json",
}
data = {
"image_file_b64": base64_image
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
response_data = response.json()
print(response_data)
except requests.exceptions.RequestException as err:
print(f"Error: {err}")
# Usage
api_key = "YOUR_API_KEY"
base64_image = encode_image_to_base64("/path/to/your/image.jpg")
remove_background(base64_image, api_key)Q: When I call the Remove Background API, the result image gets rotated
Q: I'm using Axios to make the API call, but I can't decode the result image
Q: I'm using requests in Python and I get a 500 error
requests in Python and I get a 500 errorQ: Photoroom API has stopped working/answering
Q: I have a technical issue/bug with Photoroom API
Last updated
Was this helpful?