API
Conversation
New Conversation
The newConversation
endpoint is part of the Mendable API, designed to create a new conversation and return the conversation ID.
POST /api.mendable.ai/v1/newConversation
Example Usage
Request
Here is an example request using cURL:
curl -X POST https://api.mendable.ai/v1/newConversation \
-H "Content-Type: application/json" \
-d '{
"api_key": "YOUR_API_KEY",
}'
or using Javascript:
const url = "https://api.mendable.ai/v1/newConversation";
const data = {
api_key: "YOUR_API_KEY",
};
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error("Error:", error));
Response
Here is an example response:
{
"conversation_id": 1234567890
}
The conversation_id is return as an integer. You can use this to start a chat.
Request Paremeters
Field | Type | Required | Description |
---|---|---|---|
api_key | string | Yes | Your Mendable API key |
Resetting the Conversation
To reset a conversation, you should create a new conversation id using the newConversation endpoint. This will reset the conversation and return a new conversation id. Also, make sure to not pass a history to the chat endpoint after resetting it that way the AI won't use previous messages to respond to the user.
End Conversation (Optional)
The endConversation
endpoint is part of the Mendable API, designed to end a conversation. This helps keep track of conversation time, useful for analytics.
POST /api.mendable.ai/v1/endConversation
Example Usage
Request
Here is an example request using cURL:
curl -X POST https://api.mendable.ai/v1/endConversation \
-H "Content-Type: application/json" \
-d '{
"api_key": "YOUR_API_KEY",
"conversation_id": 123,
}'
const url = "https://api.mendable.ai/v1/endConversation";
const data = {
"api_key": "YOUR_API_KEY",
"conversation_id": 123,
};
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error("Error:", error));
Response
Here is an example response:
Conversation has ended.
Get Conversation Messages
To get all messages for a conversation, you can use the /v1/messages/byConversationId
endpoint. This will return all messages for a conversation, including the user's messages and the bot's responses.
POST /api.mendable.ai/v1/messages/byConversationId
Example Usage
Request
Here is an example request using cURL:
curl -X POST "https://api.mendable.ai/v1/messages/byConversationId" \
-H "Content-Type: application/json" \
-d '{
"api_key": "YOUR_SERVER_SIDE_API_KEY",
"conversation_id": 1720329
}'
Response
[
{
"message_id": 12344321,
"conversation_id": 56788765,
"sender": "Human", // Human or AI
"timestamp": "2024-01-19T23:22:58.223",
"message": "How do I create a new project?",
"rating_value": 0
},
{
"message_id": 12344321,
"conversation_id": 56788765,
"sender": "AI", // Human or AI
"timestamp": "2024-01-19T23:23:02.092",
"message": "To create a new project...",
"rating_value": 1 // positive rating 1, no rating 0 and negative rating -1
},
]