翻译任务 API
创建翻译任务
为文档/文件翻译创建新的翻译任务。
- 完整地址
- https://otranslator.com/api/v1/translation/create
- 认证
- 需要在 Authorization 请求头中传入 API Key
- Content-Type
- multipart/form-data
- 错误格式
- { "error": "Invalid API key." }
注意事项
创建任务会立即进入等待队列,并返回 taskId。后续可通过查询任务接口获取进度、费用和下载链接。
账号积分余额至少需要 2 credits 才能创建任务。preview 为 true 时仅生成预览并支付预览积分。
glossary 参数按术语表名称匹配,可重复传入多个同名字段来指定多个术语表。
示例
1curl -X POST 'https://otranslator.com/api/v1/translation/create' \
2--header 'Authorization: [yourSecretKey]' \
3--form 'file=@bitcoin.pdf' \
4--form 'fromLang=English' \
5--form 'toLang=Simplified Chinese' \
6--form 'outputFormat=MD' \
7--form 'bilingualMode=Horizontal' 请求参数
| 参数 | 类型 | 默认 | 描述 | 示例 |
|---|---|---|---|---|
| *file | binary | - |
| bitcoin.pdf |
| *fromLang | String | - |
| English |
| *toLang | String | - |
| Simplified Chinese |
| model | String | - |
| - |
| fileDescription | String | - | 文档描述,通过提供额外的信息,提高翻译的质量,例如添加额外的文档背景信息和其他翻译需求等 | - |
| glossary | String | - | 翻译时使用的术语表名称 | - |
| preview | Boolean | false | 是否仅生成预览仅生成预览时,通过支付 2 credits 来生成文档翻译的预览 | - |
| shouldTranslateImage | Boolean | false |
| - |
| forceOCR | Boolean | false | 是否强制使用 OCR 识别文档内容。开启后会同时启用图片翻译。 | - |
| shouldTranslateFileName | Boolean | true | 是否翻译文件名 | - |
| strictSourceLanguageCheck | Boolean | false | 是否只翻译识别为原语言的文本。开启后会更严格过滤非源语言内容,费用计算也会使用更严格的系数。 | - |
| outputFormat | String | - | 输出格式。传入 MD 时会尝试生成 Markdown 译文。 | MD |
| bilingualMode | String | Horizontal | 双语文件排版方向。Horizontal 表示左右对照,Vertical 表示上下对照。 | Horizontal |
| password | String | - | PDF文件的打开密码 | - |
| ignoreComments | Boolean | false | 是否忽略 DOCX、PPTX、XLSX 的批注 | - |
| ignoreNotes | Boolean | false | 是否忽略 PPTX 的备注 | - |
| ignoreHeadersAndFooters | Boolean | false | 是否忽略 DOCX 的页眉和页脚 | - |
| ignoreHidden | Boolean | false | 是否忽略 PPTX 的隐藏页面 | - |
| ignoreMasters | Boolean | false | 是否忽略 PPTX 的母版文本 | - |
| ignoreSheetNames | Boolean | false | 是否不翻译XLSX的表名 | - |
| extractTextRegExpPattern | String | - |
| - |
| extractTextRegExpFlags | String | - |
| - |
| allowFlip | Boolean | true | 是否允许从右到左语言翻转页面布局。传入 false 时会同时关闭图片翻转。 | - |
| allowFlipImage | Boolean | true | 是否允许从右到左语言翻转图片内容。 | - |
| webhookUrl | String | - | 状态更新时的回调URL,回调的内容包含:{taskId, progress, status} | - |
响应
| 参数 | 类型 | 默认 | 描述 | 示例 |
|---|---|---|---|---|
| taskId | String | - | 任务ID | - |
常见错误
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 create the task.
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 Invalid fromLang: [language]. Use a language returned by /api/v1/languages.
The provided source language is not supported.
400 Invalid toLang: [language]. Use a language returned by /api/v1/languages.
The provided target language is not supported.
400 Missing required file upload: file.
Upload the source document in the file form field.
404 Glossary "[name]" not found.
The specified glossary does not exist or does not belong to the current API account.