You can get machine translation and translation quality scores from the /translate endpoint. This endpoint/class takes three parameters:

  • text - The text to translate.
  • source_lang - The ISO 639 source language code (e.g. ‘eng’ for English).
  • target_lang - The ISO 639 target language code (e.g ‘fra’ for French).

Under the hood, the /translate endpoint simultaneously leverages multiple state-of-the-art LLM and machine translation models to perform translations. The translations from these models are scored and ranked using reference-free quality estimation models. This allows us to select the highest quality machine translation for the given source and target languages.

Supported Languages

Our translation API supports a wide range of languages, including but not limited to English, Hindi, French, Spanish, German, and more. Refer to the language codes to identify specific languages.

List of supported languages


The /translate endpoint will return a JSON object response with two fields:

  • Best translation - The translated text.
  • Score - A score from -1.0 to 1.0 representing the translation quality. Higher the score better the quality.

Generate a translation

To generate a translation, you can use the following code examples. Depending on your preference or requirements, select the appropriate method for your application.

1import os
2import json
4import predictionguard as pg
6# Set your PREDICTIONGUARD access token as an environmental variable.
7os.environ["PREDICTIONGUARD_TOKEN"] = "<your access token>"
9# Translate the text.
10result = pg.Translate.create(
11 text="The sky is blue",
12 source_lang="eng",
13 target_lang="fra"
14 )
17 result,
18 sort_keys=True,
19 indent=4,
20 separators=(',', ': ')

The output will look something like:

2 "response": {
3 "Best translation": "Le ciel est bleu",
4 "Score": 0.8694158792495728
5 }