---
title: "API 錯誤 處理與額度 | Narwhal API"
description: "API 錯誤 處理頁面涵蓋 Narwhal API 的問題回應、穩定的錯誤代碼、額度標頭、速率限制，以及遇到錯誤時該如何重試，讓你的程式能依回應內容判斷何時該重試、何時該停止。"
url: "https://narwhalapi.com/zh-tw/docs/errors"
---

# 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"
}
```

## 狀態與代碼

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

## 額度標頭

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

`X-Request-ID` `X-Narwhal-Cost` `X-Narwhal-Balance` `X-RateLimit-Limit` `X-RateLimit-Remaining` `X-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 金鑰。

返回 [快速入門](https://narwhalapi.com/zh-tw/docs/quickstart.md) 或查看 [經濟資料 API 參考文件](https://narwhalapi.com/zh-tw/docs/api/economics.md)。

此頁面對你有幫助嗎?
