> For clean Markdown of any page, append `.md` to the page URL. > For a complete documentation index, see https://docs.sarvam.ai/llms.txt. > For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server. # How to poll status and export results > Poll live-status for per-language translation progress, then trigger and poll an async export for each completed language's translated document from the Sarvam Document Translation API. `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`. | Endpoint | Purpose | | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | `GET /translate/document/jobs/{job_id}/live-status` | Overall 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/status` | Poll export status until `export_state` is `Completed`, then download from `download_url`. | > **Note** > > **`live-status` response shapes differ by file type**, but the poll/export logic below works for both: > > | Upload type | Progress tracking | > | ------------------------------- | ----------------------------------- | > | PDF | Per page (`page_metrics`) | > | Word, spreadsheet, presentation | Per segment (`translation_metrics`) | > > `job_state`, `translations[].state`, and `translations[].target_language_code` are present in both shapes. See [Overview](/api/api-guides-tutorials/doc-translation/overview#page-granular-vs-document-granular-responses) for full field lists. > **Warning** > > **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. > **Note** > > **`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 > **Note** > > Replace `YOUR_SARVAM_API_KEY` with your key from [Key Management](https://dashboard.sarvam.ai/key-management). This example assumes you already created a job, uploaded the file, and called `start`. See the [Overview quickstart](/api/api-guides-tutorials/doc-translation/overview#quickstart). #### Python ```python 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) ``` #### JavaScript ```javascript import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: process.env.SARVAM_API_KEY, }); const jobId = "550e8400-e29b-41d4-a716-446655440000"; const TERMINAL = new Set(["Completed", "PartiallyCompleted", "Failed"]); async function pollJob(jobId) { while (true) { const status = await client.documentTranslation.getLiveStatus(jobId); console.log(`job_state=${status.job_state} progress=${status.progress}%`); if (TERMINAL.has(status.job_state)) return status; await new Promise((r) => setTimeout(r, 12_000)); } } async function exportCompleted(jobId, translations) { const urls = {}; for (const t of translations) { if (t.state !== "Completed") continue; const exportJob = await client.documentTranslation.triggerExport(jobId, { lang: t.target_language_code, }); while (true) { const status = await client.documentTranslation.getExportStatus(jobId, { exportId: exportJob.export_id, }); if (status.export_state === "Completed") { urls[t.target_language_code] = status.download_url; break; } if (status.export_state === "Failed") { console.log(`Export failed for ${t.target_language_code}`); break; } await new Promise((r) => setTimeout(r, 5_000)); } } return urls; } const final = await pollJob(jobId); const downloads = await exportCompleted(jobId, final.translations ?? []); console.log("Downloads:", downloads); ``` The sample above covers polling through export. See the [Overview](/api/api-guides-tutorials/doc-translation/overview#how-it-works) for the complete five-step flow including create, upload, and start. ## Related * [Document Translation Overview](/api/api-guides-tutorials/doc-translation/overview) * [Set Style Guidelines](/api/api-guides-tutorials/doc-translation/how-to/style-guidelines) > Poll live-status for per-language translation progress, then trigger and poll an async export for each completed language's translated document from the Sarvam Document Translation API.