Batch Image API: Job Status & Output Retention
In this article
For a batch image API, the correct job status and output retention settings depend on your workflow: use an asynchronous job model with statuses like pending, processing, completed, and failed, and set output retention to 24–72 hours for most use cases, with a maximum of 7 days. These settings balance reliability, cost, and compliance, ensuring you can poll for results without overpaying for storage or violating data privacy policies.
Why Batch Image APIs Need Job Statuses
Batch image processing—resizing thousands of photos, applying filters, or running OCR—takes time. A single HTTP request that waits for all images to finish would time out or tie up connections. Instead, APIs use an asynchronous pattern: you submit a job, get a job ID, and poll for status updates. This decouples the client from the heavy processing and allows the server to queue work efficiently.
Common statuses you'll encounter include:
- pending – the job is queued but not yet started.
- processing – the server is actively working on the images.
- completed – all images processed successfully; outputs are ready for download.
- failed – an error occurred; check the error details for partial results.
- canceled – the client requested cancellation before completion.
Some APIs add partial or warning statuses when some images fail but others succeed. Always check the API documentation for the exact status names and transitions.
How Output Retention Works
Output retention is the duration the API stores your processed images after the job completes. After that period, the files are deleted, and any download URLs become invalid. Retention is measured from the moment the job finishes, not from submission. Typical values range from 15 minutes to 7 days, with 24 hours being a common default.
The retention period serves two purposes: it gives you time to download results, and it limits the API provider's storage costs and legal liability. For sensitive images, shorter retention reduces exposure if a breach occurs. For large batches, longer retention lets you schedule downloads during off-peak hours.
Choosing the Right Status Polling Interval
Polling too frequently wastes API calls and may trigger rate limits. Polling too rarely delays your pipeline. A good strategy is exponential backoff: start at 1 second, double each time, and cap at 30 seconds. For example:
- Wait 1 second, then check status.
- If still processing, wait 2 seconds.
- Then 4, 8, 16, and 30 seconds thereafter.
Most batch jobs complete within minutes. If your job runs longer than an hour, consider using webhooks instead of polling. Webhooks push a notification to your server when the job completes, eliminating wasted polls entirely. Many APIs support both; choose webhooks for long-running or high-volume jobs.
Setting Retention for Different Use Cases
There is no one-size-fits-all retention setting. Match it to your workflow:
- Real-time processing (e.g., profile photo uploads): 15–60 minutes. Download immediately and delete.
- Standard batch (e.g., e-commerce product images): 24–72 hours. Gives you a day to download and re-process if needed.
- Compliance-sensitive (e.g., medical or legal documents): 1 hour or less. Minimize exposure; use direct-to-S3 transfer if available.
- Long-term archiving (e.g., media libraries): 7 days max. But consider having the API write directly to your own cloud storage instead.
If the API offers a retention parameter per job, override the default for each batch. For example, set 1 hour for a quick thumbnail generation, and 72 hours for a large dataset that you'll process in stages.
Common Problems and How to Avoid Them
Three issues trip up developers:
- Expired URLs mid-download: If you download after retention expires, you get a 404. Solution: start downloads immediately after completion, and re-run the job if you miss the window.
- Rate limiting from aggressive polling: Providers limit requests per second. Solution: use exponential backoff or webhooks.
- Data privacy violations: Storing images longer than necessary may breach GDPR or HIPAA. Solution: set the shortest retention that still allows your workflow, and document your choice.
Also, check if the API deletes inputs automatically. Some providers keep source images for a separate period. If you upload sensitive data, verify the input retention policy too.
Cost and Storage Implications
Longer retention increases provider costs, which they may pass to you. Some APIs charge per GB-hour for stored outputs. A 100 MB job retained for 7 days costs roughly 16.8 GB-hours (100 MB × 168 hours). At $0.01 per GB-hour, that's $0.17 per job—negligible for small batches but significant for terabytes. Review the pricing page and calculate your expected storage.
To minimize costs, download results and delete the job immediately if the API supports deletion. Some providers offer a delete endpoint that frees storage before the retention period ends. Use it in a finally block after successful download.
Alternatives to Built-in Retention
If the API's retention limits are too short or too long, consider these alternatives:
- Direct-to-cloud output: Many APIs let you specify an S3 bucket or Azure Blob Storage destination. The processed images are written there, and the API never stores them. This gives you full control over lifecycle policies.
- Self-hosted processing: For high volumes, run your own image pipeline using open-source tools like ImageMagick or Sharp. You control everything, but you handle scaling and maintenance.
- Hybrid approach: Use the API for complex tasks (e.g., AI-based upscaling) but download results immediately and store them in your own infrastructure.
Each option trades off convenience for control. For most teams, the API's built-in retention with a 24-hour setting is a safe default.
Frequently Asked Questions
What happens if I don't download before the retention expires?
The output files are permanently deleted, and the download URLs return 404. You cannot recover them. You must resubmit the job, which may incur new processing costs. To avoid this, set up an automated download script that runs immediately after the job completes.
Can I extend the retention period after a job completes?
Some APIs allow you to extend retention with a PATCH /jobs/{id} call that updates the retention field. Others do not, because storage is allocated at job creation. Check the API reference. If extension is not supported, you must re-run the job with a longer retention setting.
Is it better to poll or use webhooks for status updates?
Webhooks are more efficient for long-running jobs because they push the completion event to your server, eliminating wasted polls. Polling is simpler to implement and works fine for jobs that finish in under a minute. Use webhooks if the API supports them and your job runs longer than 5 minutes.
How do I know if a job failed partially?
Some APIs return a failed status with an error object listing which images failed and why. Others use a partial status. Always inspect the job's results array for per-image statuses. Implement retry logic for failed images.
Does retention time affect the input images I uploaded?
No, input retention is usually separate. Providers may keep source images for a different period (often 24 hours) to allow reprocessing. Read the privacy policy to confirm. If you upload sensitive data, ask the provider about input deletion guarantees.