Authentication
Every request sends two headers: x-rapidapi-key with your key and x-rapidapi-host: nlp-translation.p.rapidapi.com. You get the key from RapidAPI after you subscribe to a plan (Basic is free).
| Header | Where | Required | Value |
|---|---|---|---|
x-rapidapi-key | header | Yes | Your RapidAPI application key, shown on the RapidAPI listing once you subscribe. |
x-rapidapi-host | header | Yes | Always nlp-translation.p.rapidapi.com. |
Call the API from your own backend so the key stays private. Never ship it in public client code.
Translate text or HTML: /v1/translate
/v1/translate translates plain text or HTML into one or more languages. Use GET with the parameters
in the query string, or POST with a JSON, form-urlencoded or multipart body.
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Plain text or HTML to translate. Up to 1,000 characters per request on Basic, 5,000 on paid plans. |
to | string | Yes | Target language code, or several separated by ; (for example fr;pt). Codes are case-sensitive. |
from | string | No | Source language code. Omit it for automatic source language detection. |
protected_words | string | No | Words to leave untranslated, separated by ; (for example Acme;CloudSync). Case-sensitive. |
Request
cURL
curl --request POST \
--url https://nlp-translation.p.rapidapi.com/v1/translate \
--header 'Content-Type: application/json' \
--header 'x-rapidapi-host: nlp-translation.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
--data '{"text":"Nice to meet you","to":"fr","from":"en"}' JavaScript
const response = await fetch("https://nlp-translation.p.rapidapi.com/v1/translate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-rapidapi-host": "nlp-translation.p.rapidapi.com",
"x-rapidapi-key": process.env.RAPIDAPI_KEY,
},
body: JSON.stringify({
text: "Nice to meet you",
to: "fr",
from: "en",
}),
});
const data = await response.json();
if (data.status !== 200) throw new Error(data.Error);
console.log(data.translated_text["fr"]); Python
import os
import requests
response = requests.post(
"https://nlp-translation.p.rapidapi.com/v1/translate",
headers={
"x-rapidapi-host": "nlp-translation.p.rapidapi.com",
"x-rapidapi-key": os.environ["RAPIDAPI_KEY"],
},
json={
"text": "Nice to meet you",
"to": "fr",
"from": "en",
},
timeout=30,
)
data = response.json()
print(data["translated_text"]["fr"]) PHP
<?php
$ch = curl_init("https://nlp-translation.p.rapidapi.com/v1/translate");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-rapidapi-host: nlp-translation.p.rapidapi.com",
"x-rapidapi-key: " . getenv("RAPIDAPI_KEY"),
],
CURLOPT_POSTFIELDS => json_encode([
'text' => 'Nice to meet you',
'to' => 'fr',
'from' => 'en',
]),
]);
$data = json_decode(curl_exec($ch), true);
echo $data["translated_text"]['fr']; Response
A successful response has status 200 and one translation per target code in translated_text.
Response
{
"status": 200,
"from": "en",
"to": "fr",
"original_text": "Nice to meet you",
"translated_text": {
"fr": "Ravi de vous rencontrer"
},
"translated_characters": 16
} | Field | Type | Present | Description |
|---|---|---|---|
status | number | Always | 200 on success, otherwise the error code. Always check this field. |
from | string | On success | Source language code (detected when you omitted from). |
to | string | On success | Target codes that were translated, separated by ;. |
original_text | string | On success | The text you sent. |
translated_text | object | On success | One entry per target code: { "fr": "…" }. |
translated_characters | number | On success | Characters counted for this request: text length × number of target languages. |
message | string | Sometimes | Notes a plan limit, for example when extra target languages were dropped. |
Error | string | On error | What went wrong, in plain English. |
GET request
The same call as a GET, without from so the source language is detected automatically:
cURL
curl --request GET \
--url 'https://nlp-translation.p.rapidapi.com/v1/translate?text=Nice%20to%20meet%20you&to=fr' \
--header 'x-rapidapi-host: nlp-translation.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' Several target languages
Separate target codes with ; to get every translation in one response. Your plan sets how many codes one request may
list: Basic 1, Pro 2, Ultra 3, Mega 4.
cURL
curl --request POST \
--url https://nlp-translation.p.rapidapi.com/v1/translate \
--header 'Content-Type: application/json' \
--header 'x-rapidapi-host: nlp-translation.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
--data '{"text":"Nice to meet you","to":"fr;pt","from":"en"}' Response
{
"status": 200,
"from": "en",
"to": "fr;pt",
"original_text": "Nice to meet you",
"translated_text": {
"fr": "Ravi de vous rencontrer",
"pt": "Prazer em conhecê-lo"
},
"translated_characters": 32
}
If to lists more codes than your plan allows, the extra codes are dropped and message says why:
Response
{
"status": 200,
"from": "en",
"to": "fr;pt",
"original_text": "Nice to meet you",
"translated_text": {
"fr": "Ravi de vous rencontrer",
"pt": "Prazer em conhecê-lo"
},
"translated_characters": 32,
"message": "Translated. Maximum Multiple target languages simultaneously in your current plan is 2"
} HTML
Send HTML in text and the markup comes back unchanged: tags and attributes are preserved and only the text is
translated. Markup counts toward the characters of the request.
cURL
curl --request POST \
--url https://nlp-translation.p.rapidapi.com/v1/translate \
--header 'Content-Type: application/json' \
--header 'x-rapidapi-host: nlp-translation.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
--data '{"text":"<p>Free shipping on <strong>all orders</strong></p>","to":"es","from":"en"}' Response
{
"status": 200,
"from": "en",
"to": "es",
"original_text": "<p>Free shipping on <strong>all orders</strong></p>",
"translated_text": {
"es": "<p>Envío gratis en <strong>todos los pedidos</strong></p>"
},
"translated_characters": 51
} Protected words
protected_words keeps brand names and product terms exactly as written. Separate several with ;; matching
is case-sensitive.
cURL
curl --request POST \
--url https://nlp-translation.p.rapidapi.com/v1/translate \
--header 'Content-Type: application/json' \
--header 'x-rapidapi-host: nlp-translation.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
--data '{"text":"Acme Cloud keeps your files safe","to":"de","from":"en","protected_words":"Acme Cloud"}' Translate JSON: POST /v1/jsontranslate
/v1/jsontranslate translates the string values of a JSON object and keeps its keys, numbers and structure. Send the
document as a string in json; from is required on this endpoint.
| Parameter | Type | Required | Description |
|---|---|---|---|
json | string | Yes | The JSON document to translate, as a string. It must be an object ({…}). A JSON object instead of a string also works. |
to | string | Yes | Target language code, or several separated by ;. Codes are case-sensitive. |
from | string | Yes | Source language code. Required on this endpoint (no automatic detection). |
protected_keys | string | No | Keys whose values are left as they are, separated by ;. Use dot paths for nested keys, for example id;meta.sku. |
protected_words | string | No | Words to leave untranslated inside the values, separated by ;. Case-sensitive. |
Request
cURL
curl --request POST \
--url https://nlp-translation.p.rapidapi.com/v1/jsontranslate \
--header 'Content-Type: application/json' \
--header 'x-rapidapi-host: nlp-translation.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
--data '{"from":"en","to":"de","json":"{\"title\":\"Welcome home\"}"}' JavaScript
const response = await fetch("https://nlp-translation.p.rapidapi.com/v1/jsontranslate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-rapidapi-host": "nlp-translation.p.rapidapi.com",
"x-rapidapi-key": process.env.RAPIDAPI_KEY,
},
body: JSON.stringify({
from: "en",
to: "de",
json: "{\"title\":\"Welcome home\"}",
}),
});
const data = await response.json();
if (data.status !== 200) throw new Error(data.Error);
console.log(data.translated_json["de"]); Python
import os
import requests
response = requests.post(
"https://nlp-translation.p.rapidapi.com/v1/jsontranslate",
headers={
"x-rapidapi-host": "nlp-translation.p.rapidapi.com",
"x-rapidapi-key": os.environ["RAPIDAPI_KEY"],
},
json={
"from": "en",
"to": "de",
"json": "{\"title\":\"Welcome home\"}",
},
timeout=30,
)
data = response.json()
print(data["translated_json"]["de"]) PHP
<?php
$ch = curl_init("https://nlp-translation.p.rapidapi.com/v1/jsontranslate");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-rapidapi-host: nlp-translation.p.rapidapi.com",
"x-rapidapi-key: " . getenv("RAPIDAPI_KEY"),
],
CURLOPT_POSTFIELDS => json_encode([
'from' => 'en',
'to' => 'de',
'json' => '{"title":"Welcome home"}',
]),
]);
$data = json_decode(curl_exec($ch), true);
echo $data["translated_json"]['de']; Response
translated_json holds one translated JSON string per target code. Parse it with your JSON library.
Response
{
"status": 200,
"from": "en",
"to": "de",
"original_json": "{\"title\":\"Welcome home\"}",
"protected_keys": "",
"protected_words": "",
"translated_json": {
"de": "{\"title\":\"Willkommen zu Hause\"}"
},
"translated_characters": 24
} | Field | Type | Present | Description |
|---|---|---|---|
status | number | Always | 200 on success, otherwise the error code. |
from | string | On success | Source language code. |
to | string | On success | Target codes that were translated. |
original_json | string | On success | The JSON document you sent. |
translated_json | object | On success | One translated JSON string per target code. |
translated_characters | number | On success | Characters counted: JSON length × number of target languages. |
Error | string | On error | What went wrong. |
Protected keys
protected_keys returns the values of the listed keys unchanged, for IDs, SKUs, URLs or codes. Separate keys with ; and use dot paths for nested keys, for example id;meta.sku.
cURL
curl --request POST \
--url https://nlp-translation.p.rapidapi.com/v1/jsontranslate \
--header 'Content-Type: application/json' \
--header 'x-rapidapi-host: nlp-translation.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
--data '{"from":"en","to":"fr","json":"{\"sku\":\"TSHIRT-01\",\"name\":\"Blue T-shirt\"}","protected_keys":"sku"}' Errors
Errors come back as {"status": <code>, "Error": "<message>"}. The HTTP status is often 200 even when the request failed,
so always check the status field of the body.
Response
{
"status": 412,
"Error": "Invalid Target Language Code: fra"
} | When | HTTP | Body |
|---|---|---|
to is missing or empty | 200 | {"status":412,"Error":"Target Language Code Needed"} |
| A target code is not in the language list (codes are case-sensitive) | 200 | {"status":412,"Error":"Invalid Target Language Code: fra"} |
text is longer than your plan allows (1,000 on Basic, 5,000 on paid plans) | 200 | {"status":412,"Error":"Text with More than 1000 characters or less than one Character is not allowed"} |
| More requests in progress than your plan's concurrent limit | 200 | {"status":429,"Error":"Your are currently have 1 translating job, Your Max thread: 1"} |
/v1/jsontranslate without from | 412 | {"status":412,"Error":"From Language Code Needed in JSON Data Translation"} |
/v1/jsontranslate without to | 200 | {"status":412,"Error":"Target Language Code Needed in JSON Data Translation"} |
json is not a JSON object | 200 | {"status":412,"Error":"JSON must be start with { && end with }"} |
| A temporary problem on our side | 500 | {"status":500,"Error":"Server Error"} |
Errors about your key, subscription or monthly quota come from RapidAPI in RapidAPI's own format, for example {"message": "You are not subscribed to this API."}. For status 429 and 5xx, wait a moment and retry.
Language codes
Language codes are case-sensitive: use zh-CN, not zh-cn. A few differ from ISO 639-1: Hebrew is iw and Javanese is jw. See all 110 codes.