API-37Recommended
Run long jobs asynchronously
When work can take longer than 10 seconds, accept it with 202 and a status resource the client can poll.
How to do it
Return 202 with a Location header pointing to a job, such as /jobs/job_31c. The job shows its state, such as queued, running, succeeded or failed. When done, it links to the result or holds a problem details object. Send Retry-After on the job to pace polling.
Examples
HTTP example
POST /exports HTTP/1.1
HTTP/1.1 202 Accepted
Location: /jobs/job_31c
Retry-After: 5
How to check
Start an export in a test. The answer is 202 with Location, and polling ends in a completed state with a result link.
Sources
Related rules
- API-91 Return a result for each item in a batch in API design
- AIF-45 Send work nobody waits for as a batch in AI features
- APP-45 Show progress for long actions in Web app interface
- SCL-39 Build large exports ahead of time in Scaling
- AGT-19 Run long work as tasks in Agents as users
- USG-20 Let customers download the usage behind each invoice in Usage-based billing
- DSK-17 Keep extension state in storage instead of the background worker in Desktop apps and extensions
- MED-23 Build documents in a background job in Files and media
- EVT-16 Move slow work out of the request in Integration and events
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/reliability/long-running-jobs">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.