POST /v1/translate reference
Še ni prevedeno — prikazano v angleščini.
POST https://api.langapi.xyz/v1/translate
This is the endpoint that does the work. It accepts a JSON body or a URL-encoded form and always responds with JSON.
Body parameters
| Name | Type | Required | Notes |
|---|---|---|---|
text | string or array of strings | yes | Up to 50 entries, none of them empty. A single string is treated as a one-element array. |
target_lang | string | yes | A target code such as NL, EN-GB or PT-BR. Case does not matter; en_gb works. |
source_lang | string | no | A base code such as ES. Leave it out to let the engine detect the language. |
formality | string | no | default, more, less, prefer_more or prefer_less. See Formality control. |
glossary_id | string | no | Id of one of your glossaries. Needs source_lang, and the pair must match. See Glossary endpoints. |
tag_handling | string | no | html or xml. Markup is preserved, text nodes are translated. See HTML and XML tag handling. |
preserve_formatting | boolean | no | Keep leading/trailing whitespace, punctuation and capitalisation exactly as sent. |
context | string | no | Up to 2,000 characters of background for disambiguation. Not translated, not counted. |
Two target codes are aliases: EN resolves to EN-US and PT to PT-PT. Name the variant explicitly if the distinction matters to you.
Validation order
Checks run in a fixed sequence and stop at the first failure. Knowing the order helps when a request fails for more than one reason.
textpresent, non-empty, at most 50 items — otherwisevalidation_error
or too_many_texts.
- Total characters within your plan's per-request limit — otherwise
text_too_long.
target_langpresent and supported — otherwisevalidation_erroror
invalid_target_lang.
source_lang, if given, supported — otherwiseinvalid_source_lang.formalityis one of the five values, andmore/lessis only used on a
target that supports it — otherwise validation_error.
tag_handling,contextlength, and finally the glossary: it must exist
(glossary_not_found), source_lang must be set and the language pair must match (validation_error).
Only after all of that are characters reserved against your quota.
Worked example
A Spanish product description into British English, with a glossary that pins the product name and context that tells the engine what kind of text it is.
curl https://api.langapi.xyz/v1/translate \
-X POST \
-H "Authorization: Bearer la_live_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"text": ["La funda protege el teléfono contra golpes y arañazos."],
"source_lang": "ES",
"target_lang": "EN-GB",
"glossary_id": "01JAX1F7Q0M2ZK8WDN5R3TB9VE",
"context": "Short product description in an online shop for phone accessories."
}'
{
"translations": [
{
"detected_source_language": "ES",
"text": "The case protects the phone against knocks and scratches."
}
],
"request_id": "01JAX1G2H4N6PQ8S0T2V4W6X8Z",
"characters": 54,
"engine": { "prompt_tokens": 88, "completion_tokens": 17, "total_tokens": 105 }
}
Response body
| Field | Content |
|---|---|
translations[].text | The translation of the entry at the same index in text. |
translations[].detected_source_language | The source_lang you sent, or the code the engine detected. |
request_id | 26-character ULID for this request. Identical to the X-Request-Id header. |
characters | Characters charged. Identical to X-Characters-Billed. |
engine.prompt_tokens | Tokens the engine read. Informational only. |
engine.completion_tokens | Tokens the engine produced. Informational only. |
engine.total_tokens | Sum of the two; 0 when every text was served from the cache. |
Response headers
| Header | Value |
|---|---|
X-Request-Id | The request's ULID. Present on errors as well. |
X-Characters-Billed | Characters charged for this request. |
X-RateLimit-Limit | Requests per second your plan allows. |
X-RateLimit-Remaining | Requests still available in the current one-second window. |
X-RateLimit-Reset | Seconds until the window has moved on; always 1. |
Cache-Control | no-store on every API response. |
Form-encoded bodies
Without a JSON content type the body is read as application/x-www-form-urlencoded. Repeat text for each entry; text[] is accepted as well.
curl https://api.langapi.xyz/v1/translate \
-H "Authorization: Bearer la_live_xxxxxxxx" \
--data-urlencode "text=Reset password" \
--data-urlencode "text=Remember me on this device" \
--data-urlencode "target_lang=PL"
Plan limits
| Pay as you go | Starter | Business | |
|---|---|---|---|
| Characters per request | 50,000 | 100,000 | 200,000 |
| Texts per request | 50 | 50 | 50 |
| Requests per second | 10 | 25 | 100 |
Counting characters
The count is mb_strlen over every entry of text, summed. Letters, digits, spaces, line breaks, punctuation and every character of HTML or XML markup are included. context is excluded. The same function produces the reservation, the characters field and the usage record, so the three cannot diverge.
Caching
Each entry in text is cached separately. The cache key covers the text itself, the source language (or "auto"), the target language, formality, the glossary id together with its version, tag_handling, preserve_formatting and context. Change any of them and the entry is translated afresh. Cached entries are still charged; the reservation happens before the cache is consulted.
Engine failures
The engine is called with a 30-second timeout. A transport error, a 5xx or a 429 from the engine is retried once internally. If the second attempt fails too, the reservation is rolled back and you receive 503 with the code engine_unavailable and Retry-After: 5. Nothing is charged for that request.
Popravljeno 7. sep. 2026, 00:00