1. Get The API Key
Log In to your http://Custom.MT account and create an API Key. In order to do that select Translation tab and then go to Credentials tab. You will see the section called API Keys that will have no connections available, so you need to press Create New button. A new connection will be automatically created.
...
Copy the text in the Key column, you will need this API Key in the following steps to enable the connection.
...
https://console.custom.mt/credentials/
...
2. Authentification
To authorize the user in the headers, add the token field from the Custom MT Console user's account.
Code Block |
---|
curl -X GET \
{api_endpoint}/api-translation/{action} \
-H 'cache-control: no-cache' \
-H 'token: {user_token}' |
api_endpoint https://console.custom.mt
...
action route of the requested action
user_token it is your API key
3. Translate Using Template List
CreateTemplates in the console following the guidelines from the article Templates .
...
Paste the API Key copied at Step 2.
...
Enter the languages from the translation template you created earlier.
...
Get the list of templates for the selected languages by pressing Try it out and Execute buttons.
...
Translate your text by adding the text to be translated and the template name and pressing Execute button.
...
...
4. Get a Template List
Code Block |
---|
curl --location --request POST ' {api_endpoint}/translation/get-templates' \
--header 'token: {user_token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"source_language": "en",
"target_language": "es"
}' |
As a result, we get:
Code Block |
---|
[
{
"template_name": "test1"
},
{
"template_name": "test2"
}
] |
5. Translate With Batch Request:
Code Block |
---|
curl --location --request POST '{api_endpoint}/translation/translate' \
--header 'token: {user_token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"text": ["Machine translation uses artificial intelligence to translate texts from one language to another automatically.", “test text 1”, “test text 2”],
"template_name": "test2"
}' |
max batch number is 50 TUs
As a result, we get:
Code Block |
---|
{
"translated_text": [
"La traducción automática utiliza inteligencia artificial para traducir textos de un idioma a otro automáticamente."
]
} |
6. Errors or warnings
If base model not available you’ll get message in response:
Code Block |
---|
{
"translated_text": [
"text"
],
"message": "The main model is not available. If the error continues, please contact CMT hub support."
}
If it was not possible to translate the text and received a critical error, the answer will be like this:
{
“error”: “Something happened on the CMT hub side. They already know about it and they are solving the issue.”
} |