瀏覽全部文件

API 錯誤 處理:錯誤碼、額度與重試

按 HTTP 狀態和穩定的機器可讀代碼處理 Narwhal 問題。

REST 錯誤使用 application/problem+json。MCP 工具錯誤的結構化內容包含相同的問題欄位。

問題回應

分支依據 status 首先以及 code 做進一步判斷。將 detail 視為供人閱讀的診斷文字,而非供程式使用的穩定值。

RFC 9457 問題詳情
{
  "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"
}

狀態與代碼

狀態公開錯誤代碼含義
400invalid_query國家、期間或其他請求輸入無效。
400invalid_cursor分頁游標格式錯誤,或屬於不同的篩選條件。
400invalid_pairfrom和to貨幣相同。
400range_too_large日期視窗超過該路由允許的長度。請傳送更短的視窗。
400invalid_interval該時間間隔不是此路由接受的值。股票 K 線接受 1d 或 1m。
400invalid_name名稱搜尋除 Inc. 之類的詞外,至少需要兩個字母或數字。
401invalid_api_key未提供 Bearer 金鑰,或金鑰格式錯誤、無法識別或未啟用。
402insufficient_credits您的餘額不足以支付此次呼叫。該呼叫未執行,也不收費。請前往以下位置加值額度: top_up_url 於回應中。
403account_paused帳戶因付款爭議未結而被暫停。請聯絡 hello@narwhalapi.com。
403account_pending透過代理程式註冊建立的帳戶正在等待其使用者驗證郵件中的驗證碼。在此之前,監控、webhook、串流票證、團隊邀請和儲值都無法使用。
403api_key_required監控工具和 report_missing_data 需要以 Bearer 權杖的形式提供 API 金鑰。應用程式登入會被拒絕。
404series_not_found沒有已核准的目前或歷史觀測值符合請求。
404resource_not_found所請求的命令資源無法使用。
404event_not_found沒有與該 ID 相符的事件。
404not_found行事曆中沒有與該 ID 相符的發布紀錄。
404route_not_found請求的REST路由不存在。
404not_covered該國家、市場或上市標的不在此資料的涵蓋範圍內。
404tool_not_found請求的 MCP 工具不是公共工具,或不存在。
404calendar_not_published請求的國家與年份的行事曆尚未發布。
404commodity_not_supported此大宗商品代碼不提供現貨價格或價格柱。
404currency_not_supported此大宗商品不以請求的貨幣報價。
404subscription_not_found日曆訂閱ID未知,或不屬於你。
404physical_series_not_found沒有與該ID相符的實物價格序列。
404palmoil_series_not_found沒有與該ID相符的棕櫚油序列。
404webhook_request_failedWebhook目的地未知,或無法重播該傳送。
405method_not_allowed該路由存在,但不接受請求的HTTP方法。
409cursor_expired游標已過期或其快照無法使用。日曆和事件游標也使用此錯誤。請移除游標後重新請求。
409physical_series_ambiguous選取條件符合多個序列。
409limit_reached已達帳戶的 Webhook 目的地數量上限。
410gone價格串流已被移除。POST /v1/prices/stream-ticket 會回傳此錯誤。
413request_too_large請求本文過大。
422out_of_range該日期或年份超出了該曆法系統所涵蓋的範圍。詳細資料中會給出該範圍。
422non_existent_date該日期在該曆法中不存在,例如超過月底的某一天。
422no_sunrise該緯度在當天沒有日出(極晝或極夜),因此當天沒有基於日出的值。
422time_zone_required請在傳送 lat 和 lon 的同時傳送 tz(IANA 時區)。
422location_required傳送 lat 和 lon 時,tz 要用 Asia/Kolkata 以外的時區。
422inputs_unavailable此股票沒有資金成本輸入資料,因此無法計算該數字。
422currency_mismatch申報文件使用的幣別與價格幣別不同。
422risk_free_unavailable該股票所在國家沒有政府殖利率曲線。請傳送 risk_free,即你自己的無風險利率(百分比)。
422not_applicable該指標不適用於此股票,例如銀行的 WACC。
422insufficient_history該股票與其基準共有的報酬率資料太少,無法計算 beta。
429rate_limit_exceeded已達網路或帳戶的每分鐘限制;請在 Retry-After。
500internal_errorNarwhal 無法完成請求。
503api_disabled公開資料存取閘門暫時關閉。
503economics_unavailableNarwhal 無法安全地根據已接受的官方發布滿足請求。
503calendar_coverage_unavailable目前無法安全地提供該行事曆。
503database_unavailable資料儲存系統暫時無法使用。
503rights_state_changingNarwhal 無法確認來源授權在準備回應期間維持不變。
503predictions_unavailable目前無法安全地提供預測資料。
503upstream_unavailable目前無法讀取價格或匯率資料。
503upstream_busy目前無法取得這些資料。請在 Retry-After 給出的秒數後重試。
503palmoil_unavailable目前無法安全提供棕櫚油資料。
503physical_price_unavailable目前無法安全提供實物價格資料。
503physical_reference_unavailable目前無法安全提供實物序列資料。
503rate_limiter_unavailableNarwhal無法檢查你的速率限制。請稍後重試。
503command_unavailable目前無法完成帳戶命令。
503webhook_unavailable目前無法提供Webhook。

額度標頭

每次收費的呼叫都會回傳該次呼叫的費用,以及扣款後的餘額。兩者皆以美元表示,小數六位。

X-Request-IDX-Narwhal-CostX-Narwhal-BalanceX-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-Reset

X-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_limit_exceeded 包括 Retry-After ,且不收費。

當您的額度用完時

餘額不足以支付的呼叫會被拒絕,並回傳 402 insufficient_credits。其中包含該次呼叫的費用、您的餘額,以及加值額度的連結。

402 insufficient_credits
{
  "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_id → Narwhal API 支援。切勿提供 API 金鑰。

返回 快速入門 或查看 經濟資料 API 參考文件。

此頁面對你有幫助嗎?