# Translate documents

Upload a DOCX, PPTX, PDF or TXT file, poll its status and download the translated file with its layout kept.

VibeQL translates DOCX, PPTX, PDF and TXT files. The translated file has the same format as the original, and the layout stays in place.

There are two ways to translate a file:

- **DeepL format.** Upload, poll, download. Use it for large files and with the DeepL client libraries.
- **Azure format.** One request that waits for the result, up to 90 seconds. Use it for small files.

## DeepL format

### 1. Upload the file

`POST https://vibeql.com/v2/document` with a multipart form.

| Field | Required | Description |
|---|---|---|
| `file` | Yes | The file to translate. |
| `target_lang` | Yes | Target language code, for example `DE` or `PT-BR`. |
| `source_lang` | No | Source language code. Leave it out to detect it from the text. |
| `filename` | No | File name to use instead of the name of the uploaded file. The extension sets the format. |

```bash
curl https://vibeql.com/v2/document \
  -H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
  -F "file=@annual-report.pdf" \
  -F "target_lang=PT-BR"
```

```json
{
  "document_id": "6DCB64C24BB8F7489283D26C42ABDB80",
  "document_key": "D097D7505E5240652F0B5BE2663A212EAA3D79F5C0013AB6051288601405CDED"
}
```

Keep both values. You need the `document_key` for every later request about this document.

### 2. Check the status

`POST https://vibeql.com/v2/document/{document_id}` with `document_key` in the body.

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

| `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` |

```json
{ "document_id": "6DCB64C24BB8F7489283D26C42ABDB80", "status": "translating", "seconds_remaining": 12 }
```

```json
{ "document_id": "6DCB64C24BB8F7489283D26C42ABDB80", "status": "done", "billed_characters": 18452 }
```

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

### 3. Download the result

`POST https://vibeql.com/v2/document/{document_id}/result` with `document_key` in the body. The response is the file.

```bash
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
```

If the translation is not done yet, the API returns `503` with `{"message": "Document not ready"}`. Check the status again and retry.

### All steps in code

The DeepL client libraries upload, poll and download in one call. Set the server URL as shown in the [quickstart](/docs/quickstart).

**Python**

```python
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"
)
```

**Node**

```js
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");
```

**Python (HTTP)**

```python
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)
```

## Azure format

`POST https://vibeql.com/translator/document:translate` translates a file in one request. Send the file as the multipart field `document`.

| Query parameter | Required | Description |
|---|---|---|
| `api-version` | Yes | Must be `2024-05-01`. |
| `targetLanguage` | Yes | Target language, for example `de` or `pt-BR`. |
| `sourceLanguage` | No | Source language. Leave it out to detect it. |

```bash
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
```

The request waits up to 90 seconds and returns the translated file. If the translation fails, it returns `422`. If it takes longer than 90 seconds, it returns `504`. For large files, use the DeepL format.

## Formats and limits

| Format | Extension |
|---|---|
| Word | `.docx` |
| PowerPoint | `.pptx` |
| PDF | `.pdf` |
| Plain text | `.txt` |

Your plan sets the maximum file size and number of pages. Beta accounts can upload files up to 20 MB and 300 pages. A larger file returns `413`. Other file types return `400`. See [Limits and errors](/docs/limits-and-errors).

There is no minimum charge per document. A document uses the characters of its source text, the same as a text request. The `billed_characters` field shows the count when the status is `done`.

## What is kept

- The page and slide layout.
- Fonts and colors. PDFs are the exception, see below.
- Tables and columns.
- Images, in the same positions.

## Known limits

- Scanned PDFs are not translated yet. The PDF must contain selectable text.
- Text inside images is not translated.
- In PDFs, fonts are replaced by fonts with the same metrics, so the text keeps its size and position.
- WordArt and embedded OLE objects are not translated.

## Retention

VibeQL deletes the original and the translated file 24 hours after upload. After that, download requests return `404`. Download the result before then.
