API 錯誤 處理:錯誤碼、額度與重試
按 HTTP 狀態和穩定的機器可讀代碼處理 Narwhal 問題。
REST 錯誤使用 application/。MCP 工具錯誤的結構化內容包含相同的問題欄位。
問題回應
分支依據 status 首先以及 code 做進一步判斷。將 detail 視為供人閱讀的診斷文字,而非供程式使用的穩定值。
{
"type": "https://narwhalapi.com/problems/series-not-found",
"title": "Economics series not found",
"status": 404,
"detail": "No approved economics observations matched the request.",
"code": "series_not_found",
"request_id": "019d1af4-8f33-7b21-91af-ef535f2dcf50"
}狀態與代碼
| 狀態 | 公開錯誤代碼 | 含義 |
|---|---|---|
400 | invalid_ | 國家、期間或其他請求輸入無效。 |
400 | invalid_ | 分頁游標格式錯誤,或屬於不同的篩選條件。 |
400 | invalid_ | from和to貨幣相同。 |
400 | range_ | 日期視窗超過該路由允許的長度。請傳送更短的視窗。 |
400 | invalid_ | 該時間間隔不是此路由接受的值。股票 K 線接受 1d 或 1m。 |
400 | invalid_ | 名稱搜尋除 Inc. 之類的詞外,至少需要兩個字母或數字。 |
401 | invalid_ | 未提供 Bearer 金鑰,或金鑰格式錯誤、無法識別或未啟用。 |
402 | insufficient_ | 您的餘額不足以支付此次呼叫。該呼叫未執行,也不收費。請前往以下位置加值額度: top_up_url 於回應中。 |
403 | account_ | 帳戶因付款爭議未結而被暫停。請聯絡 hello@narwhalapi.com。 |
403 | account_ | 透過代理程式註冊建立的帳戶正在等待其使用者驗證郵件中的驗證碼。在此之前,監控、webhook、串流票證、團隊邀請和儲值都無法使用。 |
403 | api_ | 監控工具和 report_missing_data 需要以 Bearer 權杖的形式提供 API 金鑰。應用程式登入會被拒絕。 |
404 | series_ | 沒有已核准的目前或歷史觀測值符合請求。 |
404 | resource_ | 所請求的命令資源無法使用。 |
404 | event_ | 沒有與該 ID 相符的事件。 |
404 | not_ | 行事曆中沒有與該 ID 相符的發布紀錄。 |
404 | route_ | 請求的REST路由不存在。 |
404 | not_ | 該國家、市場或上市標的不在此資料的涵蓋範圍內。 |
404 | tool_ | 請求的 MCP 工具不是公共工具,或不存在。 |
404 | calendar_ | 請求的國家與年份的行事曆尚未發布。 |
404 | commodity_ | 此大宗商品代碼不提供現貨價格或價格柱。 |
404 | currency_ | 此大宗商品不以請求的貨幣報價。 |
404 | subscription_ | 日曆訂閱ID未知,或不屬於你。 |
404 | physical_ | 沒有與該ID相符的實物價格序列。 |
404 | palmoil_ | 沒有與該ID相符的棕櫚油序列。 |
404 | webhook_ | Webhook目的地未知,或無法重播該傳送。 |
405 | method_ | 該路由存在,但不接受請求的HTTP方法。 |
409 | cursor_ | 游標已過期或其快照無法使用。日曆和事件游標也使用此錯誤。請移除游標後重新請求。 |
409 | physical_ | 選取條件符合多個序列。 |
409 | limit_ | 已達帳戶的 Webhook 目的地數量上限。 |
410 | gone | 價格串流已被移除。POST /v1/prices/stream-ticket 會回傳此錯誤。 |
413 | request_ | 請求本文過大。 |
422 | out_ | 該日期或年份超出了該曆法系統所涵蓋的範圍。詳細資料中會給出該範圍。 |
422 | non_ | 該日期在該曆法中不存在,例如超過月底的某一天。 |
422 | no_ | 該緯度在當天沒有日出(極晝或極夜),因此當天沒有基於日出的值。 |
422 | time_ | 請在傳送 lat 和 lon 的同時傳送 tz(IANA 時區)。 |
422 | location_ | 傳送 lat 和 lon 時,tz 要用 Asia/Kolkata 以外的時區。 |
422 | inputs_ | 此股票沒有資金成本輸入資料,因此無法計算該數字。 |
422 | currency_ | 申報文件使用的幣別與價格幣別不同。 |
422 | risk_ | 該股票所在國家沒有政府殖利率曲線。請傳送 risk_free,即你自己的無風險利率(百分比)。 |
422 | not_ | 該指標不適用於此股票,例如銀行的 WACC。 |
422 | insufficient_ | 該股票與其基準共有的報酬率資料太少,無法計算 beta。 |
429 | rate_ | 已達網路或帳戶的每分鐘限制;請在 Retry-After。 |
500 | internal_ | Narwhal 無法完成請求。 |
503 | api_ | 公開資料存取閘門暫時關閉。 |
503 | economics_ | Narwhal 無法安全地根據已接受的官方發布滿足請求。 |
503 | calendar_ | 目前無法安全地提供該行事曆。 |
503 | database_ | 資料儲存系統暫時無法使用。 |
503 | rights_ | Narwhal 無法確認來源授權在準備回應期間維持不變。 |
503 | predictions_ | 目前無法安全地提供預測資料。 |
503 | upstream_ | 目前無法讀取價格或匯率資料。 |
503 | upstream_ | 目前無法取得這些資料。請在 Retry-After 給出的秒數後重試。 |
503 | palmoil_ | 目前無法安全提供棕櫚油資料。 |
503 | physical_ | 目前無法安全提供實物價格資料。 |
503 | physical_ | 目前無法安全提供實物序列資料。 |
503 | rate_ | Narwhal無法檢查你的速率限制。請稍後重試。 |
503 | command_ | 目前無法完成帳戶命令。 |
503 | webhook_ | 目前無法提供Webhook。 |
額度標頭
每次收費的呼叫都會回傳該次呼叫的費用,以及扣款後的餘額。兩者皆以美元表示,小數六位。
X-Request-IDX-Narwhal-CostX-Narwhal-BalanceX-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-ResetX-Narwhal-Cost 為該次呼叫從您的餘額中扣除的金額,例如 0.002000 一次經濟數據呼叫所需。 X-Narwhal-Balance 是您的免費額度、贈送額度與付費額度的加總。錯誤以及表示資料未變更的回應不收費。
該 X-RateLimit-* headers describe your request bucket. X-RateLimit-Limit is the size of the bucket, the burst, not a count of requests per minute: 8 while your account has only free credit and 84 once it holds paid credit. The bucket refills at 50 requests a minute on free credit and 500 requests a minute on paid credit. X-RateLimit-Remaining is what is left in it and X-RateLimit-Reset is when it is full again, in UTC (ISO 8601). X-RateLimit-Short-Limit、 X-RateLimit-Short-Remaining 與 X-RateLimit-Short-Reset carry the same values and are sent alongside. A request for several ids is one request. A separate abuse-protection bucket allows 120 requests per minute with a burst of 20 for one network identity, so clients sharing an address can be throttled together. A 429 rate_ 包括 Retry-After ,且不收費。
當您的額度用完時
餘額不足以支付的呼叫會被拒絕,並回傳 402 insufficient_。其中包含該次呼叫的費用、您的餘額,以及加值額度的連結。
{
"type": "https://narwhalapi.com/docs/errors#insufficient_credits",
"title": "Insufficient credits",
"status": 402,
"code": "insufficient_credits",
"detail": "This call costs $0.002. Your balance is $0.000. Top up at https://narwhalapi.com/dashboard/billing",
"top_up_url": "https://narwhalapi.com/dashboard/billing",
"cost_micro": 2000,
"balance_micro": 0
}cost_micro 與 balance_micro are whole millionths of a dollar, so 2000 is $0.002. Do not retry a 402 until the balance has changed. Free credit renews on the first day of each month.
重試行為
- 請勿直接重試
400;請先修正請求。 - 請勿直接重試
402直到您加值額度為止。 - 請勿直接重試
401;不要繼續使用同一把遭拒的金鑰。 - 重試
429只有在Retry-After或X-RateLimit-Reset。 - 冪等請求若收到
500或503,請採用有上限的指數退避與隨機抖動後重試。 - A
404 series_可能只有在發布受支援的官方版本後才可用。not_ found
尋求幫助
請傳送端點、UTC 時間、status、code 和 request_ → Narwhal API 支援。切勿提供 API 金鑰。
返回 快速入門 或查看 經濟資料 API 參考文件。
此頁面對你有幫助嗎?