TokenLab

文字

建立翻譯

將文字翻譯為目標語言

POST
/v1/translations

概覽

使用 /v1/translations 進行文字對文字翻譯。

這個 endpoint 與 音訊翻譯 不同,後者會接收音訊檔案,並且一律輸出英文文字。

針對 agent workflow,建議先找出目前推薦的翻譯 model:

curl "https://api.tokenlab.sh/v1/models?recommended_for=translation"

接著把選定的 model 明確傳給 /v1/translations。

recommended_for=translation 只適用於文字翻譯(POST /v1/translations),不適用於 音訊翻譯。

請求主體

modelstring必填

由 /v1/models?recommended_for=translation 回傳的翻譯 model ID。

textstring必填

要翻譯的來源文字。

target_languagestring必填

目標語言代碼或語言名稱,取決於 model 支援情況。

source_languagestring

選用的來源語言提示。

mime_typestring預設值: text/plain

來源文字格式。支援值:text/plain、text/html。

userstring

選用的終端使用者識別碼,用於濫用監控與請求追蹤。

回應

textstring

翻譯後的文字。

modelstring

產生翻譯結果的 model。

source_languagestring | null

model 偵測到或接受的來源語言。

target_languagestring

本次請求使用的目標語言。

請求

curl -X POST "https://api.tokenlab.sh/v1/translations" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seed-translation",
    "text": "你好,歡迎使用 TokenLab。",
    "target_language": "en"
  }'

回應

Response
{
  "text": "Hello, welcome to TokenLab.",
  "model": "doubao-seed-translation",
  "source_language": "zh",
  "target_language": "en"
}

授權

BearerAuth
AuthorizationBearer <token>

API Key 驗證。請在 Dashboard > API > API Keys 建立或管理 API 金鑰。

位置: header

請求標頭

X-TokenLab-Delivery-Policy?string

單次請求傳遞策略。會覆寫 API key 與 Workspace 的預設值。系統會自動優先嘗試 TokenLab Verified,並可能在輸出、請求接受或建立持久性資源前切換至 Official 模式一次。

可選值

  • "auto"
  • "verified"
  • "official"

請求主體

application/json

回應

application/json

application/json

application/json

application/json

application/json

application/json