] API错误 (429 ): { "error": { "message": "Model tpm limit exceeded. Please try ag...

2026年02月13日 15:30 processing

错误信息

[ERROR] API错误 (429 ): { "error": { "message": "Model tpm limit exceeded. Please try again later.", "type": "rix_api_error", "param": "", "code": "bad_response_status_code" } } [ERROR] LLM API调用失败: 请求过于频繁,超出API限制 详细信息: { "error": { "message": "Model tpm limit exceeded. Please try again later.", "type": "rix_api_error", "param": "", "code": "bad_response_status_code" } } [ERROR] LLM处理错误: 请求过于频繁,超出API限制 详细信息: { "error": { "message": "Model tpm limit exceeded. Please try again later.", "type": "rix_api_error", "param": "", "code": "bad_response_status_code" } } [ERROR] 错误堆栈: Error: 请求过于频繁,超出API限制 详细信息: { "error": { "message": "Model tpm limit exceeded. Please try again later.", "type": "rix_api_error", "param": "", "code": "bad_response_status_code" } } at handleAPIError (E:\nuero\my-neuro-main\live-2d\js\api-utils.js:89:11) at async LLMClient.chatCompletion (E:\nuero\my-neuro-main\live-2d\js\ai\llm-client.js:81:17) at async InputRouter.llmHandler (E:\nuero\my-neuro-main\live-2d\js\ai\llm-handler.js:205:34) at async InputRouter.handleVoiceInput (E:\nuero\my-neuro-main\live-2d\js\ai\conversation\InputRouter.js:89:13) at async ASRProcessor.onSpeechRecognized (E:\nuero\my-neuro-main\live-2d\js\ai\conversation\ASRController.js:82:17) [ERROR] 用户显示错误: 请求频率超限,请稍后再试

AI 解决方案

代码报错分析报告

1.
原文:Model tpm limit exceeded. Please try again later.
译文:模型TPM限制已超出。请稍后再试。

原因分析


根本原因:API调用频率超过了服务商的TPM(每分钟令牌数)限制。

具体分析

  • 错误类型:rix_api_error,状态码:429(Too Many Requests)

  • 错误发生在LLM API调用过程中,具体位置在api-utils.js:89:11

  • 这是典型的速率限制错误,表明您的应用程序在短时间内发送了过多请求
  • ##解决方案

    方案一:添加请求延迟(推荐)


    // 在 api-utils.js 或 llm-client.js 中添加延迟逻辑
    class LLMClient {
      constructor() {
        this.lastRequestTime = 0;
        this.minRequestInterval = 1000; // 最小请求间隔1秒
      }
    
      async chatCompletion(prompt) {
        // 检查请求间隔
        const now = Date.now();
        const timeSinceLastRequest = now - this.lastRequestTime;
        
        if (timeSinceLastRequest < this.minRequestInterval) {
          await new Promise(resolve => 
            setTimeout(resolve, this.minRequestInterval - timeSinceLastRequest)
          );
        }
        
        this.lastRequestTime = Date.now();
        
        // 继续原有的API调用逻辑
        // ... 您的API调用代码
      }
    }
    

    方案二:实现指数退避重试机制


    // 在 handleAPIError 函数中添加重试逻辑
    async function handleAPIError(error, retryCount = 0) {
      if (error.code === 'bad_response_status_code' && 
          error.message.includes('tpm limit exceeded')) {
        
        if (retryCount < 3) {
          const delay = Math.pow(2, retryCount) * 1000; // 指数退避
          console.log(`API限制,等待 ${delay}ms 后重试...`);
          
          await new Promise(resolve => setTimeout(resolve, delay));
          return retryCount + 1; // 返回新的重试计数
        }
      }
      
      throw error; // 超过重试次数,抛出错误
    }
    

    4预防措施

    ###1. 实现请求队列系统:使用队列管理所有API请求,确保不会超过TPM限制

  • 监控API使用情况:在控制台添加请求计数器和速率监控
  • ###推荐工具:

  • 令牌计数器:在发送请求前计算token数量,避免超出限制

  • 请求限流器:使用类似p-limitbottleneck库管理并发请求
  • ```javascript
    // 使用 p-limit 控制并发
    import pLimit from 'p-limit';

    const limit = pLimit(5); // 最多5个并发请求

    async function safeAPICall(fn) {
    return limit(() => fn());
    关键提醒:TPM限制是API服务商为防止滥用设置的硬性限制,请务必遵守服务条款,合理设计请求频率。