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 时间、状态、代码以及 request_ → Narwhal API 支持团队。切勿提供 API 密钥。
返回 快速入门 或查看 经济数据 API 参考。
此页面对你有帮助吗?