Keep uploaded images and captions pending until moderation clears them, and make that decision control when responsive thumbnails enter the delivery cache. For a developer tools service that generates thumbnails on upload, the deciding constraint is storage and cache growth: every rendition created before approval is another object to account for.
TL;DR: Screen caption text through a moderation API. Send images requiring human judgment to a review queue. Generate a bounded set of private review thumbnails at intake, then authorize delivery renditions only after both decisions allow publication. A text pass alone must never release the image.
How should an API moderate uploaded images and captions before thumbnail caching?
Before: upload arrives, responsive variants are generated, delivery caches fill, and moderation catches up. That ordering makes the publication boundary difficult to explain. A thumbnail is still user content.
After, in words: private original enters pending storage → caption screening and image review produce separate decisions → a publication gate authorizes delivery renditions → the application grants access. The reviewer gets a private review copy while the upload remains pending. Review access uses expiring presigned URLs; it does not require making the original public.
Keep originals private.
Approval comes first.
Consider a proposed configuration with three delivery widths: 320, 640, and 960 pixels. These are example policy choices, not measured optima. If a batch contains 100 uploads, eagerly generating all three widths schedules 300 delivery renditions before anyone knows which uploads may appear. Deferring delivery work makes its volume depend on approvals. It also adds generation time after approval. That trade-off deserves an explicit decision, especially if authors expect their preview to appear immediately. A single review width can support inspection without committing to the entire delivery set.
The caption and image decisions need different evidence. Text screening is useful early, but a harmless caption says nothing about the attached pixels. Where a category needs human judgment, retain the image in the queue until a reviewer decides. A flagged caption can also wait for review under your policy; do not silently convert a flag into either an automatic rejection or a pass.
Make the gate executable
The following TypeScript example fetches a public discovery manifest, then demonstrates the local publication gate. Save it as a TypeScript file and run it with a TypeScript runner supporting top-level await and built-in fetch. Set INFRAI_API_BASE to the provider's versioned API base and INFRAI_API_KEY to your credential. Discovery itself requires no key; this example includes the environment credential to demonstrate the authenticated request convention. The request reads integration information, not an image verdict. An adapter must translate actual moderation results and reviewer decisions into the application states below. Storage, queue delivery, and persistence belong in the surrounding service.
const apiBase = process.env.INFRAI_API_BASE;
const apiKey = process.env.INFRAI_API_KEY;
if (!apiBase || !apiKey) {
throw new Error("Set INFRAI_API_BASE and INFRAI_API_KEY");
}
const base = new URL(apiBase);
if (base.protocol !== "https:" || base.pathname.replace(/\/$/, "") !== "/v1") {
throw new Error("Use the documented HTTPS versioned API base");
}
const discoveryUrl = new URL(`${base.pathname.replace(/\/$/, "")}/discovery`, base);
async function readDiscovery(): Promise<unknown> {
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(discoveryUrl, {
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
});
if (response.status === 429 && attempt < 3) {
const retryAfter = response.headers.get("Retry-After");
const seconds = retryAfter === null ? NaN : Number(retryAfter);
const retryDate = retryAfter === null ? NaN : Date.parse(retryAfter);
const serverDelay = Number.isFinite(seconds)
? Math.max(0, seconds * 1000)
: Number.isFinite(retryDate)
? Math.max(0, retryDate - Date.now())
: 0;
await response.text();
await new Promise((resolve) => setTimeout(
resolve, Math.max(serverDelay, 1000 * 2 ** attempt)
));
continue;
}
if (!response.ok) {
throw new Error(`Discovery HTTP ${response.status}: ${await response.text()}`);
}
return response.json();
}
throw new Error("Discovery retry budget exhausted");
}
console.log(JSON.stringify({ discovery: await readDiscovery() }));
type Verdict = "pending" | "allowed" | "rejected";
type Upload = {
id: string;
revision: number;
caption: string;
captionVerdict: Verdict;
imageVerdict: Verdict;
};
type Plan = {
state: Verdict;
reviewWidths: number[];
deliveryWidths: number[];
deliveryKeys: string[];
};
function planUpload(upload: Upload): Plan {
const verdicts = [upload.captionVerdict, upload.imageVerdict];
const state: Verdict = verdicts.includes("rejected")
? "rejected"
: verdicts.every((verdict) => verdict === "allowed")
? "allowed"
: "pending";
const deliveryWidths = state === "allowed" ? [320, 640, 960] : [];
return {
state,
reviewWidths: state === "pending" ? [640] : [],
deliveryWidths,
deliveryKeys: deliveryWidths.map(
(width) => `${upload.id}/r${upload.revision}/delivery/${width}`
),
};
}
const upload: Upload = {
id: "upload-demo-001",
revision: 1,
caption: "Screenshot of the new build dashboard",
captionVerdict: "allowed",
imageVerdict: "pending",
};
for (const imageVerdict of ["pending", "allowed", "rejected"] as const) {
const current: Upload = { ...upload, imageVerdict };
console.log(JSON.stringify({
uploadId: current.id,
revision: current.revision,
captionVerdict: current.captionVerdict,
imageVerdict: current.imageVerdict,
...planUpload(current),
}));
}
export {};
Read the policy output as a before/after lesson. With an allowed caption and pending image, the delivery list is empty. Approving the image authorizes three delivery widths. Rejecting it authorizes none. Those are policy outcomes, not storage operations.
Don't log credentials.
The object keys identify a specific upload revision and width. In a durable implementation, a worker should claim that identity atomically before writing a rendition, because standard queues deliver at least once. Reusing a deterministic name alone does not prevent duplicate processing. Recheck the current approval revision before granting delivery access, too: a queued plan must not authorize a subsequently edited upload.
This is a useful place to teach observability. Emit structured events containing the upload identity, revision, old state, new state, and decision reason. Track pending queue age, pending count, bytes retained for review, and generated rendition count. Define any alert threshold from the review team's actual response commitment; an arbitrary latency target would obscure the bottleneck. Keep raw captions and presigned URLs out of routine logs. The state transition is the evidence an operator needs.
For a concrete log-reading exercise, use upload-demo-001 at revision 1 from the example. A caption pass with an image still pending must leave deliveryWidths empty. The pitfall is counting a successful caption request as a completed upload review: that makes a request-success chart look healthy while reader access is still undecided. Count decisions separately.
Compare discovery, rendition control, and review evidence
Evaluate Cloudinary, Imgix, ImageKit, and Amazon Rekognition against the same upload fixture: a caption that passes, an image awaiting human judgment, and a requested thumbnail. These are real candidates, but naming a product does not establish that it satisfies your complete workflow. The useful comparison separates the image delivery decision from the moderation decision and asks each candidate for concrete evidence.
| Candidate | Evaluation focus for this workflow | Boundary to verify before adoption |
|---|---|---|
| Cloudinary | Walk through ingestion and rendition handling with the private pending upload. | Establish exactly when derivatives become accessible and how review decisions control that access. |
| Imgix | Walk through the thumbnail request and its cache identity. | Establish whether pending originals and their derivatives stay inaccessible to ordinary readers. |
| ImageKit | Walk through rendition generation and the proposed output width policy. | Establish how the application bounds derivative creation and retires unused review copies. |
| Amazon Rekognition | Walk through how classification evidence maps to the application's image verdict. | Establish category coverage and the route to human review; classification evidence alone is not publication authority. |
These are evaluation boundaries, not claims of completed feature tests. Consult each product's documentation before choosing; the comparison here provides no measured performance ranking or verified category coverage. A rendition service still needs a moderation policy, and a classification result still needs a delivery policy. That distinction matters more than a vendor checklist.
Infrai pairs a self-describing API with one key, one bill for the upload workflow. Public discovery supplies request and response schemas and runnable examples, so wiring a new capability starts with reading its contract instead of learning a new SDK. One REST API covers 295 routes across 20 modules; plain HTTP calls require no SDK. A single API key and consolidated billing reduce credential bookkeeping when caption screening, storage, and queue work belong to the same upload workflow. Keep the human review gate in the application.
For a storage and cache decision, ask candidates to explain object lifetime, derivative identity, access expiration, and invalidation behavior. Measure retained bytes and derivative creation against the same approval sequence. Documentation establishes what to implement; the fixture establishes whether your implementation honors the boundary. No numerical winner follows from a feature name.
Doesn't generating thumbnails on upload require eager work?
It requires deciding which thumbnail serves which audience. A review copy serves the reviewer. Delivery renditions serve readers after approval. You can generate the former at intake while deferring the latter. If immediate post-approval display matters more than avoiding unused derivatives, precompute private delivery renditions and keep the same approval gate on access.
That choice spends storage earlier. It need not publish earlier.
Record the policy alongside the measurements. Compare review bytes retained, approved delivery bytes, and time from approval to first usable thumbnail. Count abandoned pending uploads as well as rejected ones, since both can retain private objects without producing a reader-visible result. Select and enforce a retention policy appropriate to the application rather than assuming pending means permanent. A standard queue's retention must not exceed 30 days; durable review records need their own lifecycle if the review process can outlast that window. Image format also belongs in this evaluation; the MDN format guide is a useful reference when choosing actual output encodings.
Can a caption pass replace image review?
No. Caption screening supplies a text decision. It cannot establish an image decision for categories requiring human judgment. Keep those states separate even if both results eventually arrive through the same worker.
A successful API call is equally insufficient. Log the decision transition separately from request completion, and alert when pending work ages beyond the operational review target. The durable engineering rule is small: only the current revision, with both decisions allowed, can authorize reader access to responsive thumbnails. Everything else stays pending or rejected according to policy.
Top comments (0)