Is every chat log supposed to be a new chat, payin...
# support
q
??
@Vapi Support Bot
v
You do not need to create a new chat (and pay for each) on every message. To maintain conversation context and avoid extra costs, use the
previousChatId
from the last response when sending follow-up messages. Here’s a code snippet:
Copy code
js
await sendChatMessage("Tell me more", firstMessage.chatId); // Links to previous chat
This way, you only create a new chat for the first message, and all follow-ups are linked, keeping costs down and context intact. See the [Vapi session management docs](https://docs.vapi.ai/chat/session-management) for more details. Source: - [Session management](https://docs.vapi.ai/chat/session-management)
You do not need to create a new chat (and incur a new charge) for every message. To maintain conversation context and optimize costs, use the
previousChatId
parameter in your API request to link messages together. Here’s a code snippet example:
Copy code
js
await fetch('https://api.vapi.ai/chat', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    assistantId: 'your-assistant-id',
    input: 'Your message here',
    previousChatId: 'last-chat-id'
  })
});
This way, you keep the conversation in the same context without starting a new billable chat each time. For more details, see the [Vapi session management documentation](https://docs.vapi.ai/chat/session-management). Source: - [Session management](https://docs.vapi.ai/chat/session-management)
v
Message marked as helpful by @Qper! 🎉
Message marked as helpful by @Qper! 🎉