錯誤與速率限制
錯誤格式
所有 API 錯誤都會傳回以下結構的 JSON:
{
"error": "Short error description",
"detail": "Extended description (optional)"
}
部分端點(採用 Django REST Framework 預設格式)也可能傳回:
{
"detail": "Error message"
}
大多數錯誤回應也會包含 correlation_id,與 X-Correlation-ID 回應標頭中的 ID 相同。聯絡客服時,請提供此 ID。以下範例皆省略此欄位。
HTTP 狀態碼
| 狀態碼 | 意義 | 發生情況 |
|---|---|---|
| 200 | 成功 | 請求成功 |
| 400 | 請求錯誤 | 缺少參數或參數無效 |
| 401 | 未經授權 | 驗證權杖缺漏、無效、已撤銷或已過期 |
| 403 | 禁止存取 | 權杖缺少必要的權限範圍或工作空間存取權,或方案未包含 API(api_plan_required) |
| 404 | 找不到資源 | 資源不存在,或工作空間沒有已同步的資料 |
| 405 | 不允許此方法 | 對端點使用了不正確的 HTTP 方法 |
| 422 | 無法處理的實體 | 請求本文驗證失敗 |
| 429 | 請求過多 | 超過速率限制 |
| 500 | 伺服器內部錯誤 | 伺服器發生非預期錯誤 |
| 503 | 服務無法使用 | Elasticsearch 或其他相依服務停止運作 |
速率限制
V1 API(服務權杖)
| 類型 | 限制 | 適用範圍 |
|---|---|---|
| 突發流量 | 每 10 秒 20 次請求 | 每個權杖 |
| 時間區間 | 每 15 分鐘 600 次請求 | 每個權杖 |
使用者 API(JWT)
| 類型 | 限制 | 適用範圍 |
|---|---|---|
| 已通過驗證 | 每分鐘 100 次請求 | 每位使用者 |
| 匿名 | 每分鐘 20 次請求 | 每個 IP |
速率限制標頭
觸發速率限制時,回應會包含:
HTTP/1.1 429 Too Many Requests
Retry-After: 30
處理速率限制:請等待 Retry-After 指定的時間(以秒為單位)後再重試。若持續收到 429 回應,請採用指數退避機制。
常見錯誤情境
身分驗證錯誤
// Missing Authorization header
{"detail": "Authentication credentials were not provided."}
// Invalid or expired JWT
{"detail": "Given token not valid for any token type", "code": "token_not_valid"}
// Service token not found (wrong or mistyped key)
{"detail": "Invalid service token."}
// Revoked service token
{"detail": "Service token is revoked."}
// Expired service token
{"detail": "Service token has expired."}
這些情況都會傳回 401。若服務權杖有效,但方案未包含 API,則會改為傳回 403,並附上錯誤代碼 api_plan_required,詳見下方說明。
權限錯誤
// Token missing the endpoint's scope
{"detail": "Token does not have the required scope."}
// workspace_id missing or not in the token's allowed list
{"detail": "Token does not have access to this workspace."}
// Plan doesn't include the API (Free, Plus)
{
"error": "API for AI agents is part of the Pro and Max plans. This account does not have an active Pro or Max plan. Upgrade at https://ivgraph.com/billing/ and your API keys will work right away.",
"code": "api_plan_required",
"upgrade_url": "https://ivgraph.com/billing/"
}
Pro 和 Max 方案皆包含 API,US$1.99 的 Pro 週方案也包含在內。使用 Free 和 Plus 方案時,任何使用服務權杖的請求,以及建立權杖的操作,都會傳回此 403 錯誤。權杖只會暫停使用,不會刪除:帳號一旦改用 Pro 或 Max 方案,權杖就會立即恢復運作。
驗證錯誤
// Missing required parameter
{"error": "Query parameter \"q\" is required."}
// Invalid UUID format
{"error": "Invalid node_id format."}
// Query too long (V1 API)
{"error": "Query too long (max 256 characters)."}
// Disallowed characters in query
{"error": "Query contains disallowed characters."}
資源錯誤
// Workspace not synced
{"error": "No synced data found for this workspace."}
// Node not found
{"error": "Node not found."}
// Elasticsearch unavailable
{"error": "Search service unavailable"}