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.
An initial question from the AI to start the conversation (e.g., demographic questions like gender). Display this message to the user immediately after thread creation to begin the conversation flow.
{ "success": true, "threadId": "82451", "initialMessage": "Are you male or female?", "expiresAt": "2025-11-10T15:30:00Z", "messageCount": 2, "message": "Thread created successfully. Use this threadId in your chat requests."}
The initialMessage field may or may not be present depending on whether the AI has an initial question. Always check for its presence and display it to the user if available.
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;}