( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/AstrBot/astrbot/core/provider/sources/ope...

2026年06月08日 08:36 20.94 秒 success

错误信息

self._add_action_func(lambda rs: rs.outcome.result()) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 449, in result return self.__get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result raise self._exception File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 513, in _iter_llm_responses_with_fallback async for resp in self._iter_llm_responses( File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 473, in _iter_llm_responses async for resp in stream: # type: ignore File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 1358, in text_chat_stream ) = await self._handle_api_error( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 1232, in _handle_api_error raise e File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 1345, in text_chat_stream async for response in self._query_stream(payloads, func_tool): File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 691, in _query_stream stream = await self.client.chat.completions.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/openai/resources/chat/completions/completions.py", line 2814, in create return await self._post( ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1931, in post return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1716, in request raise self._make_status_error_from_response(err.response) from None openai.PermissionDeniedError: Error code: 403 - {'error': {'message': '用户额度不足, 剩余额度: $0.000000 (request id: 20260608083325723284789w2IUYQAH)', 'type': 'rix_api_error', 'param': '', 'code': 'insufficient_user_quota'}} [2026-06-08 08:33:25.864] [Core] [WARN] [v4.25.5] [result_decorate.stage:169]: 启用流式输出时,依赖发送消息前事件钩子的插件可能无法正常工作

AI 解决方案

🔍 错误分析

1. 🌐 错误翻译


原文:Error code: 403 - {'error': {'message': '用户额度不足, 剩余额度: $0.000000 (request id: 20260608083325723284789w2IUYQAH)', 'type': 'rix_api_error', 'param': '', 'code': 'insufficient_user_quota'}}
译文:错误代码:403 - {'error': {'message': '用户额度不足, 剩余额度: $0.000000 (请求ID: 20260608083325723284789w2IUYQAH)', 'type': 'rix_api_error', 'param': '', 'code': 'insufficient_user_quota'}}

2. 🎯 原因分析


  • 根本原因:调用 OpenAI 兼容的 API(由 DMXAPI 或类似服务提供)时,您账户中的余额已用尽(剩余额度为 $0.000000),无法支付本次请求的费用。

  • 错误位置:错误发生在向 API 端点发起聊天流式请求时(openai.resources.chat.completions.completions.create),服务端返回了 403 (Forbidden) 权限拒绝错误,明确提示了 insufficient_user_quota(用户额度不足)。
  • 3. 💡 解决方案


  • 立即充值:登录到您所使用的 API 服务提供商(从错误信息看很可能是 DMXAPI)的管理后台,为您的账户充值。

  • 检查配置:确认 AstrBot 配置中使用的 API Key 是否正确且关联了有余额的账户。

  • 代码级容错(可选):如果希望在代码中更优雅地处理此类错误,可以捕获特定的 openai.PermissionDeniedError
  • import openai
    
    try:
        # 调用API的代码
        response = await client.chat.completions.create(...)
    except openai.PermissionDeniedError as e:
        # 检查是否是额度不足错误
        error_detail = str(e)
        if "insufficient_user_quota" in error_detail or "额度不足" in error_detail:
            print("错误:API账户余额不足,请及时充值。")
            # 这里可以添加发送警报通知等逻辑
        else:
            # 其他权限错误
            print(f"权限错误: {e}")
    

    4. 🛡️ 预防措施


  • 监控与预警:在 API 管理平台设置用量或余额预警,确保在余额耗尽前得到通知。

  • 错误处理:在代码中对 API 调用增加完善的错误捕获和日志记录,特别是对于 4xx/5xx 的状态码,便于快速定位是网络、认证还是配额问题。