storage API Documentation
Store, optimize, version, and serve files from any backend or framework with a single HTTP API. Built for zero-config image optimization, instant asset rollbacks, and predictable Naira pricing.
1. Overview & CalVer Versioning
storage uses Calendar Versioning (vYYYY.M.PATCH),
currently pinned at v2026.1.2. Every API response includes
X-API-Version: v2026.1.2 and
X-Storage-Platform: storage headers.
| Prefix | Purpose | Recommended For |
|---|---|---|
/api/v2026.1.2/* |
Pinned CalVer API routes | All new integrations |
/api/* |
Unversioned compatibility aliases | Existing legacy integrations (100% backward compatible) |
/uploads/:projectId/:filename |
Public cached file delivery | Direct <img>, PDFs, downloads, OpenGraph URLs |
Returns live platform version metadata and database connectivity status.
2. Authentication & Scoped API Keys
Every storage and mail request is authenticated per-project using a scoped API key generated inside your project dashboard. Pass your key using either of these headers:
# Recommended header x-api-key: st_live_94a8f1e0c4d2... # Alternative Bearer format (for st_* keys) Authorization: Bearer st_live_94a8f1e0c4d2...
Key Prefixes & Scopes
| Scope | Permitted Operations |
|---|---|
upload |
Upload files (POST /storage/upload) and roll back versions (POST /storage/files/:assetId/rollback) |
read |
List project assets (GET /storage/files) and inspect version histories (GET /storage/files/:assetId/versions) |
delete |
Delete by URL (DELETE /storage/delete) or delete full versioned assets (DELETE /storage/files/:assetId) |
mail |
Send OTP verification and password reset emails (POST /mail/send) |
st_live_ or
st_dev_ are hashed with SHA-256 on our servers and revealed only once upon creation.
Always store API keys in server-side environment variables (STORAGE_API_KEY) — never embed them in public browser JavaScript bundles.
3. 60-Second Quickstart
Create a project in your dashboard, copy your x-api-key into your app's
.env, and drop in one of the examples below.
// Helper for Node 18+ / Express (works directly with multer req.file) async function uploadToStorage(fileBuffer, filename, mimeType, opts = {}) { const form = new FormData(); form.append("file", new Blob([fileBuffer], { type: mimeType }), filename); if (opts.key) form.append("key", opts.key); if (opts.versionTag) form.append("versionTag", opts.versionTag); const qs = new URLSearchParams(); if (opts.width) qs.set("width", String(opts.width)); if (opts.quality) qs.set("quality", String(opts.quality)); if (opts.format) qs.set("format", opts.format); if (opts.optimize === false) qs.set("optimize", "false"); const res = await fetch( `https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/upload${qs.toString() ? "?" + qs : ""}`, { method: "POST", headers: { "x-api-key": process.env.STORAGE_API_KEY }, body: form, } ); const json = await res.json(); if (!res.ok) throw new Error(json.message || "Upload failed"); return json.data; // { url, assetId, version, savedBytes, ... } }
// app/api/upload/route.ts (Next.js App Router) import { NextResponse } from "next/server"; export async function POST(request: Request) { const incoming = await request.formData(); const file = incoming.get("file") as File | null; if (!file) return NextResponse.json({ error: "Missing file" }, { status: 400 }); const outbound = new FormData(); outbound.append("file", file, file.name); outbound.append("key", `uploads/${file.name}`); const res = await fetch( "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/upload?format=webp&quality=80", { method: "POST", headers: { "x-api-key": process.env.STORAGE_API_KEY! }, body: outbound, } ); const data = await res.json(); return NextResponse.json(data, { status: res.status }); }
# Upload an image, resize to max 1400px wide, convert to WebP, and version under "products/jacket"
curl -X POST "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/upload?width=1400&format=webp&quality=80" \
-H "x-api-key: st_live_your_key_here" \
-F "file=@./jacket.png" \
-F "key=products/jacket" \
-F "versionTag=v2026.1.2-r1"
import os, requests with open("banner.png", "rb") as f: res = requests.post( "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/upload", headers={"x-api-key": os.environ["STORAGE_API_KEY"]}, params={"format": "webp", "quality": 80}, data={"key": "marketing/banner"}, files={"file": ("banner.png", f, "image/png")}, ) res.raise_for_status() print(res.json()["data"]["url"])
4. Upload Files & Sharp Image Pipeline
Send a multipart/form-data request with a file field.
Raster images (PNG, JPEG, GIF,
WebP) are automatically optimized via Sharp using your project's defaults unless overridden.
SVGs, PDFs, Office files, and other non-raster binaries pass through untouched.
Multipart Form Fields
| Field | Type | Description |
|---|---|---|
filerequired |
Binary | The file to store (up to 25 MB default max file size). |
folderoptional |
String | Target project folder (e.g., avatars or marketing/banners). Also accepted via ?folder= query param. Auto-creates the folder if it doesn't exist yet. |
keyoptional |
String | Logical path/identifier (e.g., user-42). Re-uploading with the same folder + key appends a new immutable version (v2, v3…). |
versionTagoptional |
String | Custom label for this revision (e.g., v2026.1.2-rc1). Defaults to v1, v2, … |
Optimization Query Parameters
| Parameter | Default | Description |
|---|---|---|
format |
Project default (webp) |
Output image format: webp, avif, jpeg, png, or gif. |
quality |
80 |
Compression quality from 1 to 100. |
width / height |
Original | Resize preserving aspect ratio (fit: "inside") without upscaling smaller images. |
optimize |
true |
Pass optimize=false to bypass Sharp and store the exact original bytes. |
Example Response (200 OK)
{
"success": true,
"message": "File uploaded successfully",
"data": {
"name": "1796508956373-hero.webp",
"path": "/persistent/uploads/6b148d1a.../marketing/1796508956373-hero.webp",
"url": "https://storage-api-pa6e.onrender.com/uploads/6b148d1a.../marketing/1796508956373-hero.webp",
"assetId": "6b148d1a3912d46919911284",
"folder": "marketing",
"logicalKey": "marketing/hero",
"version": "v1",
"versionNumber": 1,
"versionTag": "v1",
"mimeType": "image/webp",
"sizeBytes": 22410,
"originalSizeBytes": 171330,
"savedBytes": 148920,
"optimized": true
}
}
Project Folders
Organize project assets into folders (up to 5 levels deep, e.g. avatars or
marketing/banners). Create folders in your project dashboard or via API, then pass
folder when uploading or listing files. Files uploaded into a folder are served at
/uploads/:projectId/:folder/:filename.
Returns all folders in your project with per-folder fileCount and totalSizeBytes.
# 1. Create a folder (nested paths auto-create parent folders)
curl -X POST "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/folders" \
-H "Content-Type: application/json" \
-H "x-api-key: st_live_your_key_here" \
-d '{"path": "marketing/banners"}'
# 2. Upload a file into that folder
curl -X POST "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/upload" \
-H "x-api-key: st_live_your_key_here" \
-F "folder=marketing/banners" \
-F "file=@./hero.png" \
-F "key=homepage-hero"
# 3. List only files inside that folder (use ?folder=root for project root)
curl "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/files?folder=marketing/banners" \
-H "x-api-key: st_live_your_key_here"
Deletes an empty folder safely. Non-empty folders return 409 Conflict until their files or subfolders are removed.
5. Immutable Asset Versioning & Rollbacks
When you include a logical key on upload, every subsequent upload to that key
is preserved as an immutable revision on disk and tracked in MongoDB. You can list assets, inspect every historical
revision, or switch the active version pointer back to any earlier revision in one request.
Lists up to 200 assets belonging to your authenticated project, each with its activeVersion and versionCount.
Returns the full revision history of an asset sorted newest-first, including each revision's CDN URL, size, compression savings, and timestamp.
curl -X POST "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/files/ASSET_ID/rollback" \
-H "Content-Type: application/json" \
-H "x-api-key: st_live_your_key_here" \
-d '{"versionNumber": 1}'
6. Deleting Files
You can delete either a single revision by its public URL (fully backward compatible with legacy apps) or wipe
an entire versioned asset and all its revision files by assetId. Project ownership
and path-traversal checks are strictly enforced on every delete.
curl -X DELETE "https://storage-api-pa6e.onrender.com/api/v2026.1.2/storage/delete" \
-H "Content-Type: application/json" \
-H "x-api-key: st_live_your_key_here" \
-d '{"fileUrl": "https://storage-api-pa6e.onrender.com/uploads/PROJECT_ID/1796508956373-hero.webp"}'
Deletes the FileAsset record, removes all revision files from persistent disk, and immediately reclaims project storage quota.
7. CDN Delivery & Smart Caching
Every uploaded file is immediately accessible at
https://storage-api-pa6e.onrender.com/uploads/:projectId/:filename with open CORS
(Access-Control-Allow-Origin: *), gzip/deflate compression,
ETag, and Last-Modified headers.
| File Types | Cache-Control Policy | TTL |
|---|---|---|
.webp .avif .jpg .png .svg .pdf |
public, max-age=31536000, immutable |
1 Year |
.docx .xlsx .csv |
public, max-age=604800, immutable |
7 Days |
| All other binary formats | public, max-age=86400 |
24 Hours |
8. Transactional Mail API
Send pre-styled HTML & plaintext transactional emails for verification (OTP)
or password_reset flows using your authenticated project API key. All dynamic values are HTML-escaped.
curl -X POST "https://storage-api-pa6e.onrender.com/api/v2026.1.2/mail/send" \
-H "Content-Type: application/json" \
-H "x-api-key: st_live_your_key_here" \
-d '{
"to": "ada@example.com",
"name": "Ada",
"type": "verification",
"data": { "otp": "482910" }
}'
9. Error Codes, Quotas & Plans
All error responses follow a predictable JSON shape: { "success": false, "message": "..." }.
| Status | Meaning |
|---|---|
400 |
Invalid input, missing file/URL, malformed path, or invalid version number. |
401 |
Missing x-api-key header or unauthenticated dashboard session. |
403 |
Invalid/revoked API key, missing scope, cross-project file access, or Free plan 2-project limit reached. |
404 |
File, asset ID, version number, or route not found. |
413 |
Single file exceeds MAX_FILE_SIZE_MB (25 MB) or project storage quota exceeded. |
429 |
OTP resend cooldown active (wait 45 seconds before requesting a new code). |
503 |
MongoDB temporarily unavailable for SaaS routes (legacy Postgres routes remain operational). |