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"
}
}Préparer un upload d'image
Étape 1 du téléversement d’image : obtiens un image_id et une URL PUT presignée pour un fichier local.
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, le content_type (image/jpeg, image/png ou image/webp) et la
taille exacte du fichier dans size_bytes. La réponse renvoie
201 Created avec le nouvel image_id, une upload_url presignée (valable
1 heure), son expires_at, la limite max_bytes et les
allowed_content_types.
Ensuite, fais un PUT des octets bruts du fichier vers upload_url avec le même
Content-Type et sans en-tête Authorization :
curl -X PUT -H "Content-Type: image/png" --data-binary @photo.png "<upload_url>"
POST /images/uploads/{image_id}/complete.
size_bytes est requis et doit être la taille exacte du fichier (au plus
10 485 760 octets) : elle est signée dans upload_url, donc un PUT de toute
autre longueur est rejeté. Tu peux avoir au plus 20 uploads en attente de
finalisation ; au-delà, prepare renvoie
429 too_many_pending_uploads.
Requiert l’un des scopes images.edit, images.transform ou videos.generate.
Gratuit.Autorisations
Organization API key (Authorization: Bearer samsa_sk_...) or OAuth 2.1 access token (Authorization: Bearer samsa_at_...).
Corps
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 >= 1Réponse
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.