API na preklad textu
Prekladajte text pomocou GPT Translator API.
Endpoint
POST https://api.gpttranslator.co/v1/translation/text-translation/api
Overenie
Pridajte svoj API kľúč do hlavičiek požiadavky:
x-api-key: YOUR_API_KEY
Content-Type: application/json
Telo požiadavky
Povinné polia:
textreťazec: zdrojový text na prekladsourceLangreťazec: kód zdrojového jazykatargetLangreťazec: kód cieľového jazykamodelreťazec: názov prekladového modelu
Voliteľné polia:
domainreťazec: odborná oblasťwritingStylereťazec: preferovaný štýl písaniatonereťazec: preferovaný tóncustomPromptreťazec: vlastné pokyny na preklad
Kódy jazykov sú zdokumentované samostatne v časti Podporované jazyky. Podporované modely sú zdokumentované v časti Podporované modely.
Pravidlá validácie
text: povinné. Nesmie byť prázdne.sourceLang,targetLang: musia zodpovedať^[a-zA-Z]+(-[a-zA-Z]+)?$, najmenej 2 a najviac 11 znakov. Musí ísť o kód z časti Podporované jazyky.model: musí byť jednou z hodnôt v časti Podporované modely.
Príklady
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())
Typy odpovedí
Úspech 200
{
"message": "Text translation completed successfully",
"error": null,
"data": {
"translatedText": "bonjour le monde",
"originalText": "hello world",
"totalWords": 2,
"isRTL": false,
"tokensConsumed": 3
},
"statusCode": 200
}
Chyba validácie požiadavky 400
Chyby validačného middleware sa vracajú v tomto formáte:
{
"error": "Invalid source language. Please select a supported language."
}
Ďalšie možné chyby validácie:
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.
Chýbajúci API kľúč/neplatná hlavička 401
{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 401,
"data": null
}
Chyby API kľúča alebo nastavenia používateľa 400
Neplatný kľúč v databáze:
{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 400,
"data": null
}
Používateľ nie je aktívny:
{
"message": "User not found or user is not active",
"error": "User not found or user is not active",
"statusCode": 400,
"data": null
}
Chýba organizácia:
{
"message": "Organization Id not found for the user",
"error": "Organization Id not found for the user",
"statusCode": 400,
"data": null
}
Obmedzenie plánu 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
}
Dosiahnutý limit tokenov 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
}
Chyba spracovania/servera 500
{
"message": "Error in text translation for api",
"error": "Detailed server error message",
"data": null,
"statusCode": 500
}