Skip to navigation

Jobs & Errors

View as Markdown

Document AI jobs are asynchronous. You submit a job, wait for it to finish, then fetch the output. The same three steps apply to Digitise, Extract, Split, and Classify.

1

Submit

Call digitise(), extract(), split(), or classify(). One call creates and submits the job, and returns a job_id with an initial status.

2

Poll

Call get_status() with the job_id until the job reaches a terminal state.

3

Fetch

Call get_results() for structured data, or get_download_url() for the output file (Digitise and Extract only). See Fetch the output.

Job states

StateDescription
pendingJob created, queued for processing
runningJob is being processed
completedAll pages processed successfully
partially_completedSome pages succeeded, some failed
failedAll pages failed or a job-level error occurred
rejectedJob rejected before processing (e.g. validation or entitlement)

Split and Classify jobs report accepted when created and completed when finished. Their status includes type (split or classify), phase, and progress, and usage has pages_processed and pages_source.

Terminal states are completed, partially_completed, failed, and rejected.

Status response

{
"job_id": "019fb81e-2543-70bd-a737-b5a2d62a3bb7",
"status": "completed",
"pipeline": "digitise",
"usage": {
"pages_total": 1,
"pages_processed": 1,
"pages_succeeded": 1,
"pages_failed": 0
},
"created_at": "2026-07-31T12:20:11Z",
"updated_at": "2026-07-31T12:20:15Z"
}

Fetch the output

Each operation returns its output through a different call:

OperationFetch withYou get
Digitiseget_download_url()A link to a ZIP with the primary file, per-page metadata, and a manifest
Extractget_results()The field values you defined. get_download_url() returns the output file
Splitget_results()The child documents (segments)
Classifyget_results()The decision, or one per page

Calling either before the job reaches a terminal state returns 409.

What to do in each terminal state

StateWhat to do
completedFetch the output. For Split and Classify, also check review_required before accepting the result automatically
partially_completedFetch the output, then check usage.pages_failed to see how many pages are missing, and resubmit those pages if you need them
failedThere is no output to fetch. Check the error, fix the cause, and submit again
rejectedThe job never started processing, usually because of validation or entitlement. Fix the request or your plan access and submit again

Poll every few seconds (the examples use 5) and read usage in the status response to show progress on long documents.

Error Handling

import json, os
from sarvamai import SarvamAI
from sarvamai.core.api_error import ApiError
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
try:
with open("./insurance-policy.pdf", "rb") as f:
job = client.doc_ai.extract(
file=[("insurance-policy.pdf", f, "application/pdf")],
schema=json.dumps({
"type": "object",
"properties": {
"policy_number": {"type": "string", "description": "Insurance policy number"},
},
}),
output_format="json",
)
# ... poll get_status() until terminal ...
results = client.doc_ai.get_results(job_id=job.job_id)
print(results.result)
except ApiError as e:
if e.status_code == 400:
print(f"Bad request or invalid schema: {e.body}")
elif e.status_code in (402, 403):
print("Billing or entitlement error")
elif e.status_code == 409:
print("Results requested before the job reached a terminal state")
elif e.status_code == 413:
print("File too large")
elif e.status_code == 429:
print("Rate limit exceeded")
else:
print(f"Error {e.status_code}: {e.body}")
except FileNotFoundError:
print("Document file not found: ./insurance-policy.pdf")

Error Codes

The full error-code table, retry guidance, and SDK exception reference live on the central Errors & Troubleshooting page. Errors specific to this API:

HTTP StatusDescription
400Invalid request or schema (includes documents exceeding the page limit)
402 / 403Billing or entitlement error
404Resource unavailable (e.g. job not found)
409Results or download requested before the job reached a terminal state
413File too large
422Invalid file format or corrupted file. For Split and Classify, also an invalid page range or an option this deployment does not offer
429Rate or admission limit
503Billing unavailable