Most CDN purges are blunt. You either clear one URL at a time, or you clear everything and pay for it in cache misses. If your site serves a dozen clients from one account, neither option fits.
smallPict now groups uploads into folders, and purges by folder. This post covers the folder rules, the three ways to use them (SDK, HTTP, MCP), and the rate limits to know before you wire purges into a deploy script.
What a folder is
A folder is a label attached to an upload. It is not a directory on a disk, and it does not change how the file is served. It changes two things: the stored path under your account, and the unit you can purge.
The rules are short:
- 1 to 3 segments, separated by
/, for exampleblog/2026orclient-a/banner - each segment allows
a-z,0-9,-and_, up to 64 characters, and the whole folder up to 128 - the server lower-cases the value, so
Blog/2026andblog/2026are the same folder - empty segments,
.., and more than three segments are rejected
The SDKs reject those last three cases before they send a request, as a validation error. Anything else malformed comes back from the API as 400 invalid_folder. Either way the call fails; no file lands in the wrong folder.
The folder also comes back in the result and in the job status. If you log the response, you have a record of where the file landed without a second request.
Uploading into a folder, in Node
The optimize() method takes a folder option:
import { SmallPictClient } from '@smallpict/sdk';
const client = new SmallPictClient({ apiKey: process.env.SMALLPICT_API_KEY as string, secretKey: process.env.SMALLPICT_SECRET_KEY as string,});
const result = await client.optimize({ file: 'banner.png', format: 'avif', folder: 'client-a/banner',});
console.log(result.folder); // 'client-a/banner'console.log(result.url, result.bytesSaved, result.modeApplied);That call queues a job, uploads the bytes to the pre-signed URL, polls the status endpoint until the job completes, and resolves with the result. The folder travels from the request to the job status, so the value you read back is the value the server stored.
The other six SDKs (Python, PHP, Go, Rust, Ruby and Java) take the same folder option, spelled the way each language expects.
Uploading into a folder, over HTTP
Without an SDK, the folder goes in the options object of POST /v1/optimize. Every request is signed with your secret key; the request signatures post shows how to compute X-Signature by hand.
curl -X POST https://api.smallpict.app/v1/optimize \ -H "X-API-Key: $SMALLPICT_API_KEY" \ -H "X-Timestamp: $TIMESTAMP" \ -H "X-Signature: $SIGNATURE" \ -H "Content-Type: application/json" \ -d "$BODY"with this body:
{ "filename": "banner.png", "mime_type": "image/png", "filesize": 482133, "options": { "format": "avif", "folder": "client-a/banner" }}The response carries an upload URL and a job id. Upload the bytes there with a PUT, then read the job status for the final folder and url.
Purging one folder
Here is the part that saves work. Instead of tracking a list of URLs per client, purge the folder:
await client.purgeCdn({ purgeType: 'folder', folder: 'client-a/banner' });purgeType takes three values:
url: the default. Purges the URLs you list.folder: purges one upload folder and everything in its sub-folders.all: purges every file of your account.
The result tells you where the purge ran. deliveryModes comes back as ['managed'] when smallPict's CDN did the work, or ['byo'] when the purge was forwarded to your own CDN because bring-your-own delivery is on. Same call, different destination.
The rate limits, before you put this in a deploy script
Folder and all purges are limited per hour, per account:
folder: 10 per hourall: 2 per hour
A request past the limit fails with 429 purge_rate_limited, and the SDKs do not retry it. That is deliberate: the limit frees up over the hour, not within seconds, so a retry loop would only burn attempts. Treat it as a scheduling problem, not a transient failure.
In practice, a deploy that touches 30 folders should not fire 30 purges. Group uploads so one folder maps to one deploy, or purge only the handful of folders that changed. Per-URL purges do not count toward these hourly limits.
From an AI assistant, over MCP
The smallPict MCP server exposes the same folder concept as tool parameters, so an assistant can do this without a script:
smallpict_optimize_imageaccepts an optionalfolder(same rules: 1 to 3 segments ofa-z,0-9,-,_). The server lower-cases it, and the result reports the stored folder.smallpict_purge_cdn_cacheacceptspurgeType:url,folderorall. Folder and all purges hit the same hourly limits, and the limit comes back as a tool error rather than being retried.smallpict_get_quotareports the read-only capacity of the key's account: storage used against its limit and add-on blocks, CDN usage and status, booster balances with the lot that expires first, the unpaid-account state, the period end, and a dashboard link.
That last one matters for agents. An assistant that can see remaining capacity can decline to start a batch instead of failing halfway through it. Nothing in the MCP server buys anything: storage blocks and boosters are bought in the dashboard only.
When folders are the right unit
Folders fit when your uploads already have a natural boundary: a client, a campaign, a section of the site, a dated import. The purge then matches the boundary, and you stop keeping a list of URLs next to the files.
They fit less well if you upload one image at a time with no grouping in mind, because a folder per file gives you nothing a URL purge did not already give you.
Our rule of thumb: pick the folder at the moment you know why the file exists, because that is when you still know what it belongs to.
What this post does not claim
No speed or compression numbers appear here. Everything above is a behaviour you can check with a few API calls: upload two files into two folders, purge one, and see that the other stays cached.
Details are in the Image Optimization Endpoint and MCP server docs.