Creates a new conversation thread with a unique 5-digit ID. Once created, you can send multiple messages to this thread and the AI will automatically remember the conversation history (last 20 messages).
Optional patient phone number (any format: 5551234567, +15551234567, (555) 123-4567).The system will automatically find the patient and link the thread.
{ "success": true, "threadId": "82451", "expiresAt": "2025-10-22T19:30:00.000Z", "message": "Thread created successfully. Use this threadId in your chat requests."}
Monitor expiresAt and create new threads when needed:
Copy
if (new Date(thread.expiresAt) < new Date()) { // Thread expired, create new one const newThread = await createThread({ phone: user.phone }); sessionStorage.threadId = newThread.threadId;}