错误码参考

本页列出模型调用网关源码声明的 33 个 HTTP 错误码,包括兜底分支。 message 当前主要为英文;中文含义和处理建议见下表。按 error.code 判断,不按文案匹配。 参数校验文案随字段变化,同一 code 可以有多个 message;源码存在不等于每个分支都已逐项实测。 资金 402 与错误契约修复须随对应版本发布后才在线上生效。

错误结构

{
  "error": {
    "code": "model_not_found",
    "message": "The model 'TokenPostie-example-model' does not exist or is not available to this account.",
    "param": "model",
    "type": "invalid_request_error"
  }
}

稳定错误码

CodeHTTP含义客户端建议
invalid_request_error400请求体不合法检查 JSON 和字段类型
invalid_request400/413/415JSON 解析失败、请求体过大或内容类型不支持调整请求体和 Content-Type
unsupported_parameter400参数当前不支持移除或调整参数
missing_api_key401缺少 Bearer token补充 Authorization 头
invalid_api_key401API Key 无效或禁用更换 API Key 或联系管理员
api_key_expired401API Key 已过期更新密钥或有效期
ip_not_allowed403IP 不在 Key 白名单检查出口 IP 和白名单
model_access_denied403API Key 无权调用目标模型检查模型授权
project_policy_disabled403项目策略已禁用联系项目管理员
project_model_access_denied403项目无权调用该模型检查项目模型授权
customer_kyc_not_submitted403尚未提交实名资料提交实名资料
customer_kyc_pending403实名待审核等待审核
customer_kyc_rejected403实名未通过更新资料后重新提交
customer_kyc_expired403实名凭证过期更新实名资料
model_not_found404当前账户下没有可用模型 route先调用 /v1/models
insufficient_quota402资金不足,包括无法预留本次费用充值或调整授信,不要自动重试
credit_limit_exceeded402后付费授信达到上限结算或提高授信,不要自动重试
rate_limit_exceeded429超过 RPM/TPM/QPM按 Retry-After 降速
concurrency_limit_exceeded429进行中的请求超过并发上限按 Retry-After 等待
provider_unavailable503目标模型服务暂不可用稍后重试或切换模型
session_affinity_target_unavailable503strict 会话亲和目标不可用稍后重试,或由项目管理员切换为 soft/off
upstream_authentication_error502平台上游鉴权失败联系 TokenPostie 运营处理
upstream_request_rejected400目标模型无法处理当前请求检查参数和模型能力
upstream_request_failed502无法进一步分类的上游请求失败记录请求 ID 后排查
upstream_rate_limited503上游容量、频率或平台额度暂时受限退避后重试;持续出现时联系运营
upstream_model_unavailable503上游模型暂不可用稍后重试或切换模型
upstream_service_unavailable503上游服务或网络暂不可用退避后重试
upstream_timeout504上游请求超时确认幂等后重试
internal_error500平台内部处理失败保留请求 ID,稍后重试;持续出现时联系运营
authentication_failed401框架层鉴权失败兜底检查登录或鉴权状态
permission_denied403框架层权限拒绝兜底检查访问权限
not_found404框架层资源不存在兜底检查请求路径和资源
customer_kyc_required403实名要求的兜底拒绝完成实名后重试

实际返回文案

下表为固定英文原文或参数模板。{model}、{seconds} 是运行时值,不是字面文本。 HTTP 错误对象的 param 无特定参数时为 null;参数校验可能返回字段路径。

Codemessage 原文或模板
invalid_request_error随字段变化,例如 Output token limit exceeds the configured model maximum of {max}.;见参数校验表
invalid_requestThe request could not be processed.
unsupported_parameter随模型和参数变化;见参数校验表
missing_api_keyYou must provide a TokenPostie API key in the Authorization header.
invalid_api_keyThe provided TokenPostie API key is invalid or disabled.
api_key_expiredThe provided TokenPostie API key has expired.
ip_not_allowedThis API key is not allowed from the current client IP.
model_access_deniedThe model '{model}' is not enabled for this API key.
project_policy_disabledThe project policy for this API key is disabled.
project_model_access_deniedThe model '{model}' is not enabled for this project.
customer_kyc_not_submittedCustomer real-name verification is required before using this API key.
customer_kyc_pendingCustomer real-name verification is pending review.
customer_kyc_rejectedCustomer real-name verification was rejected.
customer_kyc_expiredCustomer real-name verification has expired.
customer_kyc_requiredCustomer real-name verification is required before using this API key.
insufficient_quotaYou exceeded your current TokenPostie quota. Please recharge or increase your balance.;费用预留失败时:The available balance is too low for this request reservation.
credit_limit_exceededYou exceeded your TokenPostie postpaid credit limit. Please settle your balance or increase credit.
rate_limit_exceededRate limit exceeded. Please retry after {seconds} seconds.;框架兜底:The request rate limit was exceeded.
concurrency_limit_exceededThe API key concurrency limit has been reached.
model_not_foundThe model '{model}' does not exist or is not available to this account.
provider_unavailableThe selected model is temporarily unavailable.
session_affinity_target_unavailableThe strict session affinity target is temporarily unavailable.
upstream_authentication_errorTokenPostie could not authenticate with the upstream provider.
upstream_request_rejectedThe request could not be processed by the selected model. Check the request parameters and model capabilities.
upstream_request_failedThe upstream provider request failed.
upstream_rate_limitedUpstream capacity is temporarily limited. Please retry later.
upstream_model_unavailableThe requested model is temporarily unavailable.
upstream_service_unavailableThe upstream provider is temporarily unavailable. Please retry later.
upstream_timeoutThe upstream provider timed out. Please retry later.
internal_errorThe request could not be completed due to an internal error.
authentication_failedAuthentication failed.
permission_deniedThe request is not permitted.
not_foundThe requested resource was not found.

参数校验文案

这类文案不是额外稳定错误码;通常归入 400 / invalid_request_error 或 unsupported_parameter, Messages 的部分原生控制拒绝只有 error.type、message、param,没有独立 code。

返回文案 / 类型含义与处理
Tool messages require tool_call_idtool 消息缺少对应调用 ID
Null content requires assistant tool callsnull 内容仅允许用于带 tool_calls 的 assistant 消息
Only assistant messages may contain tool callstool_calls 不能放在其他角色消息中
Specify only one output token limit不要同时传 max_tokens 和 max_completion_tokens
Output token limit exceeds the configured model maximum of {max}.输出预算超过已声明模型上限
This model requires a native protocol route; protocol conversion is disabled.当前模型不能自动转换到其他协议,改用模型声明的原生入口
Responses requests must use max_output_tokens, not Chat token limit parameters.Responses 使用 max_output_tokens
Provide input or instructionsResponses 缺少输入或 instructions
This route does not support native Messages effort control.当前 Messages route 不支持 output_config effort
The selected model does not enforce thinking.budget_tokens. Use output_config.effort and max_tokens instead.不要传不会被该模型执行的 thinking.budget_tokens
The selected model does not apply top_k.当前模型不执行 top_k
字段、类型、枚举或组合校验动态文案读取 param 和字段说明;Zod 可能按字段生成不同 message,不能枚举全部运行时字符串

全部显式输入校验文案与字段模板见 参数错误文案,由源码生成并校验一致性。

类型与传输差异

OpenAI-compatible error.type 按类别区分:401 为 authentication_error,权限/实名为 permission_error,资金为 insufficient_quota,429 为 rate_limit_error,参数/模型不存在为 invalid_request_error,平台与上游服务故障为 server_error。

Messages 采用 {"type":"error","error":{"type":"...","message":"...","code":"..."}}: 401 对应 authentication_error;402/403 对应 permission_error;404 对应 not_found_error; 429 对应 rate_limit_error;5xx 对应 api_error;其他通常为 invalid_request_error。 流式错误在已开始的 HTTP 200 内发送终止事件,不再改变 HTTP 状态。

Responses 流式错误是扁平事件,例如:

event: error
data: {"type":"error","code":"upstream_rate_limited","message":"Upstream capacity is temporarily limited. Please retry later.","param":null,"sequence_number":3}

WebSocket 还有 invalid_json(消息无法解析)、unsupported_type(仅支持 chat 类型)、 missing_model(缺少模型)及 internal_error(内部处理失败);这是消息内 code,不是 HTTP 状态。 gRPC 使用 gRPC status,并在 tokenpostie-error-code 元数据中保留平台 code;资金为 FAILED_PRECONDITION,鉴权为 UNAUTHENTICATED,限流为 RESOURCE_EXHAUSTED。

上游错误边界

资金类错误从旧版 429 调整为 402,错误码和 OpenAI-compatible 错误类型保持稳定;402 是 TokenPostie 的平台约定。 402 不返回 Retry-After,补充资金前重试不会解决问题。429 只用于请求频率、Token 或并发限制。 Messages 资金拒绝返回 type: "error" 外层和 error.type: "permission_error",并保留资金错误码。

TokenPostie 不会把上游原始错误 code、message、raw body、request ID 或网络异常 cause 直接返回给 API 用户或客户管理员。最终用户侧应使用 TokenPostie 的 error.code 做稳定处理。

流式响应已经开始后,最初的 HTTP 状态仍可能是 200。客户端还必须读取终止 SSE 事件:OpenAI-compatible 流使用 data: {"error": ...},Responses 和 Anthropic 流使用 event: error。

请求日志排障

请求失败时,先保留响应里的 request id 或客户控制台请求日志中的请求 ID,再按以下顺序排查:

所有 HTTP 响应通过 x-tokenpostie-request-id 返回平台生成的请求 ID,不使用客户或上游提供的 ID。

请求路径完全没有匹配路由时,框架默认 404 可返回 {"message":"Route GET:/path not found","error":"Not Found","statusCode":404},不带统一 code。 这与异常处理器的 not_found 兜底分支不同。先检查 URL 和 HTTP 方法,不要把未知路径响应当成模型错误。

  1. 在客户控制台打开请求日志,确认模型、API Key、项目、HTTP 状态和 error.code。
  2. 如果是 model_not_found 或 model_access_denied,重新调用 GET /v1/models,只使用返回的模型 id。
  3. 如果是 rate_limit_exceeded,按当前 API Key 的 RPM、TPM、QPM 限额降速。
  4. 如果是 insufficient_quota 或 credit_limit_exceeded,检查余额、授信和付款状态。
  5. 联系 TokenPostie 运营时只提供请求 ID、错误码和时间,不提供完整 API Key。

相关排障步骤见 排障与安全。 客户后台的登录、组织、API Key、发票和通知错误见 客户后台错误。