messages api can't get the right result
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
1.7.2
Cloud or Self Hosted
Cloud, Self Hosted (Docker)
Steps to reproduce
- Build any chatbot, using its URL to start chatting on the web
- Using
messagesapi to get chat history - return
{"code": "not_found", "message": "Conversation Not Exists.", "status": 404} - Using
chat-messagesapi to start chatting,messagesapi can get the right result.
✔️ Expected Behavior
messages api returns the right result
❌ Actual Behavior
messages api returns {"code": "not_found", "message": "Conversation Not Exists.", "status": 404}
Testing on the Dify cloud also gets the same result.
This behavior is expected based on how the APIs are designed. The messages API (GET /messages) will return a 404 "Conversation Not Exists" error if the conversation ID doesn't match an existing conversation for the current app, user, and source (api/console). It does not create conversations—only retrieves them. In contrast, the chat-messages API (POST /chat-messages) can create a new conversation if you don't provide a conversation ID, or append to an existing one if you do. That's why after starting a chat with chat-messages, the messages API can then retrieve the history: the conversation now exists in the correct context.
A common cause for the 404 is a mismatch in user/session/app context between when the conversation was created and when you try to retrieve it. Make sure you use the same authentication and context for both creating and retrieving conversations. For best results, always start conversations with chat-messages and then use messages to fetch history within the same session or API context. This applies to both cloud and self-hosted deployments, as the logic is the same across environments.
If you need more flexible retrieval or clearer errors, it could be worth suggesting a feature request for improved conversation lookup or error messaging in future releases.
References:
- messages API implementation and error handling
- chat-messages API and conversation creation logic
- Conversation context and strict matching
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
https://github.com/langgenius/dify/blob/6453fc49735ed2e94de310d6a637fb29ca70aaac/api/services/message_service.py#L38-L42
Why are these two query parameters required? Can I get messages only with the conversation_id?
Hi, @zyh3826. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.
Issue Summary:
- You reported a 404 "Conversation Not Exists" error when using the
messagesAPI to fetch chat history after starting a chat via a chatbot URL. - The
messagesAPI only retrieves existing conversations tied to the current app/user/session context and does not create new conversations. - The
chat-messagesAPI can create new conversations and thus works fine for starting chats and fetching history. - I advised ensuring consistent authentication and context when creating and retrieving conversations.
- Another user questioned some query parameters in the message service code, but the core issue was clarified.
Next Steps:
- Please confirm if this behavior is still relevant with the latest version of Dify; if so, feel free to keep the discussion open by commenting here.
- Otherwise, this issue will be automatically closed in 15 days.
Thanks for your understanding and contribution!
still relevant with the latest version of Dify
Hi, @zyh3826. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.
Issue Summary:
- You reported that in Dify v1.7.2, the
messagesAPI returns a 404 "Conversation Not Exists" error when fetching chat history after starting a chat via a chatbot URL. - Starting chats with the
chat-messagesAPI works correctly, as it creates new conversations. - The
messagesAPI only retrieves existing conversations tied to the current app/user/session context and does not create new ones. - Another user confirmed the issue remains relevant in the latest Dify version.
- No resolution has been implemented yet.
Next Steps:
- Please let me know if this issue is still relevant with the latest version of Dify by commenting on this issue.
- If I do not hear back within 15 days, I will automatically close this issue.
Thank you for your understanding and contribution!