Appearance
本页整理 Kimi API 全部错误码(HTTP 400/401/403/404/429/500),分析每种错误的触发原因并给出具体解决步骤,帮助你快速定位接口调用问题。
Kimi API 错误码
错误响应格式
所有错误响应遵循统一格式:
json
{
"error": {
"type": "authentication_error",
"message": "Invalid Authentication"
}
}使用 OpenAI SDK 时,错误会自动抛出为对应的异常类型。
错误码速查
400 Bad Request
| 错误类型 | 触发原因 | 解决方案 |
|---|---|---|
content_filter_error | 输入或输出触发内容过滤 | 修改敏感内容,避免违规表述 |
invalid_request_error | 请求格式错误或 token 超限 | 检查参数格式,减少 prompt 长度 |
file_size_error | 文件超过大小限制 | 压缩文件或分段上传 |
file_count_error | 单次上传文件数量超限 | 减少文件数量 |
content_filter 踩坑:不只是输入会触发过滤,模型的输出也可能触发。如果你的请求内容看起来合规但仍然被过滤,可以检查 system prompt 是否有敏感表述。
401 Unauthorized
Invalid Authentication最常见原因:
- 使用了错误平台的 Key —
platform.kimi.ai(旧)和platform.kimi.com(新)的 Key 不通用 - Key 已失效或被删除
- 没有指定
baseURL,导致 Key 发送到了 OpenAI 的节点
typescript
// ✅ 确保 baseURL 和 apiKey 来自同一平台
const client = new OpenAI({
apiKey: process.env.MOONSHOT_API_KEY, // platform.kimi.com 的 Key
baseURL: "https://api.moonshot.cn/v1",
});403 Forbidden
The API you are accessing is not open通常是访问了未开放的 Beta 功能,或账号权限不足。确认 API 是否已对你的账号开放。
404 Not Found
Not found the model {model-id} or Permission denied排查步骤:
- 检查模型名拼写(区分大小写,如
kimi-k2.6不是kimi-k2) - 确认模型未下线(kimi-k2 系列将于 2026-05-25 下线)
- 确认
baseURL正确
429 Rate Limit / Quota
| 错误信息 | 原因 | 解决方案 |
|---|---|---|
The engine is currently overloaded | 服务器过载 | 稍后重试(指数退避) |
Your account is suspended | 余额不足或账号被暂停 | 充值或联系客服 |
rate_limit_reached_error | 请求超过速率限制 | 降低并发,或升级账号等级 |
rate_limit_reached_error 特殊场景:如果你确信自己的请求量不高但仍触发限速,检查是否用了错误的 api_key(比如其他账号的 Key)。不同账号的配额是独立的。
OpenAI SDK 默认重试:SDK 失败时默认重试 2 次,可能瞬间消耗 3 倍 RPM:
typescript
const client = new OpenAI({
apiKey: process.env.MOONSHOT_API_KEY,
baseURL: "https://api.moonshot.cn/v1",
maxRetries: 0, // 关闭自动重试,自己控制
});500 Server Error
服务端内部错误(文件提取失败、临时故障等),通常建议稍后重试。如果持续出现,联系 Kimi 客服。
在代码中处理错误
typescript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.MOONSHOT_API_KEY,
baseURL: "https://api.moonshot.cn/v1",
maxRetries: 0,
});
async function callKimi(prompt: string) {
try {
return await client.chat.completions.create({
model: "kimi-k2.6",
messages: [{ role: "user", content: prompt }],
});
} catch (error) {
if (error instanceof OpenAI.APIError) {
console.error(`HTTP ${error.status}: ${error.message}`);
if (error.status === 429) {
// 速率限制:等待后重试
await new Promise((r) => setTimeout(r, 1000));
}
}
throw error;
}
}不使用 SDK 时的错误处理
typescript
const response = await fetch("https://api.moonshot.cn/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.MOONSHOT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "kimi-k2.6",
messages: [{ role: "user", content: "hello" }],
}),
});
if (!response.ok) {
const error = await response.json();
console.error(response.status, error.error.type, error.error.message);
}常见问题
Q: 请求成功(200)但内容被截断,怎么处理?
A: 检查 choices[0].finish_reason,如果是 "length" 说明达到了 max_completion_tokens 限制。可以使用 Partial Mode 让模型续写,或者调大 max_completion_tokens 参数。
Q: authentication_error 但我的 Key 看起来是对的?
A: 确认两点:① Key 所属平台(kimi.com vs kimi.ai)和 baseURL 的域名(moonshot.cn vs moonshot.ai)要匹配;② Key 没有被手动删除或因安全原因吊销。
Q: 429 限速,怎么知道我的速率限制是多少?
A: 在 platform.kimi.com 控制台 → 账号设置中可以查看当前等级和 RPM/TPM 限制。通过充值或使用量积累可以提升等级。