浏览全部文档

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_keyBearer 密钥缺失、格式错误、未知或未激活。
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 时间、状态、代码以及 request_id → Narwhal API 支持团队。切勿提供 API 密钥。

返回 快速入门 或查看 经济数据 API 参考。

此页面对你有帮助吗?