Papatono API
Ka whakauru atu te whakamāoritanga kaha ki ōna taupānga ki a tātau API REST ngāwari.
Ka tīmata
Ko te TranslateAPI e whakarato ana i tētahi whakawhitinga REST māmā mō te whakamāori i te kupu i waenganui i ngā reo 180+. Ko ngā pito whakamutunga katoa o te API e hoki ana ki ngā urupare JSON.
https://api.translateapi.ai/api/v1/
Ka tīmata tere
Ka mahi i tātou tono whakamāoritanga tuatahi:
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!"
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program
{
static async Task Main()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add(
"Authorization", "Bearer YOUR_API_KEY"
);
var content = new StringContent(
JsonConvert.SerializeObject(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 = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<dynamic>(result);
Console.WriteLine(data.translated_text); // "Hola, mundo!"
}
}
Tuakiritanga
Whakamau i ōna tono mā te whakamahi i tētahi pātū API. Ka taea e koe te waihanga ngā pātū API mai i ōna Dashboard.
Whakamau i te tohuāhua (E whakarongotia ana)
Authorization: Bearer ta_your_api_key_here
Pānga uiui
https://api.translateapi.ai/api/v1/translate/?api_key=ta_your_api_key_here
Ka whakamāoritia te kupu
Ka whakamāori te kupu ki tētahi reo ūnga kotahi.
POST https://api.translateapi.ai/api/v1/translate/
Ka tono te tinana
| Parameter | Kāhua | E hiahiatia ana | Whakamāramatanga |
|---|---|---|---|
text |
string | He | Te kupu hei whakamāori (ki te 50,000 ngā pūāhua) |
target_language |
string | He* | Target language code (e.g., "es", "fr", "de") |
source_language |
string | Kāore | Source language code. Default: "auto" (auto-detect) |
* Ka whakamahia target_language (pūrākau) mō tētahi reo kotahi, target_languages (taupānga) mō te taumaha. Tirohia Whakamāoritanga Tūtohu-maha.
Ka urupare
{
"translated_text": "Hola, mundo!",
"source_language": "en",
"target_language": "es",
"translations": {
"es": "Hola, mundo!"
},
"character_count": 13,
"translation_time": 0.45
}
Whakamāoritanga Tūtohu-maha
Ka whakamāori te kupu ki ngā reo maha i roto i tētahi tono kotahi. Ka whakamahia te wāhi mutunga kotahi hei whakamāoritanga kotahi.
POST https://api.translateapi.ai/api/v1/translate/
Ka tono te tinana
{
"text": "Hello, world!",
"target_languages": ["es", "fr", "de", "ja"],
"source_language": "en"
}
Ka whakamahia target_languages (taumaha) i te wāhi o target_language (pūrākau) mō ngā ūnga maha.
Ka urupare
{
"source_language": "en",
"translations": {
"es": "Hola, mundo!",
"fr": "Bonjour, monde!",
"de": "Hallo, Welt!",
"ja": "こんにちは、世界!"
},
"character_count": 52,
"translation_time": 2.31
}
Ka whakamāoritia
Ka whakamāoritia ngā kupu maha i te wā kotahi me te tukanga ā-whāiti. Ka tukuna he rōpū me te pōti mō ngā hua.
POST https://api.translateapi.ai/api/v1/translate/batch/
Hipanga 1: Whakahauhau i te rōpū
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"
}'
Ka whakaaetia te urupare (HTTP 202)
{
"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/"
}
Hipanga 2: Pāpāho mō ngā hua
GET https://api.translateapi.ai/api/v1/jobs/{job_id}/
Hei tauira (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"Completed: {processed}/{total} texts in {result.get('processing_time', 0):.1f}s")
translations = result["result_data"]["translations"]
break
elif status == "failed":
print(f"Failed at {processed}/{total}: {result.get('error_message', 'unknown')}")
raise Exception(result.get("error_message", "Translation failed"))
elif status == "pending":
queue_pos = result.get("queue_position", "?")
print(f"Queued (position {queue_pos}) — waiting for GPU worker...")
else:
print(f"[{status}] {processed}/{total} ({progress:.0f}%)")
time.sleep(3)
Ka urupare (e noho ana — i te raupapa, e tūmanako ana mo te GPU)
{
"job_id": "67535b2b-...",
"status": "pending",
"processed_texts": 0,
"total_texts": 3,
"progress_percentage": 0.0,
"queue_position": 3
}
Ka urupare (i te wā o te tukanga)
{
"job_id": "67535b2b-...",
"status": "processing",
"processed_texts": 1,
"total_texts": 3,
"progress_percentage": 33.33,
"queue_position": null
}
Ka oti te urupare (hoatu)
{
"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
}
}
Ka whai i te nekeneketanga o te wā tūturu
Kei roto i ia urupare uiui ngā āpure nekehanga wā-tūturu kia taea ai e koe te mātaki tika i te mea e puta ana ki tōtou rōpū:
| Taiwhenua | Whakamāramatanga |
|---|---|
status |
Kāwanatanga o te mahi o nāianei: pending (i roto i te raupapa, e tūmanako ana mo tētahi kaimahi GPU), processing (te whakamāoritanga hohe), completed, failed |
processed_texts |
Ko te maha o ngā whakamāoritanga takitahi kua oti tae noa ki tēnei wā. Ka whakamāoritia i te wā tūturu i te wā e whakamāoritia ana ia kupu. |
total_texts |
Ko te tau katoa o ngā whakamāoritanga i roto i tēnei rōpū (tuhi × reo ūnga). |
progress_percentage |
Te ōrautanga o te oti (0-100). Kua tātaitai mai i te processed_texts / total_texts. |
queue_position |
Ko tōna tūnga i roto i te raupapa ina "whāiti" te tūnga (1 = ki te taha). Kōaro ina mahia, ka oti rānei. Ka whakamahia tēnei hei whakatau i te wā āwhina me te whakaatu i te tūnga o te raupapa ki ōna kaimahi. |
processing_time |
Ko te wā tukanga katoa i roto i ngā takirua (ka wātea ina oti). |
status He "pending", e mahi ana ngā kaimahi GPU ki ētahi atu rōpū. Tirohia queue_position kia kite ai i te maha o ngā mahi i mua i a koe (1 = ko koe te whai ake). Ka tīmataria ā-pūmau tōna mahi — kāore he mahi e hiahiatia ana, ka noho tonu te porowhita.
Ko nga mahi pai rawa mo nga utu nui
- Ka tukuna te reo ūnga 1 mō ia tono rōpū. Ka mau tonu tēnei i ia rōpū, ā, ka māmā te whai i te nekeneketanga.
- E pupuri ana i ngā rōpū i te 50-100 ngā kupu. He tere ake te oti i ngā rōpū iti iho, ā, ka tuku atu ki a koe ngā whakamātautau arā atu anō.
- E whakahaere ana i te nuinga o ngā mahi rōpū 2. E mahi ana te GPU i ngā rōpū 2 i te taha kotahi — he āhua o ngā mahi tāpiri, ā, kāore e tīmata tere ake.
- I te mutunga o te wā, ka tātari anō i te job_id ōrite i te wāhi o te hoatu i tētahi rōpū hōu. Ka taea tonu te tukatuka i te GPU te mahi taketake.
- E pātai ana i ia 3-5 sekona. Kāore te pātai ā-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō-tō
Ko te rōpū reo maha
Ka whakamāoritia ngā kupu maha ki ngā reo maha i tētahi wā:
{
"texts": ["Hello", "Goodbye"],
"target_languages": ["es", "fr"],
"source_language": "en"
}
Kua oti te hua_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
}
Ka tonoa ngā tohuāhua
| Parameter | Kāhua | E hiahiatia ana | Whakamāramatanga |
|---|---|---|---|
texts |
array | He | Tautuhi o ngā aho hei whakamāori |
target_language |
string | He* | Ko te waehere reo ūnga mō te reo kotahi |
target_languages |
array | He* | He rangatū o ngā waehere reo ūnga mō ngā reo maha |
source_language |
string | Kāore | Source language code. Default: "auto" |
* Hoatu rānei target_language rānei target_languages, ehara i te rua.
job_id. Porowhita GET /api/v1/jobs/{job_id}/ tae noa ki status He "completed", kātahi ka pānuitia result_data mō ngā whakamāoritanga. Ka whakamahia progress_percentage hei whai i te nekeneketanga.
Ka whakamāoritia te tuhinga
Ka whakamāoritia ngā tuhinga katoa me te pupuri i te hanga. E tautoko ana i ngā hanga pūranga maha.
POST https://api.translateapi.ai/api/v1/translate/document/
E tono ana (ngā wāhanga-maha/pūnaha-dātahi)
| Parameter | Kāhua | E hiahiatia ana | Whakamāramatanga |
|---|---|---|---|
file |
file | He | Ko te tuhinga kia whakamāoritia (10MB nui rawa) |
target_language |
string | He | Target language code (e.g., "es", "fr", "de") |
source_language |
string | Kāore | Source language code. Default: "auto" (auto-detect) |
Ko ngā momo pūkete kua tautokona
.txt- Ko ngā faila kupu pūnoa.docx- Kāri Wāhi.pdf- Tuakiri PDF (tae atu ki te karapa).json- Ka whakamāoritia ngā uara mekameka.xml- Ko ngā faila XML
.srt- Ko ngā pūrākau pūāhua.po/.pot- Gettext ngā faila whakamāoritanga.jpg/.jpeg- Kitenga JPEG (OCR).png- Kitenga PNG (OCR).tiff/.tif- Kitenga TIFF (OCR).bmp- Kitenga BMP (OCR).webp- He whakaahua WebP (OCR)
Hei tauira (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"
.txt Ko te rongoā.
Ka urupare
{
"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"
}
Uara tūnga
pending |
Kua whakarewaina te faila, e tūmanako ana kia mahia |
processing |
Ka haere tonu te whakamāoritanga |
completed |
Kua oti te whakamāoritanga, e wātea ana te whakataki |
failed |
Kua pōturi te whakamāoritanga (tirohia error_message) |
GET https://api.translateapi.ai/api/v1/translate/document/{id}/
Ka tirotirohia te tūnga o te whakamāoritanga o tētahi tuhinga, ka whiwhi rānei i te URL whakataki.
Ka urupare
{
"id": 123,
"original_filename": "document.docx",
"status": "completed",
"translated_file_url": "/media/translated/document_es.docx",
"character_count": 5420
}
Kitenga reo
Ka hangaia te kitenga reo ki ia tono whakamāoritanga. source_language to "auto" (Ka waiho rānei) ā, ka hoki te reo i kitea i roto i te urupare.
POST https://api.translateapi.ai/api/v1/translate/
Ka tono te tinana
{
"text": "Bonjour, comment allez-vous?",
"target_language": "en"
}
Ka urupare
{
"translated_text": "Hello, how are you?",
"source_language": "fr",
"target_language": "en",
"translations": {
"en": "Hello, how are you?"
},
"character_count": 28,
"translation_time": 0.52
}
Ko te source_language Ko te āpure i roto i te urupare e whakaatu ana i te reo kua kitea ina whakamahia te kitenga aunoa.
Ka tautokona ngā reo
Ka whiwhi te rārangi o ngā reo katoa e tautokona ana.
GET https://api.translateapi.ai/api/v1/translate/languages/
Ka urupare
{
"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"},
...
]
}
Kāhua whakamāoritanga
Ka whakamahia e tātau ngā tauira whakamāoritanga pūtake tūwhera e haere ana i runga i a tātau ake hanganga GPU. Ko ngā tauira katoa he whakaaetanga hokohoko (Apache 2.0).
| Kāhua | reo | Ko te pai rawa mo |
|---|---|---|
| Helsinki-NLP/opus-mt | 50+ ngā takirua reo | Ko nga reo noa (EN, ES, FR, DE, IT, PT, RU, ZH, JA, etc.) |
| Google MADLAD-400 | 400+ reo | Rerekē ngā reo, te taupānga whānui |
Ka kōwhiria e te API te tauira pai rawa mō tōtou takirua reo. Ka taea e koe te whakapūtā i tētahi engine Huinga:
| Kaikawe | Whakamāramatanga |
|---|---|
"auto" |
Papatono. Ka whakamātau HuggingFace tuatahi, ka hoki ki MADLAD-400 |
"huggingface" |
HuggingFace/MarianMT (te tere rawa, 50+ reo) |
"madlad" |
Ka whakahaua a MADLAD-400 (400+ reo) |
Whakahaere hapa
Ka whakamahia e te API ngā waehere tūnga HTTP paerewa hei tohu i te angitu, te pōhara rānei.
| Waehere | Whakamāramatanga |
|---|---|
200 |
Tērā te angitu |
400 |
Ka hē te tono - Parameter kāore i te tika |
401 |
Kāore i whakaaetia - Papamahi API tē tika, kua ngaro rānei |
402 |
E hiahiatia ana te utu - Kua hipa te waeine āhuahira i ia rā |
429 |
He tokomaha nga tono - Kua hipa te tepe o te mokatere |
503 |
Kāore i te wātea te ratonga ngaio ki te hunga whakamāoritanga. |
Hanganga urupare hapa
{
"error": "daily_limit_exceeded",
"credits_remaining": 0,
"daily_limit": 100000
}
Te mokatere o ngā tepe
He rerekē ngā rohenga e ai ki te mahere. Tirohia. te utu mō ngā taipitopito katoa:
| Rārangi | Huānga/Wā | Ko te utu | |
|---|---|---|---|
| Waihoki | 250,000 | $0 | Ka tāuru i te wātea |
| Ka tīmata | 2,500,000 | $9/m | Whakawhanake |
| Pro | 10,000,000 | $29/m | Whakawhanake |
| Waihoki | 40,000,000 | $79/m | Whakawhanake |
| Tauine | 125,000,000 | $199/m | Whakawhanake |
Ina neke atu koe i tōna tepe, ka whiwhi a koe i tētahi 429 Too Many Requests Ka haere tonu te urupare tae noa ki te marama e whai ake nei, ka whakarewa rānei e koe.
Auto-Scaling Cloud Infrastructure
TranslateAPI runs on dedicated NVIDIA A100 GPU instances with automatic horizontal scaling. When demand increases, additional GPU instances are launched within minutes to maintain fast response times. This means our API can handle virtually unlimited concurrent requests without degradation — from a single request to thousands per minute.