How to poll status and export results

View as Markdown

live-status reports one overall job_state plus a state per language in translations. Export is per language: call it once for each target language, only after that language’s own state is Completed.

EndpointPurpose
GET /translate/document/jobs/{job_id}/live-statusOverall progress + per-language state. Poll every 10-15 seconds.
POST /translate/document/jobs/{job_id}/export?lang={code}Enqueue an async export for one target language. Returns 202 Accepted with export_state=Pending. Exports in the uploaded file’s format by default.
GET /translate/document/jobs/{job_id}/export/statusPoll export status until export_state is Completed, then download from download_url.

live-status response shapes differ by file type, but the poll/export logic below works for both:

Upload typeProgress tracking
PDFPer page (page_metrics)
Word, spreadsheet, presentationPer segment (translation_metrics)

job_state, translations[].state, and translations[].target_language_code are present in both shapes. See Overview for full field lists.

Check each language’s own state, not only top-level job_state.

A job can stay Running or PartiallyCompleted while some languages in translations[] are already Completed and ready to export. Gate your export loop on translations[].state, not job_state alone.

format is optional. When omitted, the export uses the uploaded file’s native format. PDF uploads may optionally set format to pdf, docx, html, txt, or epub. Microsoft Office uploads always export in the original format only.

Example

Replace YOUR_SARVAM_API_KEY with your key from Key Management. This example assumes you already created a job, uploaded the file, and called start — see the Overview quickstart.

import os
import time
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
job_id = "550e8400-e29b-41d4-a716-446655440000"
TERMINAL = {"Completed", "PartiallyCompleted", "Failed"}
def poll_job(job_id):
while True:
status = client.document_translation.get_live_status(job_id=job_id)
print(f"job_state={status.job_state} progress={status.progress}%")
if status.job_state in TERMINAL:
return status
time.sleep(12)
def export_completed(job_id, translations):
urls = {}
for t in translations:
if t.state != "Completed":
continue
export = client.document_translation.trigger_export(
job_id=job_id,
lang=t.target_language_code,
)
while True:
status = client.document_translation.get_export_status(
job_id=job_id,
export_id=export.export_id,
)
if status.export_state == "Completed":
urls[t.target_language_code] = status.download_url
break
if status.export_state == "Failed":
print(f"Export failed for {t.target_language_code}")
break
time.sleep(5)
return urls
final = poll_job(job_id)
downloads = export_completed(job_id, final.translations or [])
print("Downloads:", downloads)

The sample above covers polling through export. See the Overview for the complete five-step flow including create, upload, and start.