REST API Quickstart

Run your first document translation task in 5 minutes

Create an asynchronous PDF or Office translation task, poll its status, and download the result. The examples below match the current public API response fields.

Base URL
https://www.fanyipaiban.com/translate/openapi/v1
Authentication
Bearer API key
Formats
PDF, DOCX, PPTX, XLSX
Billing
1,500 credits / billable page
Updated
Workflow

One task ID connects the whole process

Creation returns HTTP 202. Save data.id, then use it for polling and every result download.

01Create and secure an API key

Create a dedicated key in the Developer Center and store it in an environment variable or secret manager.

02Upload a document and create a task

Send a PDF or Office file as multipart form data with a target language and a unique Idempotency-Key.

03Poll the task status

Read the task every two to five seconds until its status becomes SUCCESS or FAILED.

04Download the translated result

After SUCCESS, call the download path with the same API key and save the returned document.

Using Codex? Read the MCP guide For documents already in a Codex workspace, use the Node.js stdio bridge and the four production MCP tools. Files over 20 MB should use the REST API instead. Open the Codex MCP guide
Step 1

Create and secure an API key

Create a dedicated key in the Developer Center. The full secret is displayed only once.

  • Store the key in an environment variable or secret manager, never in frontend JavaScript or a public repository.
  • Choose a representative test file. For scans, tables, images, or dense formatting, start with a small but difficult sample.
  • Generate one Idempotency-Key per business operation. Reuse it when a network timeout leaves the outcome unknown; after an explicit pre-task failure, fix the cause and use a new key. The maximum length is 128 characters.
PowerShellWindows PowerShell: set the key with $env:FYPB_API_KEY = "your_api_key" and use curl.exe.
Step 2

Upload a PDF and create the task

Send multipart form data with the file, source language, and target language. This example translates a PDF to Chinese.

Bash / Create PDF task
export FYPB_API_KEY="your_api_key"

curl -X POST \
  'https://www.fanyipaiban.com/translate/openapi/v1/pdf/tasks' \
  -H "Authorization: Bearer ${FYPB_API_KEY}" \
  -H 'Idempotency-Key: quickstart-pdf-001' \
  -F 'file=@./manual.pdf' \
  -F 'source_lang=auto' \
  -F 'target_lang=cn'

Read the task ID from data.id

The response is wrapped in success, requestId, and data. Do not look for task_id; the current public field is data.id.

HTTP 202 / Example response
{
  "success": true,
  "requestId": "api-request-id",
  "data": {
    "id": "document-task-id",
    "type": "PDF",
    "billingUnit": "PER_PAGE",
    "status": "QUEUED",
    "progress": 0,
    "billablePageCount": 12,
    "pageTokenPrice": 1500,
    "estimatedToken": 18000,
    "chargedToken": null,
    "downloadPath": "/openapi/v1/tasks/document-task-id/download",
    "markdownDownloadPath": "/openapi/v1/tasks/document-task-id/download-markdown",
    "comparisonDownloadPath": "/openapi/v1/tasks/document-task-id/download-comparison"
  }
}
Step 3

Poll until SUCCESS or FAILED

Query the task every 2 to 5 seconds. QUEUED and RUNNING mean processing is still active; SUCCESS and FAILED are terminal states.

Bash / Read task
TASK_ID="document-task-id"

curl \
  "https://www.fanyipaiban.com/translate/openapi/v1/tasks/${TASK_ID}" \
  -H "Authorization: Bearer ${FYPB_API_KEY}"
ResponseThe status response also exposes progress, billablePageCount, pageTokenPrice, estimatedToken, chargedToken, and the available download paths.
Step 4

Download the result after SUCCESS

The main download endpoint returns the translated PDF or editable Office file. Calling it before SUCCESS returns 409 RESULT_NOT_READY.

Bash / Download result
curl -L \
  "https://www.fanyipaiban.com/translate/openapi/v1/tasks/${TASK_ID}/download" \
  -H "Authorization: Bearer ${FYPB_API_KEY}" \
  -o translated-result.pdf

A successful PDF task can expose three artifacts

Translated PDF/tasks/{id}/downloadThe primary translated and typeset result.
Translated Markdown/tasks/{id}/download-markdownPDF only. Useful for retrieval, a knowledge base, or downstream processing.
Comparison PDF/tasks/{id}/download-comparisonPDF only. Combines source and translation for review.
Office

Use the same flow for DOCX, PPTX, and XLSX

Only the creation endpoint changes. Polling and downloading continue to use the same task endpoints.

Bash / Create Office task
curl -X POST \
  'https://www.fanyipaiban.com/translate/openapi/v1/office/tasks' \
  -H "Authorization: Bearer ${FYPB_API_KEY}" \
  -H 'Idempotency-Key: quickstart-office-001' \
  -F 'file=@./product-spec.xlsx' \
  -F 'source_lang=auto' \
  -F 'target_lang=cn'
ReviewReview formulas, cross-sheet references, tables, and slide layout before using translated Office files as final business data.
Reliability

Handle retries by error code, not by guesswork

Keep the requestId from error responses. It helps reconcile API logs with a failed integration attempt.

HTTPTypical codeWhat to do
400MISSING_IDEMPOTENCY_KEY / INVALID_IDEMPOTENCY_KEY / MISSING_TARGET_LANGUAGEAdd or correct the required header or form field, then create a new request.
401MISSING_API_KEY / INVALID_API_KEYCheck the Authorization header, Bearer token, and whether the key is active.
402INSUFFICIENT_CREDITSRecharge the shared balance, then create a new request with a new Idempotency-Key.
409IDEMPOTENCY_KEY_IN_PROGRESSWait briefly, then retry the same create request with the same Idempotency-Key.
409IDEMPOTENCY_KEY_REUSEDThe earlier request failed before creating a task. Fix the cause, then use a new Idempotency-Key.
409RESULT_NOT_READYKeep polling the existing task and download only after status becomes SUCCESS.
503PARSER_UNAVAILABLERetry later with a new Idempotency-Key because the earlier request returned an explicit failure.
Credits

Know what counts as a billable page

PDF and Office translation currently use page-based billing at 1,500 credits per billable page. The API and web workspace share one balance.

PDFPhysical page
PPTXSlide
DOCXEmbedded page count; one-page fallback when unavailable
XLSXWorksheet

View current pricing

FAQ

Questions to settle before production use

Why is Idempotency-Key required?

An upload can time out after the server has already started creating a task. Reuse the same key when the outcome is unknown to prevent duplicate tasks and credit reservations. If the API explicitly reports a pre-task failure, fix the cause and use a new key.

Can I call the API directly from browser JavaScript?

Do not expose an API key in frontend code. Store the key on your server and call the document translation API from a backend service, worker, or controlled automation environment.

Should I batch-submit scanned PDFs immediately?

Test a representative sample first, especially a page with tables, images, headers, or dense formatting. Recognition quality and layout complexity affect the review and delivery workflow.

Does the API use a separate credits balance?

No. The API, MCP integration, and web workspace use the same credits balance, so you can test a file in the workspace before automating the confirmed workflow.

Start with one representative document

Run upload, polling, and download end to end. Review the result and chargedToken before connecting a batch or production workflow.

Run the full workflow with a real document

Upload a PDF, Word, Excel, or PPT file to check translation, layout retention, bilingual review, and export quality.

滚动至顶部