Skip to content
VibeQL
Blog

Document translation API: how it works, with code

How a document translation API uploads, polls and downloads a file, with curl, Python and Node examples, the three ways APIs bill documents, and how to handle errors.

· 7 min read

A document translation API takes a whole file, such as a DOCX, PPTX or PDF, and returns the same file in another language with the layout kept. Most of these APIs work in three steps: you upload the file, you check the status until the translation is done, and you download the result. VibeQL uses the same three requests as the DeepL API, so the official DeepL client libraries work with it.

This post shows each step with code, explains the three ways that providers bill documents, and lists the errors your code must handle.

Why is document translation asynchronous?

A text request translates a few sentences and answers in one response. A document can have hundreds of pages. Translating it takes from seconds to minutes, which is too long for one HTTP request.

So the API splits the work. The upload returns at once with an ID. The translation runs in the background. Your code asks for the status from time to time, and downloads the file when it is ready.

Step 1: upload the file

Send the file as a multipart form to POST /v2/document, with the target language.

curl https://vibeql.com/v2/document \
  -H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
  -F "file=@annual-report.pdf" \
  -F "target_lang=PT-BR"
{
  "document_id": "6DCB64C24BB8F7489283D26C42ABDB80",
  "document_key": "D097D7505E5240652F0B5BE2663A212EAA3D79F5C0013AB6051288601405CDED"
}

Keep both values. The document_key proves that the document is yours, and every later request needs it. Leave out source_lang and VibeQL detects the language from the text. The file extension sets the format: .docx, .pptx, .pdf or .txt. The languages page lists the codes.

Step 2: check the status

Send the document_key to POST /v2/document/{document_id}.

curl https://vibeql.com/v2/document/6DCB64C24BB8F7489283D26C42ABDB80 \
  -H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
  -d "document_key=D097D7505E5240652F0B5BE2663A212EAA3D79F5C0013AB6051288601405CDED"

The status field has one of four values:

status Meaning Extra fields
queued The file waits for a translation worker. –
translating The translation runs. seconds_remaining, an estimate
done The translated file is ready. billed_characters
error The translation failed. error_message

Poll every few seconds until the status is done or error. Wait longer between polls for large files.

Step 3: download the result

Send the document_key to POST /v2/document/{document_id}/result. The response body is the file.

curl https://vibeql.com/v2/document/6DCB64C24BB8F7489283D26C42ABDB80/result \
  -H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
  -d "document_key=D097D7505E5240652F0B5BE2663A212EAA3D79F5C0013AB6051288601405CDED" \
  -o annual-report.pt-BR.pdf

VibeQL deletes the original and the translated file 24 hours after upload. Download the result before then.

All three steps in code

The DeepL client libraries do the upload, the polling and the download in one call. Point them at VibeQL with the server URL option. If you prefer plain HTTP, the third tab shows the full loop with backoff.

# pip install deepl
import os
import deepl

client = deepl.DeepLClient(os.environ["VIBEQL_API_KEY"], server_url="https://vibeql.com")
client.translate_document_from_filepath(
    "annual-report.pdf", "annual-report.pt-BR.pdf", target_lang="PT-BR"
)
// npm install deepl-node
import * as deepl from "deepl-node";

const client = new deepl.DeepLClient(process.env.VIBEQL_API_KEY, { serverUrl: "https://vibeql.com" });
await client.translateDocument("annual-report.pdf", "annual-report.pt-BR.pdf", null, "pt-BR");
import os
import time
import requests

BASE = "https://vibeql.com"
HEADERS = {"Authorization": f"DeepL-Auth-Key {os.environ['VIBEQL_API_KEY']}"}

with open("annual-report.pdf", "rb") as f:
    r = requests.post(f"{BASE}/v2/document", headers=HEADERS,
                      files={"file": f}, data={"target_lang": "PT-BR"})
r.raise_for_status()
doc = r.json()

delay = 2
while True:
    s = requests.post(f"{BASE}/v2/document/{doc['document_id']}", headers=HEADERS,
                      data={"document_key": doc["document_key"]}).json()
    if s["status"] == "done":
        break
    if s["status"] == "error":
        raise RuntimeError(s["error_message"])
    time.sleep(delay)
    delay = min(delay * 1.5, 30)

out = requests.post(f"{BASE}/v2/document/{doc['document_id']}/result", headers=HEADERS,
                    data={"document_key": doc["document_key"]})
out.raise_for_status()
with open("annual-report.pt-BR.pdf", "wb") as f:
    f.write(out.content)

Already on DeepL? Then this is your existing code with one changed line. Migrate from the DeepL API by changing one line shows the same change for .NET, Java, PHP, Ruby and Go.

One request for small files

For a small file, VibeQL also accepts the Azure document format. One request uploads the file, waits up to 90 seconds, and returns the translated file:

curl "https://vibeql.com/translator/document:translate?targetLanguage=de&api-version=2024-05-01" \
  -H "Ocp-Apim-Subscription-Key: $VIBEQL_API_KEY" \
  -F "document=@slides.pptx" \
  -o slides.de.pptx

If the translation takes longer than 90 seconds, this request returns 504. Use the three-step flow for large files.

From an AI agent

If an agent such as Claude does the work, you do not write the polling loop. The MCP server gives the agent tools to start a translation and get a download link. See Translate documents inside Claude with MCP.

How do document translation APIs bill?

Providers bill documents in three main ways. The difference is large for short files.

  • Per character. You pay for the characters of the source text. Azure Translator charges $15 per 1M characters for documents. VibeQL charges $13.75 per 1M on pay as you go.
  • Per page. You pay a fixed price for each page, whatever the amount of text. Google Cloud Translation charges $0.08 per page for documents.
  • Per character, with a minimum per document. You pay per character, but each document counts as at least a fixed amount. DeepL Growth bills each document as at least 50,000 characters, at $27.50 per 1M after the first 1M included in the plan.

Here is one two-page letter with 5,000 characters:

Provider How it bills Cost for this letter
DeepL Growth, above the included 1M 50,000 characters minimum × $27.50 / 1M $1.38
Google Cloud Translation 2 pages × $0.08 $0.16
Azure Translator 5,000 × $15 / 1M $0.08
VibeQL pay as you go 5,000 × $13.75 / 1M $0.07

Sources: DeepL pricing, Google Cloud Translation pricing, Azure Translator pricing, checked November 2026. Prices change, so check the pages before you decide.

For long documents the minimum stops mattering, and the rate per character decides. The DeepL API 50,000-character minimum works through three monthly examples. For your own numbers, use the translation cost calculator or read the translation API cost benchmark.

VibeQL has no minimum charge per document. A document uses the characters of its source text, the same as a text request. When the status is done, billed_characters shows the count. All plans are on the pricing page.

Which errors must your code handle?

VibeQL returns the same status codes as DeepL, with a JSON body like this:

{ "message": "Value for 'target_lang' not supported." }
Status Meaning What to do
400 A parameter is missing or wrong, or the file type is not supported. Fix the request. Do not retry as is.
403 The API key is missing, wrong or revoked. Check the key and how you send it.
404 The document does not exist, the document_key is wrong, or the file expired after 24 hours. Check the ID and key. Upload again if it expired.
413 The file is too large for your plan. Send a smaller file, or split it.
456 You reached your plan limit for characters or files this month. Stop the batch. Wait for the next month or change your plan.
500, 502 A temporary error on our side. Retry with backoff.
503 The document is not ready to download yet. Check the status, then download when it is done.

Two errors need special care in a batch job.

456 quota exceeded. Do not retry it in a loop. Each retry fails until the next month or a plan change. Check your usage before a large batch with GET https://vibeql.com/v2/usage, which returns character_count and character_limit.

413 too large. Your plan sets the maximum file size and number of pages. Beta accounts can upload files up to 20 MB and 300 pages. Retrying does not help. Split the file or compress its images.

With the Python client library, the errors arrive as exceptions:

import os
import deepl

client = deepl.DeepLClient(os.environ["VIBEQL_API_KEY"], server_url="https://vibeql.com")

try:
    client.translate_document_from_filepath("report.docx", "report.de.docx", target_lang="DE")
except deepl.QuotaExceededException:
    print("Monthly limit reached. Stop the batch.")
except deepl.DocumentTranslationException as e:
    print(f"Translation failed: {e}")
except deepl.DeepLException as e:
    print(f"Request failed: {e}")

The full list of codes and plan limits is in limits and errors.

What does the API keep in the file?

The output has the same format as the input. Page and slide layout, fonts and colours, tables, columns and images stay in place. Each format has its own details:

Some limits apply to all formats. Scanned PDFs are not translated yet, because there is no OCR yet. Text inside images, WordArt and embedded OLE objects are not translated. The API ignores glossary_id and formality.

Try it

VibeQL is in beta and sign-up is closed. Join the waitlist to get an account. Then follow the quickstart, or read the full reference in translate documents. The developers page gives an overview of the API.

Translate your next file with VibeQL

Free plan: 3 documents and 500,000 API characters a month. Sign-up opens soon; join the list and we email you.

Free plan when your account opens. One email when it is ready, then about one product email a month.

See pricing