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.
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.
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
Create Templates in the console following the guidelines from the article.
https://console.custom.mt/templates/
4. Get a Template List
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:
[ { "template_name": "test1" }, { "template_name": "test2" } ]
5. Translate With Batch Request:
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:
{ "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:
{ "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.” }