मुख्य कंटेंट तक स्किप करें

टेक्स्ट अनुवाद 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

अनुरोध बॉडी​

आवश्यक फ़ील्ड:

  • text स्ट्रिंग: अनुवाद के लिए स्रोत टेक्स्ट
  • sourceLang स्ट्रिंग: स्रोत भाषा कोड
  • targetLang स्ट्रिंग: लक्ष्य भाषा कोड
  • model स्ट्रिंग: अनुवाद मॉडल का नाम

वैकल्पिक फ़ील्ड:

  • domain स्ट्रिंग: विषय क्षेत्र
  • writingStyle स्ट्रिंग: लेखन शैली की प्राथमिकता
  • tone स्ट्रिंग: लहजे की प्राथमिकता
  • customPrompt स्ट्रिंग: कस्टम अनुवाद निर्देश

भाषा कोड अलग से समर्थित भाषाएँ में प्रलेखित हैं। समर्थित मॉडल समर्थित मॉडल में प्रलेखित हैं।

सत्यापन नियम​

  • text: आवश्यक। खाली नहीं हो सकता।
  • sourceLang, targetLang: ^[a-zA-Z]+(-[a-zA-Z]+)?$ से मेल खाना चाहिए, न्यूनतम 2 और अधिकतम 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
}

उपयोगकर्ता सक्रिय नहीं है:

{
"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
}