DifY API is not bringing the conversation/session history
Self Checks
- [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 (我已阅读并同意 Language Policy).
- [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [X] Please do not modify this template :) and fill in all the required fields.
Dify version
0.8.3
Cloud or Self Hosted
Cloud
Steps to reproduce
When we click view through DiFy itself, the conversation is complete. The session is being considered in the conversation.
However, when using the API call, this does not happen.
✔️ Expected Behavior
API calls working with the conversation session being respected.
❌ Actual Behavior
All previous conversations do not appear in the session history.
Hello, @edrizo! I'm here to help you with any bugs, questions, or contributions you have regarding DifY. Let's tackle this issue together!
I found a similar open issue that might be relevant to your problem: Custom API Chatbot with nodejs no history of the conversation Included. The suggested solution involves ensuring that the conversation_id is correctly managed in your API requests. Here is a brief overview of how to handle it:
- Retrieve the
conversation_idafter the initial chat request. - Use the same
conversation_idfor subsequent requests to maintain the context of the conversation.
Here is an example in JavaScript:
const axios = require('axios');
const API_URL = 'https://api.dify.ai/v1/chat-messages';
const API_KEY = 'YOUR_SECRET_KEY';
let conversationId = '';
async function sendMessage(query) {
try {
const response = await axios.post(API_URL, {
inputs: {},
query: query,
response_mode: 'streaming',
conversation_id: conversationId,
user: 'abc-123'
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
});
// Update conversationId with the one from the response
if (response.data.conversation_id) {
conversationId = response.data.conversation_id;
}
console.log(response.data);
} catch (error) {
console.error('Error sending message:', error);
}
}
// Example usage
sendMessage('Hello, how are you?').then(() => {
sendMessage('Can you tell me more about that?');
});
In this example:
- The
conversationIdis initially empty. - After the first message is sent, the
conversationIdis updated with the value from the response. - Subsequent messages use the updated
conversationIdto maintain the conversation context.
Make sure to replace YOUR_SECRET_KEY with your actual API secret key. This approach ensures that the chatbot remembers the previous conversation when handling follow-up questions [1].
Additionally, the Dify API returns specific error codes or messages when the conversation_id is missing or incorrect, such as 404, Conversation does not exists and 400, invalid_param, abnormal parameter input [2][3].
For securely managing and using API keys, it is recommended to call them through the backend rather than exposing them in plaintext within frontend code or requests. This helps prevent your application from being abused or attacked [4][5][6][7].
To continue talking to Dosu, mention @dosu.
Endpoint used:
Chatbot:
- Retrieve the
conversation_idafter the initial chat request.- Use the same
conversation_idfor subsequent requests to maintain the context of the conversation.
"Retrieve the conversation_id after the initial chat request. Use the same conversation_id for subsequent requests to maintain the context of the conversation."
I'm doing this. The conversation_id is corret. But still have the issue.
When using the Dify API, if the conversation_id is correct but the conversation history is still not maintained, ensure the following:
-
Correct Structure: The
inputsfield should be an empty object{}when using an existingconversation_id. Only thequeryis processed for the ongoing conversation.Example structure:
{ "inputs": {}, "query": "ed", "response_mode": "blocking", "conversation_id": "your-conversation-id", "user": "abc-123" } -
Text Completion Model: Conversation history is only available in text completion models for conversational applications. Ensure that your application is using a compatible model.
-
Error Codes: Check for any specific error codes returned by the API that might indicate issues with the
conversation_idor other parameters. Common errors include:404, Conversation does not exist400, invalid_param, abnormal parameter input400, app_unavailable, App configuration unavailable400, provider_not_initialize, no available model credential configuration400, provider_quota_exceeded, model invocation quota insufficient400, model_currently_not_support, current model unavailable400, completion_request_error, text generation failed500, internal server error[1][2].
-
Built-in Rules: Dify assembles and concatenates historical conversation records according to built-in rules and replaces the
conversation historyvariable. Ensure that theHumanandAssistantprefixes are correctly set if modified [3][4].
If all these conditions are met and the issue persists, it might be necessary to review the specific implementation details or consult the Dify documentation for any additional configuration requirements.
To continue talking to Dosu, mention @dosu.
-
This is the first call:
Then i get the conversation_id generated.
-
Now, with the id:
- Still the same
@dosu
- This is the first call:
Then i get the conversation_id generated.
- Now, with the id:
![]()
![]()
- Still the same
@dosu
To ensure the conversation history is maintained using the Dify API, follow these steps:
- Initial Call: Make the first API call without a
conversation_idto generate a new one. - Subsequent Calls: Use the generated
conversation_idfor all subsequent API calls to maintain the conversation context.
Here is a detailed example:
Initial Call
Make the first call to generate a conversation_id:
{
"inputs": {},
"query": "Hi",
"response_mode": "blocking",
"user": "abc-123"
}
The response will include a conversation_id:
{
"event": "message",
"task_id": "task-123",
"id": "id-123",
"message_id": "msg-123",
"conversation_id": "conv-123",
"mode": "blocking",
"answer": "Hello! How can I help you?",
"metadata": {
"created_at": "2024-09-30T12:34:56Z"
}
}
Subsequent Calls
Use the conversation_id from the initial call for subsequent requests:
{
"inputs": {},
"query": "Can you tell me more about that?",
"response_mode": "blocking",
"conversation_id": "conv-123",
"user": "abc-123"
}
Key Points
- Empty
inputs: Ensure theinputsfield is an empty object{}when using an existingconversation_id. - Text Completion Model: Verify that your application is using a text completion model, as conversation history is only available for these models.
- Error Handling: Check for specific error codes that might indicate issues with the
conversation_idor other parameters.
If the issue persists despite following these steps, ensure that the Human and Assistant prefixes are correctly set if they have been modified [1][2].
To continue talking to Dosu, mention @dosu.
I did it. And still remains the issue.
I have the same issue, not happening in the previous version. whats has changed?
I have the same issue, not happening in the previous version. whats has changed?
Which version?
I'm using cloud version. Not self hosted.
Weird.
yes I mean the previous cloud version doesn't have this issue.
I'm having this problem too...
confirm its only in cloud version. self-host version working fine even with the latest 0.8.3
I also confirmed this problem with the cloud version. When looking at communications in the developer console, all history seems to remain, but it doesn't seem to be displayed on the history screen.
There is a difference in the parent_message_id is assigned between the history in the regular chat UI and the history data in the API.
In the case of the API, parent_message_id is always null. This seems to be why the chat history cannot be displayed and organized on the history screen.
I suspect that this may be due to a change in the way parent_message_id is handled in the API, or a change in the way chat history is displayed.
confirm its only in cloud version. self-host version working fine even with the latest 0.8.3
Did you self hosted it? And the issue is not happening?
Also having the same problem, I'll buy a server so I self-host Dify due to this problem.
Endpoint used:
![]()
"How did you make the conversation_Id appear before the HTTP Request from Dify? In mine, it only appears in the output."
This is it! After upgrading the Docker version from 0.8.3 to 0.9.0, I encountered the same issue. Is there any way to roll back to version 0.8.3?😭
Then i get the conversation_id generated.


