nilesh_at_appsmith
09/02/2025, 7:34 AMChiranjeet Mishra
09/03/2025, 2:21 PMpreviousChatId 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:
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:
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).