---
title: "API 错误码：问题响应与额度 | Narwhal API"
description: "API 错误码参考：处理 Narwhal API 的问题响应、稳定的错误代码、额度响应头、速率限制和重试。页面逐项说明每类错误的含义，帮助你在客户端正确处理失败请求。"
url: "https://narwhalapi.com/zh/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 时间、状态、代码以及 `request_id` → Narwhal API 支持团队。切勿提供 API 密钥。

返回 [快速入门](https://narwhalapi.com/zh/docs/quickstart.md) 或查看 [经济数据 API 参考](https://narwhalapi.com/zh/docs/api/economics.md)。

此页面对你有帮助吗?
