API de traduction de texte
Traduisez du texte avec l’API GPT Translator.
Point de terminaison
POST https://api.gpttranslator.co/v1/translation/text-translation/api
Authentification
Ajoutez votre clé API aux en-têtes de la requête :
x-api-key: YOUR_API_KEY
Content-Type: application/json
Corps de la requête
Champs obligatoires :
text(chaîne de caractères) : Texte source à traduiresourceLang(chaîne de caractères) : Code de la langue sourcetargetLang(chaîne de caractères) : Code de la langue ciblemodel(chaîne de caractères) : Nom du modèle de traduction
Champs facultatifs :
domain(chaîne de caractères) : Spécialisation par domainewritingStyle(chaîne de caractères) : Préférence de style rédactionneltone(chaîne de caractères) : Préférence de toncustomPrompt(chaîne de caractères) : Instructions de traduction personnalisées
Les codes de langue sont répertoriés séparément dans Langues prises en charge. Les modèles pris en charge sont répertoriés dans Modèles pris en charge.
Règles de validation
text: Obligatoire. Ne peut pas être vide.sourceLang,targetLang: Doit correspondre à^[a-zA-Z]+(-[a-zA-Z]+)?$, 2 caractères minimum et 11 maximum. Doit être un code de Langues prises en charge.model: Doit être l’une des valeurs de Modèles pris en charge.
Exemples
cURL
curl --location 'https://api.gpttranslator.co/v1/translation/text-translation/api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"text": "hello world",
"sourceLang": "en",
"targetLang": "fr",
"model": "gpt-4.1-mini-2025-04-14"
}'
JavaScript
const response = await fetch(
"https://api.gpttranslator.co/v1/translation/text-translation/api",
{
method: "POST",
headers: {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "hello world",
sourceLang: "en",
targetLang: "fr",
model: "gpt-4.1-mini-2025-04-14",
}),
},
);
const data = await response.json();
console.log(data);
Python
import requests
url = "https://api.gpttranslator.co/v1/translation/text-translation/api"
headers = {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"text": "hello world",
"sourceLang": "en",
"targetLang": "fr",
"model": "gpt-4.1-mini-2025-04-14"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
Types de réponse
Succès 200
{
"message": "Text translation completed successfully",
"error": null,
"data": {
"translatedText": "bonjour le monde",
"originalText": "hello world",
"totalWords": 2,
"isRTL": false,
"tokensConsumed": 3
},
"statusCode": 200
}
Erreur de validation de la requête 400
Les erreurs du middleware de validation sont renvoyées dans ce format :
{
"error": "Invalid source language. Please select a supported language."
}
Autres erreurs de validation possibles :
Invalid target language. Please select a supported language.Invalid model type. Please enter a valid model type e.g. ...Text cannot be empty.Text is required.
En-tête de clé API manquant ou non valide 401
{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 401,
"data": null
}
Erreurs de configuration de la clé API ou de l’utilisateur 400
Clé non valide dans la base de données :
{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 400,
"data": null
}
Utilisateur inactif :
{
"message": "User not found or user is not active",
"error": "User not found or user is not active",
"statusCode": 400,
"data": null
}
Organisation manquante :
{
"message": "Organization Id not found for the user",
"error": "Organization Id not found for the user",
"statusCode": 400,
"data": null
}
Restriction liée à l’abonnement 402
{
"message": "only subscribed users are allowed to use this model",
"error": "only subscribed users are allowed to use this model",
"data": null,
"statusCode": 402
}
Limite de jetons atteinte 402
{
"message": "You have reached the limit of words for translation. Please upgrade your plan to continue using this feature.",
"error": "You have reached the limit of words for translation. Please upgrade your plan to continue using this feature.",
"data": {
"requiredTokens": 123,
"tokens": 45
},
"statusCode": 402
}
Erreur de traitement/serveur 500
{
"message": "Error in text translation for api",
"error": "Detailed server error message",
"data": null,
"statusCode": 500
}