Translate

POST
Translate text from one language to another.

Request

This endpoint expects an object.
text
stringRequired
The text to check for toxicity.
source_lang
stringRequired
The source language of the text.
target_lang
stringRequired
The target language for the translation.

Response

This endpoint returns an object
id
stringOptional
Unique ID for the chat completion.
object
stringOptional
Type of object (chat completion).
created
integerOptional
Timestamp of when the chat completion was created.
best_translation
stringOptional
The best translation of the input text.
best_score
doubleOptional
The best score for the best translation.
best_translation_model
stringOptional
The model used for the best translation.
translations
list of objectsOptional
The set translations from different models.

Errors

POST
1curl -X POST https://api.predictionguard.com/translate \
2 -H "x-api-key: <apiKey>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "text": "The rain in Spain stays mainly in the plain",
6 "source_lang": "eng",
7 "target_lang": "spa"
8}'
1{
2 "id": "translation-9b2c6f43cf7d4fe69cb9b9e6a4478999",
3 "object": "translation",
4 "created": 1717676604,
5 "best_translation": "La lluvia en España permanece principalmente en la llanura",
6 "best_score": 0.5381202101707458,
7 "best_translation_model": "google",
8 "translations": [
9 {
10 "score": -100,
11 "translation": "",
12 "model": "openai",
13 "status": "error: couldn’t get translation"
14 },
15 {
16 "score": 0.5008216500282288,
17 "translation": "La lluvia en España se queda principalmente en la llanura",
18 "model": "deepl",
19 "status": "success"
20 },
21 {
22 "score": 0.5381202101707458,
23 "translation": "La lluvia en España permanece principalmente en la llanura",
24 "model": "google",
25 "status": "success"
26 },
27 {
28 "score": 0.4843788146972656,
29 "translation": "La lluvia en España se queda principalmente en la llanura.",
30 "model": "nous_hermes_llama2",
31 "status": "success"
32 }
33 ]
34}