API Documentation
Integrate powerful translation into your applications with our simple REST API.
Getting Started
Bidh an TranslateAPI a' toirt eadar-aghaidh REST sìmplidh dhut airson teacsa eadar 180+ cànan a thionndadh. Bidh freagairtean JSON air ais aig gach ceann-phuing API.
1. Faigh do iuchair API
Cruthaich cunntas an-asgaidh agus gineadh an iuchair API agad bhon phrìomh-chlàr:
- Clàraich aig translateapi.ai/signup
- Rach gu Dashboard → API Keys
- Briog air "Create API Key" agus dèan lethbhreac dhen iuchair agad
Tòisichidh iuchraichean API le ta_ an dèidh 56 caractar heicsidheachail.
https://api.translateapi.ai/api/v1/2. Make Your First Request
Cuir an iuchair bhon phrìomh-bhòrd agad an àite YOUR_API_KEY:
curl -X POST https://api.translateapi.ai/api/v1/translate/ \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"text": "Hello, world!",
"target_language": "es"
}'
import requests
response = requests.post(
"https://api.translateapi.ai/api/v1/translate/",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"text": "Hello, world!",
"target_language": "es"
}
)
result = response.json()
print(result["translated_text"]) # "Hola, mundo!"
const response = await fetch("https://api.translateapi.ai/api/v1/translate/", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
text: "Hello, world!",
target_language: "es"
})
});
const result = await response.json();
console.log(result.translated_text); // "Hola, mundo!"
$ch = curl_init("https://api.translateapi.ai/api/v1/translate/");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json"
],
CURLOPT_POSTFIELDS => json_encode([
"text" => "Hello, world!",
"target_language" => "es"
])
]);
$result = json_decode(curl_exec($ch), true);
echo $result["translated_text"]; // "Hola, mundo!"
payload := strings.NewReader(`{
"text": "Hello, world!",
"target_language": "es"
}`)
req, _ := http.NewRequest("POST", "https://api.translateapi.ai/api/v1/translate/", payload)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result["translated_text"]) // "Hola, mundo!"
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
var content = new StringContent(
JsonSerializer.Serialize(new {
text = "Hello, world!",
target_language = "es"
}),
Encoding.UTF8,
"application/json"
);
var response = await client.PostAsync("https://api.translateapi.ai/api/v1/translate/", content);
var result = JsonSerializer.Deserialize<JsonElement>(
await response.Content.ReadAsStringAsync()
);
Console.WriteLine(result.GetProperty("translated_text")); // "Hola, mundo!"
Freagairt
{
"translated_text": "Hola, mundo!",
"source_language": "en",
"target_language": "es",
"translations": {
"es": "Hola, mundo!"
},
"character_count": 13,
"translation_time": 0.45
}
Dearbhadh
Dearbhaich na h-iarrtasan agad le iuchair API. 'S urrainn dhut iuchraichean API a chruthachadh bhon choimpiutair agad dashboard.
Header Authentication (recommended)
Authorization: Bearer ta_your_api_key_here
ApiKey Header
Authorization: ApiKey ta_your_api_key_here
Query Parameter
https://api.translateapi.ai/api/v1/translate/?api_key=ta_your_api_key_here
Atharraich teacsa
Atharraich teacsa gu cànan targaid a-mhàin.
POST https://api.translateapi.ai/api/v1/translate/
Request Body
| Paramadair | Seòrsa | Riatanas | Cur-seachad |
|---|---|---|---|
text |
string | Tha | Teacsa ri eadar-theangachadh (suas ri 50,000 caractar) |
target_language |
string | Tha* | Target language code (e.g., "es", "fr", "de") |
source_language |
string | Chan eil | Source language code. Default: "auto" (auto-detect) |
engine |
string | Chan eil | Inneal-translator: "auto" (ruigsinneach), "huggingface", no "madlad". Seall air na modalan translator. Translation Models. |
* Cleachd target_language (string) airson aon chànan no target_languages (array) airson iomadach. Seall Multi-Target Translation.
Freagairt
{
"translated_text": "Hola, mundo!",
"source_language": "en",
"target_language": "es",
"translations": {
"es": "Hola, mundo!"
},
"character_count": 13,
"translation_time": 0.45
}
source_language no suidhich e air "auto" gus an cànan-thòiseachaidh a lorg gu fèin-obrachail. Thèid an cànan a lorgar a-mach san fhaidhle source_language response field.
Multi-Target Translation
Atharraich teacsa gu diofar chànanan ann an iarrtas a-mhàin. Cleachdas seo an aon cheann-uidhe ri eadar-theangachadh a-mhàin.
POST https://api.translateapi.ai/api/v1/translate/
Request Body
{
"text": "Hello, world!",
"target_languages": ["es", "fr", "de", "ja"],
"source_language": "en"
}
Cleachd target_languages (array) an àite target_language (string) airson iomadh amas.
Freagairt
{
"source_language": "en",
"translations": {
"es": "Hola, mundo!",
"fr": "Bonjour, monde!",
"de": "Hallo, Welt!",
"ja": "こんにちは、世界!"
},
"character_count": 52,
"translation_time": 2.31
}
Batch Translation
Translation multiple texts at once with async processing. Submit a batch and poll for results.
POST https://api.translateapi.ai/api/v1/translate/batch/
Step 1: Submit Batch
curl -X POST https://api.translateapi.ai/api/v1/translate/batch/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"texts": ["Hello", "Goodbye", "Thank you"],
"target_language": "es",
"source_language": "en"
}'
Freagairt (HTTP 202 Accepted)
{
"job_id": "67535b2b-c9e3-4f82-9499-e237edbc1dd8",
"status": "pending",
"total_texts": 3,
"queue_position": 1,
"source_language": "en",
"target_languages": ["es"],
"character_count": 22,
"credits_remaining": -1,
"poll_url": "https://api.translateapi.ai/api/v1/jobs/67535b2b-c9e3-4f82-9499-e237edbc1dd8/"
}
Ceum 2: Poll for Results
GET https://api.translateapi.ai/api/v1/jobs/{job_id}/
Polling Example (Python)
import time, requests
job_id = response.json()["job_id"]
total = response.json()["total_texts"]
headers = {"Authorization": "Bearer YOUR_API_KEY"}
print(f"Batch submitted: {total} texts (job {job_id})")
while True:
result = requests.get(f"https://api.translateapi.ai/api/v1/jobs/{job_id}/", headers=headers).json()
status = result["status"]
processed = result.get("processed_texts", 0)
progress = result.get("progress_percentage", 0)
if status == "completed":
print(f"Done: {processed}/{total} in {result.get('processing_time', 0):.1f}s")
translations = result["result_data"]["translations"]
break
elif status == "failed":
raise Exception(result.get("error_message", "Translation failed"))
elif status == "pending":
print(f"Queued (position {result.get('queue_position', '?')})")
else:
print(f"[{status}] {processed}/{total} ({progress:.0f}%)")
time.sleep(3)
Freagairt (crìochnaichte)
{
"job_id": "67535b2b-...",
"status": "completed",
"processed_texts": 3,
"total_texts": 3,
"progress_percentage": 100.0,
"processing_time": 10.65,
"result_data": {
"translations": ["Hola", "Adiós", "Gracias"],
"source_language": "en",
"target_language": "es",
"character_count": 22,
"processing_time": 10.65
}
}
Real-Time Progress Tracking
| Field | Cur-seachad |
|---|---|
status |
pending (sa chiù, a' feitheamh ri GPU worker), processing (actively translating), completed, failed |
processed_texts |
An àireamh de dh'eadar-theangachaidhean a chaidh a chrìochnachadh gu ruige seo. Ath-nuadhachadh ann an àm fìor nuair a thèid gach teacsa a thionndadh. |
progress_percentage |
Ceud sa cheud de chrìochnachadh (0-100). Air a ríomh bho processed_texts / total_texts. |
queue_position |
An t-ionad agad sa chiùil nuair a tha an staid "air feitheamh" (1 = an ath rud). Null nuair a thèid a phròiseasadh no a chrìochnachadh. Cleachd seo gus ùine feitheamh a mheasadh agus staid na ciùil a shealltainn dha na cleachdaichean agad. |
processing_time |
An ùine phròiseasaidh gu lèir ann an diogan (ri fhaighinn nuair a chrìochnaicheas e). |
Multi-Language Batch
Atharraich iomadh teacsa gu iomadh cànan aig an aon àm:
{
"texts": ["Hello", "Goodbye"],
"target_languages": ["es", "fr"],
"source_language": "en"
}
Crìochnaich an toradh_dàta
{
"translations": [
{"es": "Hola", "fr": "Bonjour"},
{"es": "Adiós", "fr": "Au revoir"}
],
"source_language": "en",
"target_languages": ["es", "fr"],
"character_count": 24,
"processing_time": 2.45
}
Paramadairean iarrtais
| Paramadair | Seòrsa | Riatanas | Cur-seachad |
|---|---|---|---|
texts |
array | Tha | Sreath de shreathan ri eadar-theangachadh |
target_language |
string | Tha* | Còd na cànain-targaid airson cànan singilte |
target_languages |
array | Tha* | Array of target language codes for multiple languages |
source_language |
string | Chan eil | Source language code. Default: "auto" |
* Cuir an dàrna cuid target_language no target_languages, chan e an dà chuid.
Best Practices for Large Workloads
- Seol 1 cànan targaid gach iarrtas batch. Bidh seo a' cumail gach batch luath's a' dèanamh sgrùdadh air an adhartas furasta.
- Cùm bataichean aig 50-100 teacsa. Bidh bataichean nas lugha a' crìochnachadh nas luaithe agus a' toirt dhut ùrachaidhean air adhartas nas trice.
- Cuir a h-uile obair batch a dh'fheumas tu a-steach - bidh ar cnuimhean GPU a' sgèileadh gu fèin-obrachail gus an iarrtas a làimhseachadh. Pròiseasadh na dreuchdan gu co-thaobhach air feadh iomadh instànt.
- Nuair a thèid an ùine seachad, ath-pholl an aon job_id's a bh' ann an àite batch ùr a chur a-steach. Dh'fhaoidte gu bheil an obair thùsail fhathast a' pròiseasadh air an GPU.
- Poll gach 3-5 diogan. Chan urrainn dhut am pròiseas a bhrosnachadh le polls nas trice.
Document Translation
Translation entire documents while preserving formatting. Supports multiple file formats.
POST https://api.translateapi.ai/api/v1/translate/document/
Iarrtas (multipart/form-data)
| Paramadair | Seòrsa | Riatanas | Cur-seachad |
|---|---|---|---|
file |
file | Tha | An sgrìobhainn ri eadar-theangachadh (suas ri 10MB) |
target_language |
string | Tha | Target language code (e.g., "es", "fr", "de") |
source_language |
string | Chan eil | Source language code. Default: "auto" (auto-detect) |
Seòrsan faidhle a tha air an taic
Sgrìobhainnean
.txt- Plain text files.docx- Sgrìoban Word.pdf- Sgrìobhainnean PDF (a' gabhail a-steach scanned)
Data & Localization
.json- Files JSON (translates string values).xml- XML files.srt- Faidhlichean fo-thiotalan.po/.pot- Gettext translation files
Dealbhan (OCR)
.jpg/.jpeg- Dealbhan JPEG (OCR).png- Dealbhan PNG (OCR).tiff/.tif- Dealbhan TIFF (OCR).bmp- Dealbhan BMP (OCR).webp- Dealbhan WebP (OCR)
Samhla (cURL)
# Translate a Word document
curl -X POST https://api.translateapi.ai/api/v1/translate/document/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@document.docx" \
-F "target_language=es" \
-F "source_language=en"
# Translate text from an image (OCR)
curl -X POST https://api.translateapi.ai/api/v1/translate/document/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@scanned_page.jpg" \
-F "target_language=es" \
-F "source_language=en"
Freagairt
{
"id": 123,
"original_filename": "document.docx",
"file_type": "docx",
"source_language": "en",
"target_language": "es",
"status": "completed",
"character_count": 5420,
"translated_file_url": "/media/translated/document_es.docx",
"created_at": "2024-01-15T10:30:00Z",
"completed_at": "2024-01-15T10:30:05Z"
}
GET https://api.translateapi.ai/api/v1/translate/document/{id}/
Sgrùd staid eadar-theangachadh sgrìobhainn no faigh URL an luchdaidh a-nuas.
Luachan staid
pending |
Chaidh am faidhle a luchdadh suas, a' feitheamh ri a phròiseasadh |
processing |
Translation in progress |
completed |
Translation complete, download available |
failed |
Dh'fhàillig an eadar-theangachadh (check error_message) |
Languages supported
Faigh liosta de na cànanan uile a gheibh taic.
GET https://api.translateapi.ai/api/v1/translate/languages/
Freagairt
{
"count": 186,
"results": [
{"iso": "en", "name": "English", "en_label": "English"},
{"iso": "es", "name": "Español", "en_label": "Spanish"},
{"iso": "fr", "name": "Français", "en_label": "French"},
...
]
}
Translation Models
Bidh sinn a' cleachdadh modalan eadar-theangachaidh le còd fosgailte a tha a' ruith air ar bun-structar GPU fhèin. Tha cead-siubhail coimhearsnachd aig a h-uile modal (Apache 2.0).
| Mòdail | Teangachan | As fheàrr airson |
|---|---|---|
| Helsinki-NLP/opus-mt | 50+ language pairs | Teangachan coitcheann (EN, ES, FR, DE, IT, PT, RU, ZH, JA, msaa.) |
| Google MADLAD-400 | 400+ languages | Languages rare, comprehensive coverage |
Bidh an API a' taghadh gu fèin-obrachail a' mhodail as fheàrr airson a' phàrtaidh chànain agad. 'S urrainn dhut roghainn a shònrachadh engine paramadair:
| Inneal | Cur-seachad |
|---|---|
"auto" |
A' bhun-loidhne. Feuch ri HuggingFace a chleachdadh an toiseach, an uair sin thèid air ais gu MADLAD-400 |
"huggingface" |
Force HuggingFace/MarianMT (fastest, 50+ languages) |
"madlad" |
Force MADLAD-400 (400+ languages) |
Cùram nam mearachd
Bidh an API a' cleachdadh còdan stàite HTTP caochlaideach gus soirbheachas no mearachd a shealltainn.
| Còd | Cur-seachad |
|---|---|
| 200 | Shoirbhich leis |
| 202 | Glèidhte — Shoirbhich le ciùil nan dleastanasan batch |
| 400 | Droch iarrtas — Paramadairean mì-dhligheach (teacsa air iarraidh, cànan nach gabh taic rithe, msaa.) |
| 401 | Gun chead - Iuchair API mì-dhligheach no air chall |
| 402 | Tha íocachd ri fhaighinn — Chaidh na creideisichean charactaran a chleachdadh. Ùraich do phlana no ceannaich ùr-ghnàthachadh. |
| 403 | Chaidh a dhiùltadh — chan eil raon ri fhaighinn aig iuchair API no chan eil IP sa liosta-bhuidhe |
| 503 | Service Unavailable - Translation engine temporarily down |
Fòrmat freagairt na mearachd
{
"error": "insufficient_credits",
"credits_remaining": 0
}
Crìochan a' chleachdaidh
TranslateAPI has no request rate limits. All requests are queued and processed by our auto-scaling GPU cluster. Your plan determines your monthly character allowance:
| Plana | Characters/Month | Batch API | Sgrìobhainnean | Praghas | |
|---|---|---|---|---|---|
| Saor | 250,000 | — | — | $0 | Clàraich an-asgaidh |
| Starter | 2,500,000 | $9/mìosan | Subscribe | ||
| Pro | 10,000,000 | $29/mìosan | Subscribe | ||
| Gnìomhachas | 40,000,000 | $79/mìosan | Subscribe | ||
| Sgèilich | 125,000,000 | $199/mìosan | Subscribe | ||
| Enterprise | Unlimited | $499/mìosan | Contact Sales |
Nuair a thèid thu thairis air an teannachadh agad, gheibh thu 402 Payment Required chan eil freagairt ann gus an ath mhìos no gus an ùraich thu.
Auto-Scaling Cloud Infrastructure
Ruitheas TranslateAPI air ionadan GPU NVIDIA A100 air an cur a-steach le sgaoileadh cothromach fèin-obrachail. Nuair a bhios feum air barrachd, thèid ionadan GPU a chur air bhog taobh a-staigh mionaidean gus ùine freagairt luath a chumail suas. Thèid na h-iarrtasan uile a chur sa chiùil agus a phròiseasadh - cuir na céadan de dh'iarrtasan an aon àm is thèid an làimhseachadh uile. Gheibhear tosgaire do thionndadh ann an àm fìor, agus thèid batches a phròiseasadh sa chùlaibh.
A bheil barrachd chreideasan agad?
A bheil thu a' dol às àicheadh caraidean ann am meadhan na mìos? Ceannaich ath-lìonadh creideis aon-ùine gun a bhith a' gluasad do phlana. Seall pacaidean ùrachaidh