":{"message":"No available accounts: All accounts failed or unhealthy.","type":"...
错误信息
AI 解决方案
错误翻译
javascript原文:No available accounts: All accounts failed or unhealthy.
译文:无可用账户:所有账户均失败或状态异常。
原因分析**
这是一个API服务过载错误,表明:
1. 使用的API账户池中所有账户都处于不可用状态
2. 可能是账户额度耗尽、服务异常或并发请求过多
3. 系统已自动重试5次仍无法获得可用账户解决方案**
// 1. 检查账户配置和额度
const accounts = [
{ apiKey: 'key1', isValid: true },
{ apiKey: 'key2', isValid: true }
];
// 2. 实现备用账户切换逻辑
async function makeRequestWithFallback() {
for (const account of accounts) {
try {
const response = await fetch('https://api.example.com/endpoint', {
headers: { 'Authorization': Bearer ${account.apiKey} }
});
if (response.ok) return await response.json();
} catch (error) {
console.warn(账户 ${account.apiKey} 失败,尝试下一个);
account.isValid = false;
}
}
throw new Error('所有账户均不可用');
}
// 3. 增加请求间隔和重试逻辑
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
async function makeRequestWithRetry(maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await makeRequestWithFallback();
} catch (error) {
if (i === maxRetries - 1) throw error;
await delay(1000 Math.pow(2, i)); // 指数退避
}
}
}
️ 预防措施
✅ 账户健康监控:定期检查API账户的可用性和剩余额度
✅ 请求限流策略:实现指数退避重试和请求频率限制
✅ 多账户轮询:维护多个备用账户并自动切换,避免单点故障建议工具*:
axios-retry 或 retry-axios 库简化重试逻辑