API reference
Jobs API
Authenticated endpoints for uploads, URL imports, live job tracking, review, team workspaces, and sharing, plus the worker heartbeat interface.
Workflow
Create an upload intent, send the file to the returned upload URL, and complete the intent (or import a public URL), then subscribe to live SSE updates or poll the job. A worker claims queued work, processes it, and reports stage progress. User routes use the signed-in browser session; only worker and operations routes use service bearer tokens.
| Method | Path | Purpose |
|---|---|---|
| POST | /api/uploads | Create a direct-upload intent for supported media. |
| POST | /api/uploads/multipart | Initialize a resumable chunked/multipart upload session for large media. |
| PUT | /api/uploads/[id]/chunks/[partNumber] | Upload a single numbered chunk for an active resumable multipart upload. |
| GET | /api/uploads/[id]/status | Inspect uploaded chunk parts and byte progress to resume a transfer. |
| PUT | signed object URL | Upload bytes directly to configured object storage. |
| POST | /api/uploads/[id]/complete | Verify and finalize the object, creating a queued job. |
| POST | /api/uploads/batch/complete | Commit 2-10 uploaded images as one ordered image-set job. |
| POST | /api/imports/url | Validate and enqueue a job from a public HTTP(S) media URL. |
| GET | /api/jobs | List accessible personal or team jobs, newest first (filter via q, status, workspaceId, sourceKind). |
| GET | /api/jobs/[id] | Read a job's current state and stage progress. |
| PATCH | /api/jobs/[id] | Rename a job's display name (owner or team OWNER/ADMIN). |
| GET | /api/jobs/[id]/events | Stream live job status and progress updates over SSE. |
| POST | /api/jobs/[id]/retry | Retry an incomplete or transiently failed job. |
| POST | /api/jobs/[id]/rerun | Clone stored source media into a new queued job at a chosen detail level. |
| DELETE | /api/jobs/[id] | Delete a job owned or administered by the current user. Returns 204 on success. |
| GET | /api/jobs/[id]/export?format=markdown | Download the Markdown result for an accessible job. |
| GET | /api/jobs/[id]/export?format=json | Download the structured JSON result for an accessible job. |
| GET | /api/jobs/[id]/source?asset=0&download=1 | Stream an authenticated inline preview or download the original source file. |
| PATCH | /api/jobs/[id]/evidence/[evidenceId] | Confirm or flag an evidence claim and save review notes. |
| GET / POST / DELETE | /api/jobs/[id]/share | Inspect, create, rotate, or revoke an expiring read-only public share link. |
| GET / POST | /api/workspaces | List team workspaces or create a new team workspace. |
| PATCH / DELETE | /api/workspaces/[id] | Rename a team workspace (owners/admins) or delete it (owner only). |
| GET / POST | /api/workspaces/[id]/members | List team members or add an existing OpenContext user as ADMIN, MEMBER, or VIEWER. |
| PATCH / DELETE | /api/workspaces/[id]/members/[userId] | Change a teammate's role or remove a member / leave a team. |
| GET / POST | /api/workspaces/[id]/invites | List pending invitations or create an expiring single-use email invite link. |
| GET / POST | /api/workspaces/[id]/roles | List or create custom workspace permission roles. |
| PATCH / DELETE | /api/workspaces/[id]/roles/[roleId] | Update or delete a custom workspace role. |
| GET / POST | /api/workspaces/[id]/scim-tokens | List or issue OWNER-scoped SCIM 2.0 provisioning bearer tokens. |
| DELETE | /api/workspaces/[id]/scim-tokens/[tokenId] | Revoke an active SCIM 2.0 provisioning bearer token. |
| GET / POST / PATCH / DELETE | /api/scim/v2/Users & /Groups | SCIM 2.0 directory sync endpoints authenticated via workspace SCIM bearer token. |
| DELETE | /api/workspaces/[id]/invites/[inviteId] | Revoke a pending team invitation. |
| GET / POST | /api/invites/[token] | Inspect an invitation or accept it for the signed-in verified email. |
| GET | /api/usage | Read completed analysis usage counts, duration, and recorded costs (workspaceId, days). |
| POST | /api/worker/heartbeat | Internal worker-token heartbeat for idle worker health (204). |
Read a job
Call these endpoints from a signed-in browser session and include cookies with each request as shown below.
fetch("/api/jobs/job_123", { credentials: "include" })
.then(async (response) => {
if (!response.ok) throw new Error(`Job request failed: ${response.status}`);
const job = await response.json();
console.log(job.status); // QUEUED, processing stages, COMPLETED, PARTIAL, or FAILED
console.log(job.progress); // 0-100
console.log(job.stageStates); // each stage's status, attempt, progress, and errors
});JobDetail also includes errorStage, failureKind, retryAllowed, canManage, source metadata, and retentionNote. Subscribe to GET /api/jobs/[id]/events (or poll every three seconds) and stop when status is COMPLETED, PARTIAL, or FAILED. The list endpoint returns the smaller JobSummary shape.
Create an upload
Declare the filename, byte size, optional MIME type, and detail level. Use the returned URL, method, and headers for the transfer, then complete the intent. A single intent expires after 15 minutes.
const response = await fetch("/api/uploads", {
method: "POST",
headers: { "Content-Type": "application/json" },
credentials: "include",
body: JSON.stringify({
filename: "walkthrough.mp4",
mime: file.type,
sizeBytes: file.size,
detailLevel: "MEDIUM",
}),
});
if (!response.ok) throw new Error(`Upload intent failed: ${response.status}`);
const intent = await response.json(); // uploadId, method, url, headers, expiresAtawait fetch(intent.url, {
method: intent.method,
headers: intent.headers,
body: file,
});
const queued = await fetch(`/api/uploads/${intent.uploadId}/complete`, {
method: "POST",
credentials: "include",
});
if (!queued.ok) throw new Error(`Upload completion failed: ${queued.status}`);
const job = await queued.json();On success, the complete route returns 201 and a JobSummary; the job is now QUEUED. Supported inputs and limits are listed in Uploading media.
Create an ordered image set
Create and transfer one intent for every image, preserving the intended order. Then commit all intents together. A set contains 2 to 10 images and creates one job.
const response = await fetch("/api/uploads/batch/complete", {
method: "POST",
headers: { "Content-Type": "application/json" },
credentials: "include",
body: JSON.stringify({
uploadIds: orderedUploadIds, // IDs from POST /api/uploads, in image order
detailLevel: "MEDIUM",
}),
});
if (!response.ok) throw new Error(`Image set failed: ${response.status}`);
const job = await response.json(); // JobSummary with one job IDIf one member is invalid, missing, or expired, the batch fails without creating a partial job. Use DELETE /api/uploads/[id] to cancel an unfinished or failed intent; a successful cancel returns 204.
Manage a job and its results
Retry keeps the same job and reuses stages that already succeeded. A retry returns the updated JobDetail. Deletion is permanent after confirmation and has no response body:
const retried = await fetch("/api/jobs/job_123/retry", {
method: "POST",
credentials: "include",
});
const deleted = await fetch("/api/jobs/job_123", {
method: "DELETE",
credentials: "include",
});
if (deleted.status !== 204) throw new Error(`Delete failed: ${deleted.status}`);const updated = await fetch("/api/jobs/job_123/evidence/8", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
credentials: "include",
body: JSON.stringify({
status: "FLAGGED",
note: "The second button is disabled.",
correctedText: "The secondary button is disabled.",
}),
});
if (!updated.ok) throw new Error(`Review failed: ${updated.status}`);
const { markdown, json } = await updated.json();Review status is CONFIRMED, FLAGGED, or UNREVIEWED. A correction, and a note, can be up to 5,000 and 1,000 characters respectively. A suggested correction is allowed only on a flagged claim. Clearing a review requires UNREVIEWED with no note or correction.
Image, PDF, and audio previews are available from GET /api/jobs/[id]/source. Use the zero-based asset query parameter to select an image in a set or a PDF page. Authenticated video playback uses a direct source URL instead of this preview route, while public share snapshots serve read-only source media through GET /share/[token]/source.
Errors
Failures use a stable envelope. The full catalog lists every public code and HTTP status.
{
"error": {
"code": "FORBIDDEN",
"message": "You don't have access to this job"
}
}Worker heartbeat
The worker process uses its own internal API with Authorization: Bearer <WORKER_API_TOKEN>. The idle heartbeat does not accept a user session:
const heartbeat = await fetch("/api/worker/heartbeat", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.WORKER_API_TOKEN}`,
},
body: JSON.stringify({ workerId: "oc-worker-prod-1" }),
});
if (heartbeat.status !== 204) {
throw new Error(`Worker heartbeat rejected: ${heartbeat.status}`);
}