簡介
歡迎使用 i18n-agent 翻譯 API!具備文化適應能力的 AI 驅動翻譯服務
此 API 文件提供所有可用端點、認證方法、請求/回應格式及錯誤代碼的全面資訊。
基礎 URLs
| 環境 | 網址 |
|---|---|
| 開發 | http://localhost:8000 |
| 生產 | https://api.i18nagent.ai |
主要功能
- 🌐 多語言支援 - 將內容翻譯成 10 多種語言並進行文化適應
- 🚀 即時串流 - 用於進度更新的伺服器傳送事件
- 📁 檔案翻譯 - 支援 JSON、YAML、XML、CSV 等
- 🔐 安全認證 - 基於 API 密鑰的認證
- 💳 點數系統 - 按用量付費定價模式
- 🤖 人工智能驅動 - 使用先進的 LLMs 進行準確翻譯
身份驗證
請使用以下程式碼進行身份驗證:
# With shell, you can just pass the correct header with each request
curl "api_endpoint_here" \
-H "Authorization: Bearer i18n_your_api_key_here"
const headers = {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
};
fetch('api_endpoint_here', { headers })
.then(response => response.json())
.then(data => console.log(data));
import requests
headers = {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
response = requests.get('api_endpoint_here', headers=headers)
print(response.json())
package main
import (
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "api_endpoint_here", nil)
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
請確保將
i18n_your_api_key_here替換為你的 API 密鑰。
i18n-agent API 使用 API 密鑰以存取 API。你可以在你的 帳戶儀表板 取得你的 API 密鑰。
所有向伺服器發送的 API 請求都必須在標頭中包含 API 密鑰,如下所示:
Authorization: Bearer i18n_your_api_key_here
端點
點數
取得團隊點數
GET /credits
取得已認證團隊的目前點數餘額
curl -X GET "https://api.i18nagent.ai/credits" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/credits', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/credits',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/credits", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
語言
列出支援的語言
GET /languages
取得所有支援語言的列表及其品質評分
curl -X GET "https://api.i18nagent.ai/languages" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/languages', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/languages',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/languages", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
翻譯工作
取得翻譯歷史
GET /translations
取得翻譯工作的分頁列表,可選用狀態、類型、目標語言和日期範圍篩選
curl -X GET "https://api.i18nagent.ai/translations" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/translations',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/translations", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| page | 否 | 分頁頁碼 |
| limit | 否 | 每頁項目數 |
| status | 否 | 按翻譯狀態篩選 |
| type | 否 | 按翻譯類型篩選 |
| targetLanguages | 否 | 以逗號分隔的目標語言代碼列表以供篩選 |
| fromDate | 否 | 篩選在此日期之後建立的翻譯 |
| toDate | 否 | 篩選在此日期之前建立的翻譯 |
取得翻譯詳情
GET /translations/{id}
按 ID 取得特定翻譯的詳情
curl -X GET "https://api.i18nagent.ai/translations/{id}" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations/{id}', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/translations/{id}',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/translations/{id}", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| id | 是 | 翻譯 ID |
取得翻譯狀態
GET /translations/{id}/status
取得翻譯工作的即時狀態,並提供詳細進度追蹤,包括:進度百分比、已耗時間、預計剩餘時間、檢查點資訊、多語言翻譯的部分完成情況,以及已完成結果的預先簽署的下載 URL。
curl -X GET "https://api.i18nagent.ai/translations/{id}/status" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations/{id}/status', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/translations/{id}/status',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/translations/{id}/status", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| id | 是 | 翻譯 ID |
下載翻譯結果
GET /translations/{id}/result
下載翻譯後的內容
curl -X GET "https://api.i18nagent.ai/translations/{id}/result" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations/{id}/result', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/translations/{id}/result',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/translations/{id}/result", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| id | 是 | 翻譯 ID |
| language | 否 | 特定語言結果的語言代碼 |
下載原始檔案
GET /translations/{id}/original
下載原始已上傳的檔案
curl -X GET "https://api.i18nagent.ai/translations/{id}/original" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations/{id}/original', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/translations/{id}/original',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/translations/{id}/original", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| id | 是 | 翻譯 ID |
從檢查點恢復翻譯
POST /translations/{id}/resume
從特定檢查點或自動從上次成功檢查點恢復失敗或中斷的翻譯
curl -X POST "https://api.i18nagent.ai/translations/{id}/resume" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}'
const response = await fetch('https://api.i18nagent.ai/translations/{id}/resume', {
method: 'POST',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
})
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.post(
'https://api.i18nagent.ai/translations/{id}/resume',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
json={
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
data := map[string]interface{}{
"texts": []string{"Hello, world!", "Welcome to our service"},
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", "https://api.i18nagent.ai/translations/{id}/resume", bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| id | 是 | 翻譯 ID |
請求主體參數
| 參數 | 類型 | 必填 | 描述 |
|---|---|---|---|
| checkpointId | string | 否 | 不透明的檢查點 ID,用於從中恢復 (從狀態端點取得)。如果未提供且 autoDetect 為 true,將從上次成功檢查點恢復。 |
| continueToEnd | boolean | 否 | 恢復後是否繼續處理所有剩餘內容 (預設:true) |
| autoDetect | boolean | 否 | 如果未提供 checkpointId,則自動偵測並從上次成功檢查點恢復 (預設:true) |
取得活躍中的翻譯工作
GET /translations/jobs/active
取得目前活躍中的翻譯工作列表
curl -X GET "https://api.i18nagent.ai/translations/jobs/active" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations/jobs/active', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/translations/jobs/active',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/translations/jobs/active", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
下載翻譯結果
POST /translations/{jobId}/download
下載已完成的翻譯結果。提供按語言分類的預先簽署的下載 URL。URL 於 24 小時後到期。
curl -X POST "https://api.i18nagent.ai/translations/{jobId}/download" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations/{jobId}/download', {
method: 'POST',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.post(
'https://api.i18nagent.ai/translations/{jobId}/download',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("POST", "https://api.i18nagent.ai/translations/{jobId}/download", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| jobId | 是 | 翻譯工作 ID |
下載特定語言的翻譯檔案
GET /translations/{jobId}/files/{language}
下載針對特定目標語言的單一翻譯檔案。直接傳回檔案內容,並附上適當的 Content-Type 標頭。
curl -X GET "https://api.i18nagent.ai/translations/{jobId}/files/{language}" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/translations/{jobId}/files/{language}', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/translations/{jobId}/files/{language}',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/translations/{jobId}/files/{language}", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| jobId | 是 | 翻譯工作 ID |
| language | 是 | 目標語言代碼(例如:es、fr、ja) |
建立具串流進度的翻譯
POST /translations/stream
使用伺服器發送事件 (SSE) 建立翻譯,以獲得即時進度更新。僅支援文字翻譯(不支援檔案)。以 SSE 事件形式返回即時進度更新。
curl -X POST "https://api.i18nagent.ai/translations/stream" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}'
const response = await fetch('https://api.i18nagent.ai/translations/stream', {
method: 'POST',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
})
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.post(
'https://api.i18nagent.ai/translations/stream',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
json={
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
data := map[string]interface{}{
"texts": []string{"Hello, world!", "Welcome to our service"},
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", "https://api.i18nagent.ai/translations/stream", bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
請求主體參數
| 參數 | 類型 | 必填 | 描述 |
|---|---|---|---|
| texts | array | 是 | 要翻譯的文字陣列 |
| targetLanguage | string | 否 | 目標語言代碼(例如:es、fr、ja)— 用於單一語言翻譯 |
| targetAudience | string | 否 | 目標受眾(例如:'general'、'technical'、'casual'、'formal')(預設:general) |
| industry | string | 否 | 行業背景(例如:'technology'、'healthcare'、'finance')(預設:technology) |
| sourceLanguage | string | 否 | 源語言代碼(未提供時自動偵測) |
| region | string | 否 | 特定地區的本地化(例如:Spain、Mexico、Brazil;請以英文值提供) |
| targetLanguages | array | 否 | 目標語言代碼的陣列(例如:[es、fr、zh-CN])— 用於多語言翻譯。不能與 targetLanguage 一起使用。 |
| context | string | 否 | 翻譯的可選附加上下文或指示(例如:'保持技術術語為英文','使用正式語氣','保留品牌名稱') |
| pseudoTranslation | boolean | 否 | 啟用偽翻譯模式以測試 i18n 實現,無需 AI 翻譯且不消耗點數。會轉換帶有重音、括號與可選 CJK 字元的文字,以識別未翻譯的字串並測試 UI 版面。(預設:false) |
| pseudoOptions | object | 否 | 偽翻譯的配置選項(僅在pseudoTranslation為true時使用) |
| skipWarnings | boolean | 否 | 跳過來源文字品質警告並繼續翻譯(預設:false)。當設定為 false 時,會在回應的 validationSuggestions 欄位返回與有問題來源文字相關的警告(例如:難以翻譯的詞語、複數問題、文字擴張問題)。當設定為 true 時,這些警告將被隱藏,以獲得更清晰的輸出。(預設:false) |
取得翻譯費用估算
POST /translations/estimate
計算翻譯所需的字數與點數
curl -X POST "https://api.i18nagent.ai/translations/estimate" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}'
const response = await fetch('https://api.i18nagent.ai/translations/estimate', {
method: 'POST',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
})
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.post(
'https://api.i18nagent.ai/translations/estimate',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
json={
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
data := map[string]interface{}{
"texts": []string{"Hello, world!", "Welcome to our service"},
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", "https://api.i18nagent.ai/translations/estimate", bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
請求主體參數
| 參數 | 類型 | 必填 | 描述 |
|---|---|---|---|
| content | string | 是 | 要分析的內容 |
| fileType | string | 否 | 用於內容分析的檔案類型(預設:txt) |
分析
分析內容以評估翻譯準備情況
POST /analyze
對源文本進行輕量級驗證,以在翻譯前識別潛在問題。返回帶有錯誤代碼的驗證結果,供程式化存取。此端點不消耗積分 - 它運行快速的確定性驗證,無需AI/LLM調用。
curl -X POST "https://api.i18nagent.ai/analyze" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}'
const response = await fetch('https://api.i18nagent.ai/analyze', {
method: 'POST',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
})
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.post(
'https://api.i18nagent.ai/analyze',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
json={
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
data := map[string]interface{}{
"texts": []string{"Hello, world!", "Welcome to our service"},
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", "https://api.i18nagent.ai/analyze", bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
請求主體參數
| 參數 | 類型 | 必填 | 描述 |
|---|---|---|---|
| targetLanguage | string | 是 | 用於翻譯的目標語言代碼 |
| targetAudience | string | 否 | 目標受眾 (預設:一般) |
| industry | string | 否 | 行業背景 (預設:一般) |
| sourceLanguage | string | 否 | 源語言代碼 (未提供時自動偵測) |
| region | string | 否 | 特定地區用於本地化 |
| content | object | 是 | 要分析的內容 (文字、文字陣列或結構化物件) |
| fileType | string | 否 | 可選檔案類型 (如果內容來自檔案) |
命名空間翻譯
上傳翻譯檔案以供命名空間重用
POST /namespaces/{namespace}/translations/upload
上傳現有翻譯檔案到命名空間以供將來重用。這可啟用成本最佳化,透過重用先前翻譯的字串。檔案會被處理,並提取翻譯對以進行快取。
curl -X POST "https://api.i18nagent.ai/namespaces/{namespace}/translations/upload" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}'
const response = await fetch('https://api.i18nagent.ai/namespaces/{namespace}/translations/upload', {
method: 'POST',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
})
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.post(
'https://api.i18nagent.ai/namespaces/{namespace}/translations/upload',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
json={
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
data := map[string]interface{}{
"texts": []string{"Hello, world!", "Welcome to our service"},
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", "https://api.i18nagent.ai/namespaces/{namespace}/translations/upload", bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| namespace | 是 | 命名空間識別碼 (3-50 字元,僅限英數字元 + 連字號/底線) |
取得命名空間翻譯統計資料
GET /namespaces/{namespace}/translations/stats
取得命名空間中已上傳翻譯檔案及快取重用的統計資料
curl -X GET "https://api.i18nagent.ai/namespaces/{namespace}/translations/stats" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/namespaces/{namespace}/translations/stats', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/namespaces/{namespace}/translations/stats',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/namespaces/{namespace}/translations/stats", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| namespace | 是 | 命名空間識別碼 |
列出命名空間中已上傳的翻譯檔案
GET /namespaces/{namespace}/translations/files
取得命名空間中已上傳翻譯檔案的分頁列表
curl -X GET "https://api.i18nagent.ai/namespaces/{namespace}/translations/files" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/namespaces/{namespace}/translations/files', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/namespaces/{namespace}/translations/files',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/namespaces/{namespace}/translations/files", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| namespace | 是 | 命名空間識別碼 |
| limit | 否 | 要返回的檔案最大數量 |
| offset | 否 | 分頁時要跳過的檔案數量 |
刪除已上傳的翻譯檔案
DELETE /namespaces/{namespace}/translations/files/{fileId}
從快取中刪除已上傳的翻譯檔案及所有相關聯的翻譯對
curl -X DELETE "https://api.i18nagent.ai/namespaces/{namespace}/translations/files/{fileId}" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/namespaces/{namespace}/translations/files/{fileId}', {
method: 'DELETE',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.delete(
'https://api.i18nagent.ai/namespaces/{namespace}/translations/files/{fileId}',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("DELETE", "https://api.i18nagent.ai/namespaces/{namespace}/translations/files/{fileId}", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| namespace | 是 | 命名空間識別碼 |
| fileId | 是 | 要刪除的檔案 ID |
上傳平行翻譯檔案
POST /translations/upload-parallel
上傳來源檔案和目標檔案以平行方式進行翻譯對提取和快取。兩個檔案應具有相同的結構和檔案類型。
curl -X POST "https://api.i18nagent.ai/translations/upload-parallel" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}'
const response = await fetch('https://api.i18nagent.ai/translations/upload-parallel', {
method: 'POST',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
})
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.post(
'https://api.i18nagent.ai/translations/upload-parallel',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
},
json={
"texts": [
"Hello, world!",
"Welcome to our service"
],
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
"sourceLanguage": "en",
"region": "Mexico",
"notes": "Keep technical terms in English, use formal tone"
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
data := map[string]interface{}{
"texts": []string{"Hello, world!", "Welcome to our service"},
"targetLanguage": "es",
"targetAudience": "general",
"industry": "technology",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", "https://api.i18nagent.ai/translations/upload-parallel", bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
檔案
從儲存空間下載檔案
GET /files/{filePath}
從本地儲存空間(開發)或 S3(生產)提供檔案。用於存取已上傳和已翻譯的檔案。
curl -X GET "https://api.i18nagent.ai/files/{filePath}" \
-H "Authorization: Bearer i18n_your_api_key_here" \
-H "Content-Type: application/json"
const response = await fetch('https://api.i18nagent.ai/files/{filePath}', {
method: 'GET',
headers: {
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
import requests
import json
response = requests.get(
'https://api.i18nagent.ai/files/{filePath}',
headers={
'Authorization': 'Bearer i18n_your_api_key_here',
'Content-Type': 'application/json'
}
)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.i18nagent.ai/files/{filePath}", )
req.Header.Add("Authorization", "Bearer i18n_your_api_key_here")
req.Header.Add("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
}
上述指令回應的 JSON 結構如下:
{
"translations": [
{
"original": "Hello, world!",
"translated": "¡Hola, mundo!",
"confidence": 0.98
}
],
"metadata": {
"sourceLanguage": "en",
"targetLanguage": "es",
"wordCount": 2,
"creditsUsed": 0.002,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
查詢參數
| 參數 | 必填 | 描述 |
|---|---|---|
| filePath | 是 | 檔案路徑包括任何子目錄(例如:'uploads/test-file.json' 或 'translations/result.json') |
錯誤
i18n-agent API 使用以下錯誤代碼:
| 錯誤代碼 | 含義 |
|---|---|
| 400 | 錯誤請求 -- 你的請求無效。 |
| 401 | 未經授權 -- 你的 API 金鑰無效。 |
| 402 | 需要付款 -- 你的賬戶餘額不足。 |
| 403 | 禁止訪問 -- 你的 API 金鑰已失效或找不到團隊。 |
| 404 | 未找到 -- 找不到指定的資源。 |
| 500 | 內部伺服器錯誤 -- 我們的伺服器出現問題。請稍後再試。 |
| 503 | 服務不可用 -- 我們暫時離線進行維護。請稍後再試。 |
錯誤回應格式
{
"error": "Detailed error message describing what went wrong",
"success": false
}