স্কিপ করে মূল কন্টেন্ট এ যান

ডকুমেন্ট অনুবাদ API

API কী ব্যবহার করে সমর্থিত ডকুমেন্ট ফাইল অ্যাসিঙ্ক্রোনাসভাবে অনুবাদ করুন।

কর্মপ্রবাহ​

  1. POST /v1/translation/document-translation/api ব্যবহার করে একটি ডকুমেন্ট আপলোড করুন।
  2. ফেরত পাওয়া translationId সংরক্ষণ করুন।
  3. GET /v1/translation/document-translation-status/{translationId} ব্যবহার করে স্ট্যাটাস পোল করুন।
  4. স্ট্যাটাস completed হলে অনূদিত ফাইল ডাউনলোড করতে data.documentUrl ব্যবহার করুন।

1) ডকুমেন্ট আপলোড করুন​

এন্ডপয়েন্ট​

POST https://api.gpttranslator.co/v1/translation/document-translation/api

প্রমাণীকরণ​

x-api-key: YOUR_API_KEY

কনটেন্ট টাইপ​

multipart/form-data ব্যবহার করুন এবং ফাইলটি file ফিল্ডে পাঠান।

ফর্ম ফিল্ড​

আবশ্যক:

  • file ফাইল
  • sourceLang স্ট্রিং
  • targetLang স্ট্রিং
  • model স্ট্রিং

ঐচ্ছিক:

  • domain স্ট্রিং
  • writingStyle স্ট্রিং
  • tone স্ট্রিং
  • customPrompt স্ট্রিং

ভাষার কোড তালিকাভুক্ত আছে সমর্থিত ভাষা. সমর্থিত মডেল তালিকাভুক্ত আছে সমর্থিত মডেল. সমর্থিত ফাইলের ধরন তালিকাভুক্ত আছে সমর্থিত ডকুমেন্টের ধরন.

ভ্যালিডেশন নিয়ম​

  • sourceLang, targetLang: অবশ্যই ^[a-zA-Z]+(-[a-zA-Z]+)?$ এর সাথে মিলতে হবে, ন্যূনতম ২ অক্ষর, সর্বোচ্চ ১০ অক্ষর।
  • model: অবশ্যই সমর্থিত মডেল-এর কোনো একটি মান হতে হবে।
  • file: অবশ্যই সমর্থিত ডকুমেন্টের ধরন-এর কোনো একটি এক্সটেনশন হতে হবে।

cURL উদাহরণ​

curl --location 'https://api.gpttranslator.co/v1/translation/document-translation/api' \
--header 'x-api-key: YOUR_API_KEY' \
--form 'file=@"/absolute/path/sample.docx"' \
--form 'sourceLang="en"' \
--form 'targetLang="fr"' \
--form 'model="gpt-4.1-mini-2025-04-14"' \
--form 'tone="professional"'

JavaScript উদাহরণ​

const apiKey = "YOUR_API_KEY";
const fileInput = document.querySelector("#fileInput");

const formData = new FormData();
formData.append("file", fileInput.files[0]);
formData.append("sourceLang", "en");
formData.append("targetLang", "fr");
formData.append("model", "gpt-4.1-mini-2025-04-14");
formData.append("tone", "professional");

const uploadRes = await fetch(
"https://api.gpttranslator.co/v1/translation/document-translation/api",
{
method: "POST",
headers: {
"x-api-key": apiKey,
},
body: formData,
},
);

const uploadData = await uploadRes.json();
const translationId = uploadData?.data?.translationId;

if (!translationId) {
console.error("Upload failed:", uploadData);
}

Python উদাহরণ​

import requests

api_key = "YOUR_API_KEY"
url = "https://api.gpttranslator.co/v1/translation/document-translation/api"

headers = {
"x-api-key": api_key
}

data = {
"sourceLang": "en",
"targetLang": "fr",
"model": "gpt-4.1-mini-2025-04-14",
"tone": "professional"
}

with open("/absolute/path/sample.docx", "rb") as f:
files = {
"file": ("sample.docx", f)
}
response = requests.post(url, headers=headers, data=data, files=files)

print(response.status_code)
print(response.json())

সফল রেসপন্স 201​

{
"message": "Document translation added successfully",
"data": {
"translationId": "12345"
},
"error": null,
"statusCode": 201
}

রেসপন্সের ধরন​

মিডলওয়্যার থেকে রিকোয়েস্ট ভ্যালিডেশন ত্রুটি (400):

{
"error": "Invalid model type. Please enter a valid model type e.g. ..."
}

কোনো ফাইল আপলোড করা হয়নি (400):

{
"error": "No file uploaded. Please upload a file for translation.",
"statusCode": 400,
"data": null,
"message": "No file uploaded. Please upload a file for translation."
}

অবৈধ ফাইলের ধরন (400):

{
"error": "Invalid file type. Please upload one of: docx, xlsx, pdf, pptx, srt, vtt, xml, json, yaml, yml, csv, txt, md, html, eml.",
"statusCode": 400,
"data": null,
"message": "Invalid file type. Please upload one of: docx, xlsx, pdf, pptx, srt, vtt, xml, json, yaml, yml, csv, txt, md, html, eml."
}

অবৈধ 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
}

সার্ভার ত্রুটি (500):

{
"error": "Internal server error",
"message": "An error occurred while processing the document translation request. Please try again later.",
"data": null,
"statusCode": 500
}

২) অনুবাদের স্ট্যাটাস যাচাই করুন​

এন্ডপয়েন্ট​

GET https://api.gpttranslator.co/v1/translation/document-translation-status/{translationId}

প্রমাণীকরণ​

x-api-key: YOUR_API_KEY

cURL উদাহরণ​

curl --location 'https://api.gpttranslator.co/v1/translation/document-translation-status/12345' \
--header 'x-api-key: YOUR_API_KEY'

JavaScript উদাহরণ​

const apiKey = "YOUR_API_KEY";
const translationId = "12345";

const statusRes = await fetch(
`https://api.gpttranslator.co/v1/translation/document-translation-status/${translationId}`,
{
headers: {
"x-api-key": apiKey,
},
},
);

const statusData = await statusRes.json();
console.log(statusData);

Python উদাহরণ​

import requests

api_key = "YOUR_API_KEY"
translation_id = "12345"
url = f"https://api.gpttranslator.co/v1/translation/document-translation-status/{translation_id}"

response = requests.get(url, headers={"x-api-key": api_key})

print(response.status_code)
print(response.json())

রেসপন্স ফরম্যাট​

{
"message": "Translation status fetched successfully",
"translationStatus": "completed",
"data": {
"documentUrl": "https://api.gpttranslator.co/v1/translation/download-document/65f0d3f6f0a1c91234567890"
},
"error": null,
"statusCode": 200
}

স্ট্যাটাসের মান​

  • waiting: কাজটি কিউতে আছে।
  • active: অনুবাদ চলছে।
  • completed: অনুবাদ শেষ হয়েছে এবং data.documentUrl পাওয়া যাচ্ছে।
  • failed: অনুবাদ ব্যর্থ হয়েছে। error দেখুন।

রেসপন্সের ধরন​

কিউ আইডি অনুপস্থিত (400):

{
"error": "Queue ID is required",
"message": "Queue ID is required to fetch translation status",
"data": null,
"statusCode": 400
}

অবৈধ 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
}

জব পাওয়া যায়নি (404):

{
"error": "Translation job not found",
"message": "The requested translation job does not exist.",
"data": null,
"statusCode": 404
}

ব্যবহারকারীর কনটেক্সট না থাকলে অননুমোদিত (401):

{
"error": "Unauthorized",
"message": "You are not authorized to access this resource.",
"data": null,
"statusCode": 401
}

অননুমোদিত কিউ অ্যাক্সেস (401):

{
"error": "Unauthorized access to translation status",
"message": "You do not have permission to access the status of this translation job.",
"data": null,
"statusCode": 401
}

কিউ ফলাফল থেকে আসা ব্যবসায়িক নিয়মের ব্যর্থতা (402 উদাহরণ):

{
"message": "Translation status fetched successfully",
"translationStatus": "failed",
"data": null,
"error": "only subscribed users are allowed to use this model",
"statusCode": 402
}

সার্ভার ত্রুটি (500):

{
"error": "Internal server error",
"message": "An error occurred while fetching the translation status. Please try again later.",
"data": null,
"statusCode": 500
}

3) অনূদিত ডকুমেন্ট ডাউনলোড করুন​

স্ট্যাটাস completed হলে স্ট্যাটাস রেসপন্স থেকে documentUrl কল করুন।

এন্ডপয়েন্ট​

GET https://api.gpttranslator.co/v1/translation/download-document/{translationId}

ঐচ্ছিক কোয়েরি:

  • fileType=translated (ডিফল্ট)
  • fileType=source

cURL উদাহরণ​

curl --location 'https://api.gpttranslator.co/v1/translation/download-document/65f0d3f6f0a1c91234567890' \
--header 'x-api-key: YOUR_API_KEY' \
--output translated-file

JavaScript উদাহরণ​

const apiKey = "YOUR_API_KEY";
const translationId = "65f0d3f6f0a1c91234567890";

const downloadRes = await fetch(
`https://api.gpttranslator.co/v1/translation/download-document/${translationId}`,
{
headers: {
"x-api-key": apiKey,
},
},
);

if (!downloadRes.ok) {
const err = await downloadRes.json();
console.error("Download failed:", err);
} else {
const blob = await downloadRes.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "translated-document";
a.click();
URL.revokeObjectURL(url);
}

Python উদাহরণ​

import requests

api_key = "YOUR_API_KEY"
translation_id = "65f0d3f6f0a1c91234567890"
url = f"https://api.gpttranslator.co/v1/translation/download-document/{translation_id}"

response = requests.get(url, headers={"x-api-key": api_key}, stream=True)

if response.status_code == 200:
with open("translated-document", "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
else:
print(response.status_code)
try:
print(response.json())
except Exception:
print("Download failed")

রেসপন্সের ধরন​

সফল (200):

  • বাইনারি ফাইল কনটেন্ট ফেরত দেয়।
  • হেডারে থাকে:
    • Content-Type (অনূদিত ফাইলের ধরন অনুযায়ী)
    • Content-Disposition: attachment; filename="..."

অবৈধ 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
}

ডাউনলোড ত্রুটি:

{ "error": "Invalid translation ID" }
{ "error": "Translation not found or you do not have permission to access it" }
{ "error": "Translation is currently active. Please wait for completion." }
{ "error": "Translated file not available" }

সেরা অনুশীলন​

translationStatus completed বা failed না হওয়া পর্যন্ত প্রতি ২ থেকে ৫ সেকেন্ডে স্ট্যাটাস পোল করুন।