翻譯任務 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.