跳转到内容

错误码

TokenSupernova 使用标准 HTTP 状态码,并以 OpenAI 兼容格式返回错误信息。

{
"error": {
"message": "提供的 API Key 无效",
"type": "invalid_request_error",
"code": "invalid_api_key"
}
}
状态码含义处理方式
200成功请求已处理
400请求错误检查请求体是否有误
401未授权API Key 缺失或无效
402需要付款账户余额不足 — 充值
404未找到模型或接口不存在
429速率限制降低请求频率
500服务器错误我们的问题 — 重试
503服务不可用模型临时过载 — 退避重试
{
"error": {
"message": "提供的 API Key 无效。请在 api.tokensupernova.com/console 检查你的 Key。",
"type": "auth_error",
"code": "invalid_api_key"
}
}

解决:确认 API Key 以 tsn_live_ 开头,且复制完整。

{
"error": {
"message": "余额不足。请在 api.tokensupernova.com/console 充值。",
"type": "billing_error",
"code": "insufficient_balance"
}
}

解决:在控制台中为账户充值。

{
"error": {
"message": "超出速率限制。请在 60 秒后重试。",
"type": "rate_limit_error",
"code": "rate_limit_exceeded"
}
}

解决:实现指数退避重试。参见 速率限制 →

{
"error": {
"message": "服务器内部错误。请重试。",
"type": "server_error",
"code": "internal_error"
}
}

解决:使用指数退避重试。如问题持续,联系支持

建议对 429 和 5xx 错误实现指数退避:

import time
import random
def retry_with_backoff(fn, max_retries=5, base_delay=1):
for attempt in range(max_retries):
try:
return fn()
except RateLimitError:
delay = base_delay * (2 ** attempt) + random.uniform(0, 1)
time.sleep(delay)
raise Exception("超过最大重试次数")