Skip to content

[Bug] OpenAI 代理 429 限流导致 Agent 执行失败 #8293

@uwuhhhj

Description

@uwuhhhj

What happened / 发生了什么

在 AstrBot 处理用户消息并进入工具调用流程时,OpenAI provider 收到 429 Too Many Requests,随后本次 Agent 执行失败。

日志中显示 AstrBot 已尝试“使用其他 Key 重试”,但最终仍然抛出 openai.RateLimitError,用户侧只看到:

Error occurred during AI execution.

期望行为:

  • 遇到上游 429 / 限流错误时,AstrBot 能更明确地提示用户当前是 API 限流;
  • 或者支持退避重试 / 延迟重试;
  • 不希望只返回泛化的 Error occurred during AI execution.,管理员难以判断问题原因。

Reproduce / 如何复现?

API Base URL用https://api.openai-proxy.com/v1等代理中转

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

  • AstrBot version: 4.25.1

OS

Linux

Logs / 报错日志

[2026-05-22 22:32:18.901] [Core]
[WARN]
[v4.25.1] [sources.openai_source:1062]: API 调用过于频繁,尝试使用其他 Key 重试。当前 Key: sk-proj-uFlN

[2026-05-22 22:32:19.916] [Core]
[ERRO]
[v4.25.1] [core.astr_agent_run_util:310]: Traceback (most recent call last):
  File "/AstrBot/astrbot/core/astr_agent_run_util.py", line 156, in run_agent
    async for resp in agent_runner.step():
  File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 819, in step
    llm_resp, _ = await self._resolve_tool_exec(llm_resp)
  File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 1293, in _resolve_tool_exec
    requery_resp = await self.provider.text_chat(
  File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 1217, in text_chat
    ) = await self._handle_api_error(
  File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 1081, in _handle_api_error
    raise e
  File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 1205, in text_chat
    llm_response = await self._query(payloads, func_tool)
  File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 596, in _query
    completion = await self.client.chat.completions.create(
  File "/usr/local/lib/python3.12/site-packages/openai/resources/chat/completions/completions.py", line 2739, 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.RateLimitError: <html>
<head><title>429 Too Many Requests</title></head>
<body>
<center><h1>429 Too Many Requests</h1></center>
<hr><center>openresty</center>
</body>
</html>

[2026-05-22 22:32:19.919] [Plug] [DBUG] [astrbot.long_term_memory:182]: Recorded AI response: default:GroupMessage:1043337961 | [You/22:32:19]: Error occurred during AI execution.
Error Type: RateLimitError
Error Message: <html>
<head><title>429 Too Many Requests</title></head>
<body>
<center><h1>429 Too Many Requests</h1></center>
<hr><center>openresty</center>
</body>
</html>

### Are you willing to submit a PR? / 你愿意提交 PR 吗?

- [ ] Yes!

### Code of Conduct

- [x] I have read and agree to abide by the project's [Code of Conduct](https://docs.github.com/zh/site-policy/github-terms/github-community-code-of-conduct)。

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.bugSomething isn't workingpriority: p1

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions