Documentation Index
Fetch the complete documentation index at: https://docs.retab.com/llms.txt
Use this file to discover all available pages before exploring further.
from retab import Retab
client = Retab()
# Cancel a queued or in-progress job
cancelled_job = client.jobs.cancel("job_V1StGXR8_Z5jdHi6B-myT")
print(f"Status: {cancelled_job.status}") # cancelled
{
"id": "job_V1StGXR8_Z5jdHi6B-myT",
"object": "job",
"status": "cancelled",
"endpoint": "/v1/extractions",
"request": {
"document": {
"filename": "invoice.pdf",
"url": "data:application/pdf;base64,..."
},
"json_schema": { ... },
"model": "retab-small"
},
"response": null,
"error": null,
"created_at": 1705420800,
"started_at": null,
"completed_at": 1705420850,
"expires_at": 1706025600,
"organization_id": "org_abc123",
"metadata": {"batch_id": "batch_001"}
}
Path Parameters
The unique identifier of the job to cancel.
Response Fields
Unique identifier for the job.
Will be "cancelled" on success.
The target endpoint for this job.
The original request body submitted.
Always null for cancelled jobs.
Always null for cancelled jobs.
Unix timestamp when the job was created.
Unix timestamp when processing started (if it had started).
Unix timestamp when the job was cancelled.
Unix timestamp when the job data will expire.
The organization that owns this job.
User-provided metadata from job creation.
Cancellation Behavior
The cancellation behavior depends on the job’s current status:
| Current Status | Behavior |
|---|
validating | Immediately cancelled |
queued | Removed from queue and cancelled |
in_progress | Marked for cancellation; processing may complete if already finishing |
completed | Returns 400 error - cannot cancel |
failed | Returns 400 error - cannot cancel |
cancelled | Returns 400 error - already cancelled |
expired | Returns 400 error - cannot cancel |
Jobs that are in_progress may still complete if the cancellation request arrives after processing has finished but before the status is updated. Always check the final status of the returned job object.
If cancellation races with a concurrent state transition, Retab may return 409. In that case, retrieve the job again and decide whether another cancel attempt is still needed.
Use Cases
Cancel a Batch of Jobs
# Cancel all queued jobs from a specific batch
jobs = client.jobs.list(status="queued")
for job in jobs.data:
if job.metadata and job.metadata.get("batch_id") == "batch_001":
try:
client.jobs.cancel(job.id)
print(f"Cancelled {job.id}")
except Exception as e:
print(f"Failed to cancel {job.id}: {e}")
Timeout-based Cancellation
import time
job = client.jobs.create(endpoint="/v1/extractions", request={...})
start_time = time.time()
timeout = 60 # 60 seconds
while job.status not in ("completed", "failed", "cancelled", "expired"):
if time.time() - start_time > timeout:
job = client.jobs.cancel(job.id)
print("Job cancelled due to timeout")
break
time.sleep(2)
job = client.jobs.retrieve(job.id)
Core Job object following OpenAI-style specification.
Represents a single asynchronous job that can be polled for status
and result retrieval.
Available options:
/v1/extractions,
/v1/parses,
/v1/splits,
/v1/partitions,
/v1/classifications,
/v1/schemas/generate,
/v1/edits,
/v1/edits/templates/fill,
/v1/edits/templates/generate,
/v1/evals/extract/process,
/v1/evals/extract/extract,
/v1/evals/extract/split
status
enum<string>
default:validating
Available options:
validating,
queued,
in_progress,
completed,
failed,
cancelled,
expired
Error details when job fails.
warnings
JobWarning · object[] | null
Response stored when job completes successfully.