翻譯任務 API
翻譯文本
翻譯文本並同步返回翻譯結果。
- 完整地址
- https://otranslator.com/api/v1/translation/translateTexts
- 認證
- 需要在 Authorization 請求頭中傳入 API Key
- Content-Type
- application/json
- 錯誤格式
- { "error": "Invalid API key." }
注意事項
該接口會把傳入文本臨時保存為 JSON 文檔並同步處理,適合小批量文本即時翻譯。
帳號積分餘額至少需要 2 credits。若實際費用超過餘額,接口會返回 taskId 和 price,並提示餘額不足。
範例
1curl -X POST 'https://otranslator.com/api/v1/translation/translateTexts' \
2--header 'Authorization: [yourSecretKey]' \
3--header 'Content-Type: application/json' \
4--data '{
5 "texts": [
6 "string"
7 ],
8 "fromLang": "[string]",
9 "toLang": "[string]"
10}'請求參數
響應
| 參數 | 類型 | 預設 | 描述 | 範例 |
|---|---|---|---|---|
| taskId | String | - | 任務ID | - |
| translatedTexts | String[] | - | 翻譯後的文本 | - |
| price | Integer | - | 整體翻譯所需的Credits數 | - |
| usedCredits | Integer | - | 翻譯任務已使用的Credits數 | - |
常見錯誤
401 Missing API key.
The Authorization request header is required.
401 Invalid API key.
The API key does not exist, has been deleted, or is no longer valid.
402 Insufficient credits balance.
The account does not have enough credits to translate the texts.
400 Missing required parameter: fromLang.
Provide fromLang using a language returned by /api/v1/languages.
400 Missing required parameter: toLang.
Provide toLang using a language returned by /api/v1/languages.
400 Missing required parameter: texts.
Provide a non-empty texts array.
400 Failed to translate texts.
The text translation task could not be processed.