How to put the context of the past calls and chat ...
# support
n
I have a request where I want to be able to put the context of previous calls / chats into a new conversation with the Vapi Assistant. How can I do it and what are the best practices which I should follow?
c
Hi nilesh_at_appsmith, To maintain and carry the context from previous calls or chats into a new conversation with the Vapi Assistant, you can use one of two methods:
previousChatId
or
sessionId
. 1. Using `previousChatId`**:** - This links your chats in sequence by specifying the ID of the previous chat. It's best for simple back-and-forth interactions. - When sending a new chat message, include the
previousChatId
to retain context. Here's an example:
Copy code
bash
     curl -X POST https://api.vapi.ai/chat \
       -H "Authorization: Bearer YOUR_API_KEY" \
       -H "Content-Type: application/json" \
       -d '{
         "assistantId": "your-assistant-id",
         "previousChatId": "chat_abc123",
         "input": "What's my order status?"
       }'
- Use this method for conversations that don't require long-term context retention. 2. Using `sessionId`**:** - This groups multiple chats under a persistent session, which is ideal for complex, multi-step workflows or longer conversations. - First, create a session and use the returned
sessionId
for all related chat requests. Sessions are valid for 24 hours by default. - Example session creation:
Copy code
bash
     curl -X POST https://api.vapi.ai/session \
       -H "Authorization: Bearer YOUR_API_KEY" \
       -H "Content-Type: application/json" \
       -d '{"assistantId": "your-assistant-id"}'
- Use this method when you need to maintain a comprehensive conversational history across multiple interactions. You can decide between these based on the complexity and duration of the interactions you expect. For more details on managing sessions, refer to [Session Management](https://docs.vapi.ai/chat/session-management).
4 Views