Files
A request body is JSON of at most 256 KB, so a file never travels in it. Three steps instead: ask B7R for an upload with POST /v1/uploads, PUT the file to the address it answers, then send the upload's upload_id in the call that uses the file.
- The address is on B7R's own storage in Saudi Arabia. It takes one
PUTof the whole file, with thecontent-typeheader the answer gives; a secondPUTto it is refused. - B7R reads the file back and decides its type from its bytes and its size from its length. A file whose bytes are not the type you declared, or whose length is not
size_bytes, is refused by the call that uses it. - Two deadlines. Start the
PUTbeforeupload.expires_at, when the address expires: it can be about a minute, so send the file right after you have the answer (a latePUTis refused; ask again). Use the upload byexpires_at, an hour after you asked. An upload is used once, and deleted three hours after you asked whether it was used or not. - The answer is never stored: a lost answer cannot be read again. Ask again; the first upload is never used and is deleted with the rest.
- An upload is used up by the call that saves it (a product create or change). A call refused or cut off before it saves leaves the upload usable, so a retry can name it again until
expires_at. - Each upload counts against your uploads an hour,
uploads_per_hourinGET /v1/me?include=limits. Past it the answer is429 rate_limitedwithRetry-After. When B7R holds too many uploads from every account together, the answer is503 service_unavailablewithRetry-After: try again then.
Ask for an upload
Any key may call it, but each purpose needs its own area of the key (the table below): without it the answer is 403 area_forbidden naming the area, before anything is made. A purpose is taken from the day its feature is live; before that it answers 400 invalid_request with invalid_value on purpose.
The type and size must be ones the purpose takes, or the answer is 400 invalid_request naming content_type (with the types it takes in valid_values) or size_bytes.
Headers
Bearer b7r_live_.... Any valid key. X-B7R-Key works too; send one, never both.
A new value per operation (up to 255 letters, digits, ., _, : or -; a UUID works), the same value on its retries. See Safe retries.
application/json, when the request has a body.
ar for Arabic error titles; anything else gives English. Codes never change.
Body
What the file is for. Each purpose needs its own area of the key, and is taken only once its release is live. One of design, design_original, my_store_image, ticket_image, avatar, brand_logo.
What the file is. B7R reads the file back and decides its type from its bytes; a file of another type is refused when it is used. One of image/png, image/jpeg, image/webp, application/pdf.
The file's exact size in bytes. A file of another size is refused when it is used. At most 26214400.
Answer
Name it in the call that uses the file.
Child fields
Always "PUT".
Send the file here once, as the whole request body. The address works for one PUT and is never shown again.
Child fields
The content type you declared. One of image/png, image/jpeg, image/webp, application/pdf.
Start the PUT before this time: the address expires then. It is short (about a minute): PUT the file right after you have the answer.
Use the upload by this time, an hour after you asked: name its upload_id in the call that uses the file before then. After it the upload is never used and is deleted.
Errors
| HTTP | Code | Retry |
|---|---|---|
| 400 | invalid_request | No |
| 400 | idempotency_key_required | No |
| 401 | unauthorized | No |
| 403 | area_forbidden | No |
| 403 | account_inactive | No |
| 403 | connection_disabled | No |
| 403 | https_required | No |
| 413 | request_too_large | No |
| 415 | unsupported_media_type | No |
| 429 | rate_limited | Yes |
| 500 | internal_error | Yes |
| 502 | upstream_unavailable | Yes |
| 503 | api_unavailable | Yes |
| 503 | request_expired | Yes |
| 503 | service_unavailable | Yes |
| 504 | upstream_timeout | Yes |
curl -X POST https://api.b7r.app/v1/uploads \
-H "Authorization: Bearer $B7R_API_KEY" \
-H "Idempotency-Key: $(uuidgen 2>/dev/null || node -e 'console.log(crypto.randomUUID())')" \
-H "Content-Type: application/json" \
-d '{
"purpose": "design",
"content_type": "image/png",
"size_bytes": 1843200
}'const res = await fetch("https://api.b7r.app/v1/uploads", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.B7R_API_KEY}`,
"Idempotency-Key": crypto.randomUUID(),
"Content-Type": "application/json",
},
body: JSON.stringify({
"purpose": "design",
"content_type": "image/png",
"size_bytes": 1843200
}),
});
const data = await res.json();import os, requests, uuid
res = requests.post(
"https://api.b7r.app/v1/uploads",
headers={
"Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"purpose": "design",
"content_type": "image/png",
"size_bytes": 1843200
},
timeout=30,
)
data = res.json(){
"upload_id": "6f1c2a9e-4b7d-4c3a-9e2f-0a1b2c3d4e5f",
"upload": {
"method": "PUT",
"url": "https://data.b7r.app/storage/v1/object/upload/sign/custom-api-uploads/2f9a6e1c-0d4b-4e8a-9c7f-1b2a3c4d5e6f/6f1c2a9e-4b7d-4c3a-9e2f-0a1b2c3d4e5f?token=sample",
"headers": {
"content-type": "image/png"
},
"expires_at": "2026-12-01T08:01:00.000Z"
},
"expires_at": "2026-12-01T09:00:00.000Z"
}Send the file
import { readFile } from "node:fs/promises";
const file = await readFile("design.png");
const response = await fetch(upload.upload.url, {
method: "PUT",
headers: upload.upload.headers,
body: file,
});
if (!response.ok) throw new Error(`upload failed: ${response.status}`);curl -sS -X PUT "$UPLOAD_URL" \
-H "content-type: image/png" \
--data-binary @design.pngPurposes
| Purpose | Area it needs | File types | Largest file |
|---|---|---|---|
design | products:write | image/png, image/jpeg, image/webp | 25 MB |
design_original | products:write | application/pdf | 25 MB |
my_store_image | my_store:write | image/png, image/jpeg, image/webp | 5 MB |
ticket_image | tickets:write | image/png, image/jpeg, image/webp | 5 MB |
avatar | settings:write | image/png, image/jpeg, image/webp | 2 MB |
brand_logo | settings:write | image/png, image/jpeg, image/webp | 2 MB |
