翻译任务 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.