MachineTranslation.com API Documentation
The MachineTranslation.com API translates text and structured JSON files, and lets you steer the output with a custom instruction and a glossary.
It supports:
- Plain text translation via JSON requests, with an optional custom instruction
- Structured JSON file translation, where keys and structure are preserved and only string values are translated. This endpoint also accepts a custom instruction and a glossary (reference file)
custom_instruction is available on both endpoints. reference_file is available on the JSON file endpoint only. See Custom Instructions & Glossaries below.Base URLs
Text translation:
JSON file translation:
Authentication
The API uses BEARER authentication. Include your API key in the Authorization header of every request.
Example
Request an API Key
To get an API key, contact us →
Endpoints
Create Translation (Text)
POST /pv1/translate translates plain text from one language to another. It supports a custom instruction but not a glossary. The body must be valid JSON.
reference_file, are silently ignored. A multipart upload to this endpoint returns 422 because the body is not valid JSON.HTTP Request
Headers
Authorization: BEARER <your_api_key> Content-Type: application/json
Request Body
{
"text": "The text you want to translate",
"source_language_code": "en",
"target_language_code": "fr",
"custom_instruction": "Optional instruction for the translation"
}| Field | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | Text to be translated |
| source_language_code | string | Yes | Source language code (e.g. en) |
| target_language_code | string | Yes | Target language code (e.g. fr) |
| custom_instruction | string | No | Extra instruction added to the translation prompt. Max 2,000 characters, counted after leading and trailing spaces are trimmed. |
Example Request
curl --location 'https://api.machinetranslation.com/pv1/translate' \
--header 'Authorization: BEARER <your_api_key>' \
--header 'Content-Type: application/json' \
--data '{
"text": "MachineTranslation.com {smart} translates, compares, and recommends the best translations.",
"source_language_code": "en",
"target_language_code": "fr",
"custom_instruction": "Do not translate text inside {curly_braces}; keep placeholders exactly as written."
}'Response Example
{
"translations": [
{
"engine": "smart",
"share_id": "cf733e14-ea86-4f6b-92fc-de9813197601",
"source_text": "MachineTranslation.com {smart} translates, compares, and recommends the best translations.",
"target_text": "MachineTranslation.com {smart} traduit, compare et recommande les meilleures traductions.",
"source_word_count": 9,
"target_word_count": 9,
"source_language_code": "en",
"target_language_code": "fr"
}
]
}Response Fields
translations: Array of results from different enginesengine: Translation engine usedshare_id: Unique ID for the translationsource_text/target_text: Original and translated textsource_word_count/target_word_count: Word countssource_language_code/target_language_code: Language codes
Translate JSON File
POST /pv1/translate/file translates a .json file while preserving its original structure. It accepts .json files only. Any other file type, including DOCX and XLSX, is rejected with 400 Only JSON files allowed before the glossary is read. This endpoint supports both a custom instruction and a glossary.
- JSON keys and structure are preserved
- Only string values are translated
- Numbers, booleans, arrays, and objects remain unchanged
HTTP Request
Headers
Authorization: BEARER <your_api_key> Content-Type: multipart/form-data
Request Body (form-data)
| Field | Type | Required | Description |
|---|---|---|---|
| file | file | Yes | JSON file to translate |
| source_language_code | string | Yes | Source language code (e.g. en) |
| target_language_code | string | Yes | Target language code (e.g. fr) |
| custom_instruction | string | No | Extra instruction added to the translation prompt. Max 2,000 characters, counted after leading and trailing spaces are trimmed. |
| reference_file | file | No | Glossary file whose terms are added to the translation prompt. Max 5 MB and 20,000 characters of text. Supported formats: .txt, .csv, .docx, .xlsx, .xliff, .xml. See Custom Instructions & Glossaries for the file structure. |
Example Request
curl --location 'https://api.machinetranslation.com/pv1/translate/file' \
--header 'Authorization: BEARER <your_api_key>' \
--form 'source_language_code="en"' \
--form 'target_language_code="it"' \
--form 'file=@"/path/to/sample.json"' \
--form 'custom_instruction="Do not translate text inside {curly_braces}; keep placeholders exactly as written."' \
--form 'reference_file=@"/path/to/glossary.txt"'Response Example
{
"translated_json": {
"title": "Testo tradotto",
"description": "La struttura JSON originale viene mantenuta"
},
"source_language_code": "en",
"target_language_code": "it"
}Notes
- The response returns a
translated_jsonobject with the same structure as the uploaded file.
Custom Instructions & Glossaries
Use these optional parameters to control tone, protect placeholders, or enforce preferred terminology. Both are added to the prompt when the text is translated.
| Custom instruction | Glossary | |
|---|---|---|
| Parameter | custom_instruction | reference_file |
| Text endpoint | Supported | Not supported |
| JSON file endpoint | Supported | Supported |
| Sent as | String | File upload (form-data) |
How it works
- Both are optional.
- Send them with every request. Nothing is saved to your account or API key, so a later call without them is translated without them.
- Use
custom_instructionfor rules in plain language, for example:Do not translate text inside {curly_braces}; keep placeholders exactly as written. - Use
reference_fileto supply approved terminology, such as product names and key terms.
Supported glossary file formats
.txt, .csv, .docx, .xlsx, .xliff, .xml
Not accepted: .tsv, .tmx, .tbx, .xls, .doc.
Glossary file structure
| Format | Structure |
|---|---|
| .txt, .csv, .docx | One term per line, written as source = target. A .csv file is not split on commas, and tab-separated lines are not recognised as pairs. |
| .xlsx | Source term in column A and target term in column B, on the first sheet, with no header row. |
| .xliff | Standard <source> / <target> pairs. |
| .xml | Accepted. The expected element structure is not yet specified. |
Example glossary.txt (English to Italian)
SMART Translation = Traduzione SMART consensus = consenso
.txt and .csv files must be UTF-8. Invalid bytes do not cause an error; they are converted to the � character.
Good to know
- The glossary goes into the prompt as reference material and the AI model applies it. Matching is best-effort: plurals and inflected forms are usually handled, but there is no guarantee that a term is used exactly as written.
- A glossary can contain more than one language, but it is not filtered to the request's language pair. The whole file is sent to the engines and the model decides which entries apply. One language pair per file is recommended.
- The instruction and the glossary are sent to every engine in the consensus. No priority is defined between them, since both go into one prompt block, so avoid instructions that contradict your glossary.
- The glossary is read in memory, used for that one request, and not stored.
- The extra prompt tokens from the instruction and glossary do not count toward your usage or credits.
Limits & Errors
Exceeding any limit always returns an error. Input is never silently truncated.
Limits
| Parameter | Limit | Approx. size |
|---|---|---|
| custom_instruction | 2,000 characters, counted after leading and trailing spaces are trimmed | About 500 English tokens |
| reference_file size | 5 MB | |
| reference_file text | 20,000 characters of text read from the file | About 5,000 English tokens |
| Terms, or characters per term | No separate limit, only the 20,000-character total |
Error responses
Exact status codes and messages are published only where they are confirmed. The remaining cases still return an error.
| Case | HTTP status | Error message |
|---|---|---|
custom_instruction over 2,000 characters | Not yet published | Not yet published |
reference_file over 5 MB | Not yet published | Not yet published |
reference_file over 20,000 characters of text | Not yet published | Not yet published |
Unsupported reference_file format (for example .tsv or .xls) | Not yet published | Not yet published |
Non-.json file sent to /pv1/translate/file | 400 | Only JSON files allowed |
Multipart upload sent to /pv1/translate | 422 | Body is not valid JSON. The exact message text is not yet published. |
reference_file or any unknown key in the JSON body of /pv1/translate | No error | Silently ignored |
| Missing or invalid API key | Not yet published | Not yet published |
Supported Languages
The API supports 332 languages. Use the codes below, for example English en, French fr, Chinese (Simplified) zh, Chinese (Traditional) zh-TW, Spanish es, Portuguese (Brazil) pt, Japanese ja, Arabic ar, and Hindi hi.
AI Translation Models & Smart AI Translation
MachineTranslation.com runs up to 22 AI models at once, compares the outputs, and returns the best translation most of the AI models agree on (engine: "smart").
The custom instruction and glossary are sent to every engine in the consensus, on every path.
Currently Supported Translation Sources
Sources include, but are not limited to: