واجهة API لترجمة النصوص
ترجم النصوص باستخدام GPT Translator API.
نقطة النهاية
POST https://api.gpttranslator.co/v1/translation/text-translation/api
المصادقة
أضف مفتاح API إلى ترويسات الطلب:
x-api-key: YOUR_API_KEY
Content-Type: application/json
محتوى الطلب
الحقول المطلوبة:
textstring: النص المصدر المراد ترجمتهsourceLangstring: رمز اللغة المصدرtargetLangstring: رمز اللغة الهدفmodelstring: اسم نموذج الترجمة
الحقول الاختيارية:
domainstring: التخصص حسب المجالwritingStylestring: تفضيل أسلوب الكتابةtonestring: تفضيل النبرةcustomPromptstring: تعليمات ترجمة مخصصة
رموز اللغات موضحة في اللغات المدعومة. النماذج المدعومة موضحة في النماذج المدعومة.
قواعد التحقق
text: مطلوب. لا يمكن أن يكون فارغًا.sourceLang,targetLang: يجب أن يطابق^[a-zA-Z]+(-[a-zA-Z]+)?$, بحد أدنى حرفان وبحد أقصى 11 حرفًا. ويجب أن يكون الرمز من اللغات المدعومة.model: يجب أن تكون إحدى القيم في النماذج المدعومة.
أمثلة
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())
أنواع الاستجابة
نجاح 200
{
"message": "Text translation completed successfully",
"error": null,
"data": {
"translatedText": "bonjour le monde",
"originalText": "hello world",
"totalWords": 2,
"isRTL": false,
"tokensConsumed": 3
},
"statusCode": 200
}
خطأ التحقق من الطلب 400
تُعاد أخطاء وسيط التحقق بهذا التنسيق:
{
"error": "Invalid source language. Please select a supported language."
}
أخطاء تحقق أخرى محتملة:
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.
ترويسة مفتاح API مفقودة أو غير صالحة 401
{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 401,
"data": null
}
أخطاء إعداد مفتاح API أو المستخدم 400
المفتاح غير صالح في قاعدة البيانات:
{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 400,
"data": null
}
استخدمr not active:
{
"message": "User not found or user is not active",
"error": "User not found or user is not active",
"statusCode": 400,
"data": null
}
المؤسسة غير موجودة:
{
"message": "Organization Id not found for the user",
"error": "Organization Id not found for the user",
"statusCode": 400,
"data": null
}
قيود الخطة 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
}
تم بلوغ حد الرموز 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
}
خطأ في المعالجة/الخادم 500
{
"message": "Error in text translation for api",
"error": "Detailed server error message",
"data": null,
"statusCode": 500
}