What happened / 发生了什么
root of issue: Grok don't accept any empty content field, but sometimes other models (in my case DeepSeek produces those in chat history)
Reproduce / 如何复现?
- Start with a clean chat history
- Switch model to DeepSeek w/ reasoning, instruct it to do something involving tool call (such that there are
reasoning_content left but with empty content
- Switch model to Grok series, e.g.
grok/grok-4-1-fast
And get:
{"code":"Client specified an invalid argument","error":"Invalid request content: Each message must have at least one content element."}
By catching payload, I found entries like
{
"role": "assistant",
"content": [],
"reasoning_content": "..."
},
and using the payload to replay the request to grok reproduces the exact error. After removing those entries, replay again, grok answers correctly.
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
v4.20.0 in container (podman), with telegram bot API
OS
Linux
Logs / 报错日志
[2026-03-16 13:14:04.437] [Core] [WARN] [v4.20.0] [runners.tool_loop_agent_runner:268]: Chat Model cloudflare_general/grok/grok-4-1-fast request error: Error code: 400 - {'code': 'Client specified an invalid argument', 'error': 'Invalid request content: Each message must have at least one content element.'}
Traceback (most recent call last):
File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 243, in _iter_llm_responses_with_fallback
async for resp in self._iter_llm_responses(include_model=idx == 0):
File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 220, in _iter_llm_responses
yield await self.provider.text_chat(**payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 763, in text_chat
) = await self._handle_api_error(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 714, in _handle_api_error
raise e
File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 751, in text_chat
llm_response = await self._query(payloads, func_tool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/astrbot/core/provider/sources/openai_source.py", line 251, in _query
completion = await self.client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/openai/resources/chat/completions/completions.py", line 2714, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1884, 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 1669, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'code': 'Client specified an invalid argument', 'error': 'Invalid request content: Each message must have at least one content element.'}
[2026-03-16 13:14:04.453] [Core] [INFO] [respond.stage:184]: Prepare to send - Karuboniru/157891005: [引用消息] LLM 响应错误: All chat models failed: BadRequestError: Error code: 400 - {'code': 'Client specified an invalid argument', 'error': 'Invalid request content: Each message must have at least one content element.'}
Are you willing to submit a PR? / 你愿意提交 PR 吗?
Proposed fix
Filter out all chat history with empty content (those are not going to be used anyway).
Code of Conduct
What happened / 发生了什么
root of issue: Grok don't accept any empty
contentfield, but sometimes other models (in my case DeepSeek produces those in chat history)Reproduce / 如何复现?
reasoning_contentleft but with emptycontentgrok/grok-4-1-fastAnd get:
By catching payload, I found entries like
and using the payload to replay the request to grok reproduces the exact error. After removing those entries, replay again, grok answers correctly.
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
v4.20.0 in container (podman), with telegram bot API
OS
Linux
Logs / 报错日志
Are you willing to submit a PR? / 你愿意提交 PR 吗?
Proposed fix
Filter out all chat history with empty content (those are not going to be used anyway).
Code of Conduct