curl --request POST \
--url https://api.samsa.ai/public/v1/images/uploads/prepare \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content_type": "image/png",
"filename": "christmas-card.png",
"size_bytes": 4718592
}
'import requests
url = "https://api.samsa.ai/public/v1/images/uploads/prepare"
payload = {
"content_type": "image/png",
"filename": "christmas-card.png",
"size_bytes": 4718592
}
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({content_type: 'image/png', filename: 'christmas-card.png', size_bytes: 4718592})
};
fetch('https://api.samsa.ai/public/v1/images/uploads/prepare', 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/uploads/prepare",
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([
'content_type' => 'image/png',
'filename' => 'christmas-card.png',
'size_bytes' => 4718592
]),
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/uploads/prepare"
payload := strings.NewReader("{\n \"content_type\": \"image/png\",\n \"filename\": \"christmas-card.png\",\n \"size_bytes\": 4718592\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/uploads/prepare")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"content_type\": \"image/png\",\n \"filename\": \"christmas-card.png\",\n \"size_bytes\": 4718592\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.samsa.ai/public/v1/images/uploads/prepare")
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 \"content_type\": \"image/png\",\n \"filename\": \"christmas-card.png\",\n \"size_bytes\": 4718592\n}"
response = http.request(request)
puts response.read_body{
"allowed_content_types": [
"image/jpeg",
"image/png",
"image/webp"
],
"expires_at": "2026-10-08T12:00:00Z",
"image_id": "3f1c2b7e-8d4a-4c1e-9b2f-5a6d7e8f9a0b",
"max_bytes": 10485760,
"upload_url": "https://<account>.r2.cloudflarestorage.com/user-<id>/3f1c2b7e-8d4a-4c1e-9b2f-5a6d7e8f9a0b.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=..."
}{
"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"
}
}Prepara un upload di immagine
Passaggio 1 dell’upload di immagini: ottieni un image_id e un URL PUT presigned per un file locale.
curl --request POST \
--url https://api.samsa.ai/public/v1/images/uploads/prepare \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content_type": "image/png",
"filename": "christmas-card.png",
"size_bytes": 4718592
}
'import requests
url = "https://api.samsa.ai/public/v1/images/uploads/prepare"
payload = {
"content_type": "image/png",
"filename": "christmas-card.png",
"size_bytes": 4718592
}
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({content_type: 'image/png', filename: 'christmas-card.png', size_bytes: 4718592})
};
fetch('https://api.samsa.ai/public/v1/images/uploads/prepare', 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/uploads/prepare",
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([
'content_type' => 'image/png',
'filename' => 'christmas-card.png',
'size_bytes' => 4718592
]),
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/uploads/prepare"
payload := strings.NewReader("{\n \"content_type\": \"image/png\",\n \"filename\": \"christmas-card.png\",\n \"size_bytes\": 4718592\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/uploads/prepare")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"content_type\": \"image/png\",\n \"filename\": \"christmas-card.png\",\n \"size_bytes\": 4718592\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.samsa.ai/public/v1/images/uploads/prepare")
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 \"content_type\": \"image/png\",\n \"filename\": \"christmas-card.png\",\n \"size_bytes\": 4718592\n}"
response = http.request(request)
puts response.read_body{
"allowed_content_types": [
"image/jpeg",
"image/png",
"image/webp"
],
"expires_at": "2026-10-08T12:00:00Z",
"image_id": "3f1c2b7e-8d4a-4c1e-9b2f-5a6d7e8f9a0b",
"max_bytes": 10485760,
"upload_url": "https://<account>.r2.cloudflarestorage.com/user-<id>/3f1c2b7e-8d4a-4c1e-9b2f-5a6d7e8f9a0b.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=..."
}{
"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"
}
}filename, il content_type (image/jpeg, image/png o image/webp) e la
dimensione esatta del file in size_bytes. La risposta restituisce
201 Created con il nuovo image_id, un upload_url presigned (valido 1
ora), il suo expires_at, il limite max_bytes e gli allowed_content_types.
Poi fai il PUT dei byte grezzi del file su upload_url con lo stesso
Content-Type e senza header Authorization:
curl -X PUT -H "Content-Type: image/png" --data-binary @photo.png "<upload_url>"
POST /images/uploads/{image_id}/complete.
size_bytes è obbligatorio e deve essere la dimensione esatta del file (al massimo
10,485,760 byte): è firmata in upload_url, quindi un PUT di qualsiasi altra
lunghezza viene rifiutato. Puoi avere al massimo 20 upload in attesa di
completamento; oltre, prepare restituisce
429 too_many_pending_uploads.
Richiede uno qualsiasi degli scope images.edit, images.transform o
videos.generate. Gratuito.Autorizzazioni
Organization API key (Authorization: Bearer samsa_sk_...) or OAuth 2.1 access token (Authorization: Bearer samsa_at_...).
Corpo
POST /images/uploads/prepare body — describe the file you will PUT.
Original filename. Stored as the image name; never used as the storage key.
1 - 255MIME type of the file — one of: image/jpeg, image/png, image/webp. Send the SAME value as the Content-Type header of the PUT; complete refuses bytes that are a different format.
The EXACT size of the file in bytes (at most 10485760). It is signed into upload_url: a PUT of any other length is rejected by storage. curl --data-binary @file sends the file's real length.
1 <= x <= 10485760Optional width in pixels. Only used to refuse an image over the 32 MP limit early; the stored dimensions are measured from the uploaded bytes at complete.
x >= 1Optional height in pixels (see width).
x >= 1Risposta
Successful Response
201 body for POST /images/uploads/prepare — where and how to PUT the file.
The new image's id. Send it to POST /images/uploads/{image_id}/complete after the PUT.
Presigned URL. PUT the raw file bytes here with the header Content-Type: <content_type> (no Authorization header).
UTC instant (ISO 8601) after which upload_url stops accepting the PUT (1 hour after prepare).
Largest accepted file size in bytes; complete refuses a bigger file.
The accepted MIME types.