Logo

這裡提供完整的開發指南與最佳實踐,幫助您快速上手。

錯誤碼與回報

錯誤處理說明

失敗時統一回傳 error 物件。本章列出 HTTP 狀態碼、各模組錯誤代碼,以及如何用 request_id 回報問題。

統一回應結構

所有錯誤都包在 error 物件中,固定四個欄位:code(錯誤代碼)、message(人類可讀說明)、details(補充資訊)、request_id(本次請求識別碼)。

錯誤回應範例

json
{
  "error": {
    "code": "validation_error",
    "message": "Request validation failed",
    "details": {
      "issues": [
        { "field": "text", "message": "String must contain at most 5000 character(s)" }
      ]
    },
    "request_id": "0af7651916cd43dd8448eb211c80319c"
  }
}

通用錯誤訊息

部分錯誤(例:internal_server_error、service_unavailable、translation_failed、asr_failed)的 message 為通用文字,不包含可供除錯的細節。需要協助時請附上 request_id 回報。

HTTP 狀態碼

  • 200 OK — 請求成功。
  • 400 Bad Request — 參數不符規格。
  • 401 Unauthorized — 金鑰缺失、無效或撤銷。
  • 404 Not Found — 路徑不存在或資源不存在。
  • 409 Conflict — 名稱或詞彙重複。
  • 413 Payload Too Large — 音訊超過上限(JSON/Base64 路徑 raw 1 MB 回 audio_too_long;multipart 檔案 15 MB 回 file_too_large)。
  • 429 Too Many Requests — RPM 或當期額度超限(rate_limited_* / quota_exceeded_*)。
  • 500 Internal Server Error — 伺服器內部錯誤。
  • 502 Bad Gateway — 服務處理失敗(translation_failed / asr_failed)。
  • 503 Service Unavailable — 服務暫時不可用。
  • 504 Gateway Timeout — 處理逾時。

通用錯誤代碼

任何端點都可能遇到:

  • validation_error(400)— 請求 body 驗證失敗,details.issues 列出欄位錯誤。
  • unauthorized(401)— 金鑰缺失、無效或撤銷。
  • not_found(404)— 路徑不存在。
  • internal_server_error(500)— 伺服器內部錯誤。
  • service_unavailable(503)— 服務暫時不可用,請稍後重試。

翻譯模組錯誤代碼

  • model_not_found(400)— 指定的模型代碼不存在。
  • content_policy_violation(400)— 內容違反安全政策。
  • dictionary_type_mismatch(400)— 字庫 ID 指向的類型與參數不符(例如把 forced_replacement 字庫指派給 vocabulary 欄位)。
  • dictionary_not_found(404)— 指定的字庫不存在。
  • translation_failed(502)— 翻譯服務暫時不可用。
  • translation_timeout(504)— 翻譯處理逾時。

語音辨識模組錯誤代碼

  • unsupported_audio_format(422)— 音訊格式無法被辨識。
  • asr_audio_decode_error(422)— Base64 損壞,或內容與宣告的格式不符。
  • asr_content_policy_violation(400)— 內容違反安全政策。
  • audio_too_long(413)— JSON(Base64)路徑音訊超過 raw 1 MB 上限;更大檔案請走 multipart。
  • file_too_large(413)— multipart 上傳檔案超過 15 MB 上限。
  • asr_service_busy(503)— 辨識服務忙碌中;請退避後重試。
  • asr_failed(502)— 辨識服務暫時不可用。
  • asr_timeout(504)— 辨識處理逾時。

字庫模組錯誤代碼

  • dictionary_not_found(404)— 指定的字庫不存在。
  • term_not_found(404)— 指定的詞彙不存在。
  • duplicate_name(409)— 字庫名稱重複。
  • duplicate_term(409)— 詞彙重複(同字庫內)。

日期欄位格式

回應內所有 `created_at` / `updated_at` 為 ISO 8601 UTC,格式 `YYYY-MM-DDTHH:mm:ss.sssZ`;client 需自行以 `new Date(...)` 轉換為本地時區。

回報問題

回報問題時請附上 request_id,我們可從伺服器端紀錄定位本次請求的完整脈絡。每一筆錯誤回應都帶有 request_id 欄位,SSE 串流的 error 事件也帶。

回報範本

請提供:(1) 端點路徑與 HTTP 方法、(2) 請求發生時間(含時區)、(3) error.code、(4) request_id、(5) 重現步驟或最小可重現範例。詳細資料請勿包含金鑰原文。