开始
TranslateAPI为翻译180+语言之间的文本提供了一个简单的REST界面。所有 API 端点都返回 JSON 响应 。
1. Get Your API Key
Create a free account and generate your API key from the dashboard:
- Sign up at translateapi.ai/signup
- Go to 仪表板 → APIP 键键
- Click "Create API Key" and copy your key
API keys start with ta_ followed by 56 hex characters.
https://api.translateapi.ai/api/v1/2. Make Your First Request
Replace YOUR_API_KEY with the key from your dashboard:
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!"
响应
{
"translated_text": "Hola, mundo!",
"source_language": "en",
"target_language": "es",
"translations": {
"es": "Hola, mundo!"
},
"character_count": 13,
"translation_time": 0.45
}
验证
使用 API 密钥验证您的请求。 您可以从您的 API 密钥创建 API 密钥 仪表板.
页头验证( 建议)
Authorization: Bearer ta_your_api_key_here
ApiKey Header
Authorization: ApiKey ta_your_api_key_here
查询参数
https://api.translateapi.ai/api/v1/translate/?api_key=ta_your_api_key_here
翻译文本
将文本翻译为单一目标语言 。
POST https://api.translateapi.ai/api/v1/translate/
请求机构
| 参数 | 类型 | 所需 | 说明 |
|---|---|---|---|
text |
string | 是 是 | 要翻译的文本 (最多 50,000 个字符) |
target_language |
string | 是* | Target language code (e.g., "es", "fr", "de") |
source_language |
string | 否 无 | Source language code. Default: "auto" (auto-detect) |
engine |
string | 否 无 | Translation engine: "auto" (default), "huggingface", or "madlad". See Translation Models. 翻译模型. |
* 使用 target_language 单语或单语(字符串),或 target_languages 多重 (数组) 。 见 多目标翻译.
响应
{
"translated_text": "Hola, mundo!",
"source_language": "en",
"target_language": "es",
"translations": {
"es": "Hola, mundo!"
},
"character_count": 13,
"translation_time": 0.45
}
source_language or set it to "auto" to automatically detect the source language. The detected language is returned in the source_language response field.
多目标翻译
在单一请求中将文本翻译为多种语言。 使用与单一翻译相同的端点 。
POST https://api.translateapi.ai/api/v1/translate/
请求机构
{
"text": "Hello, world!",
"target_languages": ["es", "fr", "de", "ja"],
"source_language": "en"
}
使用 target_languages (阵列)而不是 target_language (string) 针对多个目标。
响应
{
"source_language": "en",
"translations": {
"es": "Hola, mundo!",
"fr": "Bonjour, monde!",
"de": "Hallo, Welt!",
"ja": "こんにちは、世界!"
},
"character_count": 52,
"translation_time": 2.31
}
批批次翻译
立即翻译多个文本并进行同步处理。 提交批次和民意测验结果 。
POST https://api.translateapi.ai/api/v1/translate/batch/
步骤1:提交批次
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"
}'
答复(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/"
}
步骤2:结果投票
GET https://api.translateapi.ai/api/v1/jobs/{job_id}/
投票示例 (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)
答复(已完成)
{
"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 | 说明 |
|---|---|
status |
pending (queued, waiting for a GPU worker), processing (actively translating), completed, failed |
processed_texts |
Number of individual translations completed so far. Updates in real time as each text is translated. |
progress_percentage |
Completion percentage (0-100). Calculated from processed_texts / total_texts. |
queue_position |
Your position in the queue when status is "pending" (1 = next up). Null when processing or completed. Use this to estimate wait time and show queue status to your users. |
processing_time |
Total processing time in seconds (available when completed). |
多语言批次
立即将多种文本翻译成多种语言:
{
"texts": ["Hello", "Goodbye"],
"target_languages": ["es", "fr"],
"source_language": "en"
}
已完成结果_ 数据
{
"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
}
请求参数
| 参数 | 类型 | 所需 | 说明 |
|---|---|---|---|
texts |
array | 是 是 | 要翻译的字符串排列 |
target_language |
string | 是* | 单一语言目标语言代码 |
target_languages |
array | 是* | 多种语文目标语言代码的排列 |
source_language |
string | 否 无 | Source language code. Default: "auto" |
* 提供 target_language 或 target_languages不是两者兼而有之
Best Practices for Large Workloads
- Send 1 target language per batch request. This keeps each batch fast and makes progress easy to track.
- Keep batches at 50-100 texts. Smaller batches complete faster and give you more frequent progress updates.
- Submit as many batch jobs as you need — our GPU cluster auto-scales to handle demand. Jobs are processed in parallel across multiple instances.
- On timeout, re-poll the same job_id instead of submitting a new batch. The original job may still be processing on the GPU.
- Poll every 3-5 seconds. More frequent polling does not speed up processing.
文件翻译
在保存格式的同时翻译整个文档。 支持多个文件格式 。
POST https://api.translateapi.ai/api/v1/translate/document/
请求(多部分/格式数据)
| 参数 | 类型 | 所需 | 说明 |
|---|---|---|---|
file |
file | 是 是 | 要翻译的文档( 最大 10MB) |
target_language |
string | 是 是 | Target language code (e.g., "es", "fr", "de") |
source_language |
string | 否 无 | Source language code. Default: "auto" (auto-detect) |
支持的文件类型
Documents
.txt- 纯文本文件.docx- 单词文档.pdf- PDF文件(包括扫描)
Data & Localization
.json- JSON 文件( 翻译字符串值).xml- XML 文件.srt- 字幕文件.po/.pot- Gettext 翻译文件
Images (OCR)
.jpg/.jpeg- JPEG 图像( OCR).png- PNG 图像( OCR).tiff/.tif- TIFF 图像(OCR).bmp- BMP 图像( OCR).webp- WebP 图像( OCR)
示例(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"
响应
{
"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}/
检查文档翻译的状态或检索下载的 URL 。
状况价值
pending |
文件已上传, 等待处理 |
processing |
翻译中 |
completed |
翻译完成,可下载 |
failed |
翻译失败( 检查错误(_Message) |
辅助语言
获取所有支持语言的清单 。
GET https://api.translateapi.ai/api/v1/translate/languages/
响应
{
"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"},
...
]
}
Submit Corrections
Suggest a better translation for a given source text. Corrections enter a moderation queue; once approved by our team they surface as "Community Verified" translations for that text.
https://translateapi.ai/api/v1/ (not the api. translation host), and requires an API key.POST https://translateapi.ai/api/v1/suggestions/
请求机构
| Parameter | 类型 | 说明 |
|---|---|---|
source_text |
string | The original text that was translated. |
source_language |
string | Source language code (e.g. "en"). |
target_language |
string | Target language code (e.g. "es"). |
machine_translation |
string | The machine translation you are correcting. |
suggested_translation |
string | Your improved translation (must differ from machine_translation). |
Example Request
curl -X POST https://translateapi.ai/api/v1/suggestions/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_text": "Hello, world!",
"source_language": "en",
"target_language": "es",
"machine_translation": "Hola, mundo!",
"suggested_translation": "¡Hola, mundo!"
}'
响应
{
"id": 4213,
"status": "pending",
"created": true,
"message": "Correction submitted for review."
}
Re-submitting the same source/language pair updates your existing suggestion instead of creating a duplicate (returns 200 with "created": false).
翻译模型
我们使用在自己的GPU基础设施上运行的最先进的开放源码翻译模型。 所有模型都有商业许可(Apache 2. 0)。
| 型 型 | 语言 | 最佳 |
|---|---|---|
| Helsinki-NLP/opus-mt | 50+语文配对 | 通用语言(EN、ES、FR、DE、IT、PT、RU、ZH、JA等) |
| Google MADLAD-400 | 400+语言 | 少数语言,全面覆盖 |
API 自动为您的语言配对选择最佳模式。您可以选择指定 engine 参数 :
| 引擎 | 说明 |
|---|---|
"auto" |
默认值。 首先, Tries Huggging Face 将返回到 MADLAD- 400 。 |
"huggingface" |
Huggging Face/MarimanMT(最快,50+语言) |
"madlad" |
部队MADLAD-400(400+语言) |
错误处理
API使用标准 HTTP 状态代码来表示成败。
| 《法典》 | 说明 |
|---|---|
| 200 | 成功 |
| 202 | Accepted — Batch job queued successfully |
| 400 | Bad Request — Invalid parameters (missing text, unsupported language, etc.) |
| 401 | 未授权 - 无效或丢失 API 密钥 |
| 402 | Payment Required — Character credits exhausted. Upgrade your plan or purchase a top-up. |
| 403 | Forbidden — API key lacks required scope or IP not in whitelist |
| 503 | 未可用服务 - 临时关闭翻译引擎 |
错误反应格式
{
"error": "insufficient_credits",
"credits_remaining": 0
}
Usage Limits
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:
| 计划 | 特征/月 | Batch API | Documents | 价格 | |
|---|---|---|---|---|---|
| 自由 | 250,000 | — | — | $0 | 签署自由 |
| 启动器 | 2,500,000 | $9/以 单位 | 订阅 | ||
| 职业 | 10,000,000 | $29/以 单位 | 订阅 | ||
| 商业商 | 40,000,000 | $79/以 单位 | 订阅 | ||
| 比例分摊比额表 比例比 | 125,000,000 | $199/以 单位 | 订阅 | ||
| Enterprise | Unlimited | $499/以 单位 | Contact Sales |
当你超过极限时,你会得到 402 Payment Required 回复到下个月或升级 。
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. All requests are queued and processed — send hundreds of concurrent requests and they'll all be handled. Real-time translations get priority, batch jobs process in the background.
Need More Credits?
Run out of characters mid-month? Purchase a one-time credit top-up without changing your plan. View top-up packs