mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-21 17:45:23 -04:00
Claude model, error # Help after calling stop interface #310
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @13261046907 on GitHub (May 26, 2025).
Self Checks
Dify version
Version 1.4.0
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Claude model error:

When the message is outputting normally and the stop interface is successfully called, asking the question again will result in an error
✔️ Expected Behavior
Return result without error, answer normally
❌ Actual Behavior
1、Error as shown in the figure:

2、Interface call returns error:
{"event": "error", "conversation_id": "760ea5ea-f92b-441e-92f5-2eef114bef1e", "message_id": "0dadcbbe-7210-4caa-8f2e-d05dc8af87cf", "created_at": 1748232745, "code": "completion_request_error", "status": 400, "message": "[models] Bad Request Error, Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.3: all messages must have non-empty content except for the optional final assistant message'}}"}
Could you please help me with this? Thank you very much 🙏
@dosubot[bot] commented on GitHub (May 26, 2025):
Based on the information available, the error you are encountering—
completion_request_errorwith code 400 and the messageall messages must have non-empty content except for the optional final assistant message—indicates that after calling the stop interface, a subsequent request is being made where at least one message in the payload has empty content. This is not allowed by the Claude model API.Here’s what is known:
/completion-messages/{task_id}/stopendpoint is used to stop a generation task and is only supported in streaming mode. Thetask_idmust be obtained from the streaming chunk return of a/completion-messagesrequest. sourcecompletion_request_errorwith code 400 is described as "Text generation failed" and can be triggered by invalid request parameters, including empty message content. sourceWhat this likely means for your workflow:
What you can try:
messagesarray has non-empty content.Unfortunately, I was not able to find any existing documentation or previous issues in the Dify repositories that address this specific error or provide troubleshooting steps for this scenario.
If you need further assistance, providing a sample of the request payload sent after the stop operation may help in diagnosing the issue more precisely.
To continue talking to Dosu, mention @dosu-bot.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@13261046907 commented on GitHub (May 26, 2025):
Using the same code logic, no errors have occurred in other models such as gpt and deepseek. If the message is not generated after calling the stop interface, the last message must be empty. How to avoid errors when sending messages to claude again? @dosu-bot
@dosubot[bot] commented on GitHub (May 26, 2025):
The error with the Claude model occurs because it enforces a stricter requirement: all messages in the payload must have non-empty content (except for the optional final assistant message). Other models like GPT and DeepSeek are more lenient and do not throw an error if the last message is empty, which is why your current logic works for them but not for Claude.
To avoid this error when sending messages to Claude after calling the stop interface, you need to ensure that the message array you send does not include any messages with empty content. Specifically:
""ornull).This adjustment should be made only for Claude, since other models do not require it. You can implement a check in your code to clean up the message array before sending it to the Claude API.
There is no configuration in Dify or the Claude model YAML that changes this behavior—it's an API-level requirement from Claude. The solution is to ensure your message payloads always have non-empty content for all messages except the optional final assistant message before making the API call.
If you need to keep the message structure consistent across models, you can add a step to sanitize the message array for Claude requests only, right before sending.
Let me know if you need an example of how to implement this check in your code.
To reply, just mention my name @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
