curl --request POST \
--url https://api.samsa.ai/public/v1/images/background-removals \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"image": {
"image_id": "123e4567-e89b-12d3-a456-426614174000"
}
}
'import requests
url = "https://api.samsa.ai/public/v1/images/background-removals"
payload = { "image": { "image_id": "123e4567-e89b-12d3-a456-426614174000" } }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({image: {image_id: '123e4567-e89b-12d3-a456-426614174000'}})
};
fetch('https://api.samsa.ai/public/v1/images/background-removals', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.samsa.ai/public/v1/images/background-removals",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'image' => [
'image_id' => '123e4567-e89b-12d3-a456-426614174000'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.samsa.ai/public/v1/images/background-removals"
payload := strings.NewReader("{\n \"image\": {\n \"image_id\": \"123e4567-e89b-12d3-a456-426614174000\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.samsa.ai/public/v1/images/background-removals")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": {\n \"image_id\": \"123e4567-e89b-12d3-a456-426614174000\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.samsa.ai/public/v1/images/background-removals")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"image\": {\n \"image_id\": \"123e4567-e89b-12d3-a456-426614174000\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "pending",
"estimated_credits": 5
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}Rimuovere uno sfondo
Invia un job di rimozione dello sfondo — un’immagine sorgente — e ottieni un PNG trasparente.
curl --request POST \
--url https://api.samsa.ai/public/v1/images/background-removals \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"image": {
"image_id": "123e4567-e89b-12d3-a456-426614174000"
}
}
'import requests
url = "https://api.samsa.ai/public/v1/images/background-removals"
payload = { "image": { "image_id": "123e4567-e89b-12d3-a456-426614174000" } }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({image: {image_id: '123e4567-e89b-12d3-a456-426614174000'}})
};
fetch('https://api.samsa.ai/public/v1/images/background-removals', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.samsa.ai/public/v1/images/background-removals",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'image' => [
'image_id' => '123e4567-e89b-12d3-a456-426614174000'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.samsa.ai/public/v1/images/background-removals"
payload := strings.NewReader("{\n \"image\": {\n \"image_id\": \"123e4567-e89b-12d3-a456-426614174000\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.samsa.ai/public/v1/images/background-removals")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": {\n \"image_id\": \"123e4567-e89b-12d3-a456-426614174000\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.samsa.ai/public/v1/images/background-removals")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"image\": {\n \"image_id\": \"123e4567-e89b-12d3-a456-426614174000\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "pending",
"estimated_credits": 5
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The provided API key is invalid, expired, or revoked.",
"request_id": "8f14e45fceea167a5a36dedd4bea2543",
"param": "aspect_ratio"
}
}image sorgente, producendo un PNG trasparente. La chiamata
restituisce 202 Accepted con un id del job; interroga
GET /images/background-removals/{id}
per il risultato. L’image prende esattamente uno tra image_id, url o
base64 + mime_type. Non c’è alcun parametro di modello — v1 usa il modello di
rimozione dello sfondo predefinito. Richiede lo scope images.transform.
Esempio: una sorgente per modalità
curl -X POST https://api.samsa.ai/public/v1/images/background-removals \
-H "Authorization: Bearer $SAMSA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "image": { "image_id": "123e4567-e89b-12d3-a456-426614174000" } }'
curl -X POST https://api.samsa.ai/public/v1/images/background-removals \
-H "Authorization: Bearer $SAMSA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": { "url": "https://cdn.example.com/photo.png" },
"webhook_url": "https://example.com/webhooks/samsa"
}'
curl -X POST https://api.samsa.ai/public/v1/images/background-removals \
-H "Authorization: Bearer $SAMSA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "image": { "base64": "iVBORw0KGgoAAAANSUhEUg...", "mime_type": "image/png" } }'
pending:
{
"id": "f7a8b9c0-1d2e-4f3a-4b5c-6d7e8f9a0b1c",
"status": "pending",
"estimated_credits": 1
}
image_id che possiedi e per esso esiste già un risultato con lo sfondo rimosso,
l’invio restituisce immediatamente 202 con status: "completed" e
estimated_credits: 0 — nessun nuovo job viene messo in coda e il limite di
concorrenza della tua organizzazione non viene consumato. Ogni altro caso (una
sorgente https url/base64 o un image_id posseduto senza risultato pronto) è
il normale percorso addebitato sopra.{
"id": "f7a8b9c0-1d2e-4f3a-4b5c-6d7e8f9a0b1c",
"status": "completed",
"estimated_credits": 0
}
Errori
| Stato | Codice | Quando |
|---|---|---|
402 | insufficient_credits / insufficient_team_credits / insufficient_unallocated_credits | Il saldo che questa credenziale può spendere è al di sotto del costo del job. Le organizzazioni con almeno un team attivo ricevono i codici legati ai team invece di insufficient_credits (eccetto le organizzazioni di sistema esenti dal budgeting per team). Un guasto operativo nella detrazione stessa può comunque restituire il generico insufficient_credits, qualunque sia il regime. |
402 | subscription_inactive | L’organizzazione non ha un abbonamento utilizzabile. |
403 | missing_scope | La chiave non ha lo scope images.transform. |
404 | not_found | L’image_id sorgente è sconosciuto o non appartiene al creatore della chiave — anche un’immagine creata da un altro membro della tua organizzazione è un 404. |
422 | validation_error | Zero o più modalità sorgente fornite. |
429 | rate_limited / too_many_active_jobs | Finestra di frequenza per chiave o limite di concorrenza per organizzazione superato. |
Autorizzazioni
Organization API key as a bearer token: Authorization: Bearer samsa_sk_....
Corpo
POST /images/background-removals body (SAM-820 / S8.8 — ADR §7, §8, §10).
Remove the background from ONE source image, producing a transparent PNG.
The source is exactly one of image_id (an image in your organization's
context), an https url, or base64+mime_type. There is NO model
parameter — v1 uses the default background-removal model.
Cost = 1 credit on a miss; 0 on a cache HIT. When the source is an
image_id you own and a background-removed result already exists for it, the
submit returns 202 with status: "completed" and estimated_credits: 0
immediately (no new job is queued and the org's concurrency cap is not
consumed). Every other case (an https url/base64 source, or an owned
image_id with no ready result) is the normal charged path: 202 with
status: "pending" and estimated_credits: 1.
The source image: exactly one of image_id, an https url, or base64+mime_type.
Show child attributes
Show child attributes
Optional https webhook notified once on terminal status (signed per the webhook signature scheme; see the webhooks docs). On a cache hit the completed event fires immediately.
"https://example.com/webhooks/samsa"
Risposta
Successful Response
Shared 202 body for the transform-op submits (SAM-813 / S8 wave).
Every POST /images/<op> returns the async job handle
{id, status, estimated_credits}. The initial status is pending (the
job is queued), with ONE exception: background-removals and
vectorizations answer an owned-image_id cache hit (a ready result
already exists for that image) with status: "completed" and
estimated_credits: 0 — no new job is queued, the completed webhook
event is emitted immediately for a supplied webhook_url, and the result
is already available from the op's GET .../{id} endpoint. The other
transform ops (img2img, variations, resizes, upscales) always
start pending.
The job id — poll the op's GET .../{id} endpoint.
Initial status: pending (job queued — enter the polling flow), or completed with estimated_credits: 0 when background-removals / vectorizations serve an owned-image cache hit (the result is immediately available).
pending, processing, completed, failed, cancelled "pending"
Credits this job is expected to cost — 0 on a cache-hit completed response.
5

