POST /v1/translate reference

Ainda não traduzido — apresentado em inglês.

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

NameTypeRequiredNotes
textstring or array of stringsyesUp to 50 entries, none of them empty. A single string is treated as a one-element array.
target_langstringyesA target code such as NL, EN-GB or PT-BR. Case does not matter; en_gb works.
source_langstringnoA base code such as ES. Leave it out to let the engine detect the language.
formalitystringnodefault, more, less, prefer_more or prefer_less. See Formality control.
glossary_idstringnoId of one of your glossaries. Needs source_lang, and the pair must match. See Glossary endpoints.
tag_handlingstringnohtml or xml. Markup is preserved, text nodes are translated. See HTML and XML tag handling.
preserve_formattingbooleannoKeep leading/trailing whitespace, punctuation and capitalisation exactly as sent.
contextstringnoUp 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.

  1. text present, non-empty, at most 50 items — otherwise validation_error

or too_many_texts.

  1. Total characters within your plan's per-request limit — otherwise

text_too_long.

  1. target_lang present and supported — otherwise validation_error or

invalid_target_lang.

  1. source_lang, if given, supported — otherwise invalid_source_lang.
  2. formality is one of the five values, and more/less is only used on a

target that supports it — otherwise validation_error.

  1. tag_handling, context length, 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

FieldContent
translations[].textThe translation of the entry at the same index in text.
translations[].detected_source_languageThe source_lang you sent, or the code the engine detected.
request_id26-character ULID for this request. Identical to the X-Request-Id header.
charactersCharacters charged. Identical to X-Characters-Billed.
engine.prompt_tokensTokens the engine read. Informational only.
engine.completion_tokensTokens the engine produced. Informational only.
engine.total_tokensSum of the two; 0 when every text was served from the cache.

Response headers

HeaderValue
X-Request-IdThe request's ULID. Present on errors as well.
X-Characters-BilledCharacters charged for this request.
X-RateLimit-LimitRequests per second your plan allows.
X-RateLimit-RemainingRequests still available in the current one-second window.
X-RateLimit-ResetSeconds until the window has moved on; always 1.
Cache-Controlno-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 goStarterBusiness
Characters per request50,000100,000200,000
Texts per request505050
Requests per second1025100

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.

Revisto em 7 de set. de 2026 00:00