> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CreateMessageStream

# Package: aiSiteChat

# Namespace: Messages

# Method link: https://dev.wix.com/docs/api-reference/business-management/ai-site-chat/messages/create-message-stream.md

## Permission Scopes:
Innovation Lab User: SCOPE.INNOVATION_LAB.USER

## Introduction

Creates a message and streams the assistant's response back in real time.

Use this method to send a site visitor's question and receive the assistant's answer as a stream of frames, so you can display the answer as it's generated instead of waiting for the complete response.

This method must be called using the site visitor or site member identity ([SDK](https://dev.wix.com/docs/sdk/articles/get-started/about-identities.md#site-member) | [REST](https://dev.wix.com/docs/rest/articles/getting-started/about-identities.md#site-member)) to identify the site visitor sending the message. The conversation is resolved automatically from the visitor's identity, so you don't need to provide a conversation ID.

Set the message's `messageType` to `QUESTION` and provide the question text in `body.mainText`.

Each frame in the response stream contains one of the following:
- `inputMessage`: The message you sent, persisted with its server-assigned `id`, `conversationId`, and creation timestamp. Sent as the first frame.
- `answerChunk`: A part of the assistant's answer text, streamed as it's generated. Each chunk is additive, so concatenate the chunks in the order received to build the full answer. Sent zero or more times.
- `answerMessage`: The complete, persisted assistant answer. Sent as the final frame before the stream completes.

The message and the assistant's answer are persisted regardless of whether the stream completes. If the connection drops or times out, retrieve both by calling [List Messages](https://dev.wix.com/docs/api-reference/business-management/ai-site-chat/messages/list-messages.md).

If the conversation has reached its quota, the answer is a message with `messageType` `OUT_OF_QUOTA`. Behavior outside the assistant's active hours depends on the site's widget settings.

---

## REST API

### Schema

```
 Method: createMessageStream
 Description: Creates a message and streams the assistant's response back in real time.  Use this method to send a site visitor's question and receive the assistant's answer as a stream of frames, so you can display the answer as it's generated instead of waiting for the complete response.  This method must be called using the site visitor or site member identity ([SDK](https://dev.wix.com/docs/sdk/articles/get-started/about-identities.md#site-member) | [REST](https://dev.wix.com/docs/rest/articles/getting-started/about-identities.md#site-member)) to identify the site visitor sending the message. The conversation is resolved automatically from the visitor's identity, so you don't need to provide a conversation GUID.  Set the message's `messageType` to `QUESTION` and provide the question text in `body.mainText`.  Each frame in the response stream contains one of the following: - `inputMessage`: The message you sent, persisted with its server-assigned `id`, `conversationId`, and creation timestamp. Sent as the first frame. - `answerChunk`: A part of the assistant's answer text, streamed as it's generated. Each chunk is additive, so concatenate the chunks in the order received to build the full answer. Sent zero or more times. - `answerMessage`: The complete, persisted assistant answer. Sent as the final frame before the stream completes.  The message and the assistant's answer are persisted regardless of whether the stream completes. If the connection drops or times out, retrieve both by calling [List Messages](https://dev.wix.com/docs/api-reference/business-management/ai-site-chat/messages/list-messages.md).  If the conversation has reached its quota, the answer is a message with `messageType` `OUT_OF_QUOTA`. Behavior outside the assistant's active hours depends on the site's widget settings.
 URL: https://www.wixapis.com/wix-assistant-widget/v1/messages/stream
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  message
 Method parameters: 
   param name: message | type: Message   | required: true 
        - name: sender | type: Sender | description: Message sender type.  
             - enum:
             -     ASSISTANT: AI assistant.
             -     USER: Wix user. For example, a site admin.
             -     SYSTEM: Message was sent automatically due to widget settings. For example, a contact form.
             -     SITE_VISITOR: Site visitor.
        - name: answerTo | type: string | description: GUID of the message that this message is answering.  | validation: maxLength 40
        - name: messageType | type: MessageType | description: Message type.  
             - enum:
             -     QUESTION: Question.
             -     ANSWER: Answer.
             -     INTRO: Intro message, as defined in the widget settings.
             -     LEGAL: Legal disclaimer, as defined in the widget settings.
             -     CONTACT_FORM: Contact form.
             -     CONTACT_FORM_SUBMITTED: Message confirms that a contact form was successfully submitted.
             -     SITE_OWNER_NOTIFICATION: Notification for the site owner.
             -     OFFLINE: Message informing the site visitor that the AI assistant is offline, as defined in the widget settings.
             -     OUT_OF_QUOTA: Message that informs the Wix user that they have reached the maximum number of messages on their current plan.
             -     USER_ANSWER: User answer.
             -     SITE_NAVIGATION: Site visitor site Navigation information.
             -     NAVIGATION_ANSWER: Site visitor site Navigation information answer.
             -     IGNORED_ANSWER: AI Site Chat ignored the question.
             -     VISITOR_OPTION_SELECTED: Site visitor selected an option from  Message.visitor_options.
             -     ADD_TO_CART: Site visitor added a product to the cart.
             -     BOOK_SERVICE: Site visitor booked a service.
             -     GENERATED_QUESTION: AI assistant generated a question for the user to try.
             -     SUGGESTED_QUESTION: Suggested question, as defined in the widget settings.
             -     USER_QUESTION: Wix user question for testing and training.
             -     USER_QUESTION_ANSWER: Wix assistant answer for testing and training.
             -     WIX_USER_MEDIA: Media uploaded by Wix user for visitor.
             -     MEDIA: Media uploaded by visitor for Wix user.
             -     WIX_USER_CARD: Card template sent by the Wix User.
             -     WIX_USER_MINIMAL_BODY: Simple template sent by the Wix User.
             -     WIX_USER_FORM: Form sent by the Wix User.
             -     WIX_SYSTEM: System message from comm channels.
        - name: body | type: Body | description: Message body.  
           - name: mainText | type: string | description: Main text of the message.  | validation: maxLength 4096
           - name: footerText | type: string | description: Footer text of the message.  | validation: maxLength 4096
           - name: additionalData | type: array | description: Additional data for the message.  | validation: maxItems 30
        - name: visitorOptions | type: array<string> | description: Options site visitor can choose from.  | validation: maxItems 10, maxLength 500
        - name: assistantActions | type: array<string> | description: List of actions that ai assistant executed on the site visitor's behalf.  | validation: maxItems 10, maxLength 500
 Return type: CreateMessageStreamResponse
  - ONE-OF: 
     - name: inputMessage | type: Message | description: Message you sent, persisted with its server-assigned `id`, `conversationId`, and creation timestamp. Sent as the first frame of the stream.  
        - name: id | type: string | description: Message GUID.  | validation: maxLength 40
        - name: createdDate | type: string | description: Date and time the message was created.  | validation: format date-time
        - name: sender | type: Sender | description: Message sender type.  
             - enum:
             -     ASSISTANT: AI assistant.
             -     USER: Wix user. For example, a site admin.
             -     SYSTEM: Message was sent automatically due to widget settings. For example, a contact form.
             -     SITE_VISITOR: Site visitor.
        - name: conversationId | type: string | description: Conversation GUID.  | validation: format GUID
        - name: answerTo | type: string | description: GUID of the message that this message is answering.  | validation: maxLength 40
        - name: messageType | type: MessageType | description: Message type.  
             - enum:
             -     QUESTION: Question.
             -     ANSWER: Answer.
             -     INTRO: Intro message, as defined in the widget settings.
             -     LEGAL: Legal disclaimer, as defined in the widget settings.
             -     CONTACT_FORM: Contact form.
             -     CONTACT_FORM_SUBMITTED: Message confirms that a contact form was successfully submitted.
             -     SITE_OWNER_NOTIFICATION: Notification for the site owner.
             -     OFFLINE: Message informing the site visitor that the AI assistant is offline, as defined in the widget settings.
             -     OUT_OF_QUOTA: Message that informs the Wix user that they have reached the maximum number of messages on their current plan.
             -     USER_ANSWER: User answer.
             -     SITE_NAVIGATION: Site visitor site Navigation information.
             -     NAVIGATION_ANSWER: Site visitor site Navigation information answer.
             -     IGNORED_ANSWER: AI Site Chat ignored the question.
             -     VISITOR_OPTION_SELECTED: Site visitor selected an option from  Message.visitor_options.
             -     ADD_TO_CART: Site visitor added a product to the cart.
             -     BOOK_SERVICE: Site visitor booked a service.
             -     GENERATED_QUESTION: AI assistant generated a question for the user to try.
             -     SUGGESTED_QUESTION: Suggested question, as defined in the widget settings.
             -     USER_QUESTION: Wix user question for testing and training.
             -     USER_QUESTION_ANSWER: Wix assistant answer for testing and training.
             -     WIX_USER_MEDIA: Media uploaded by Wix user for visitor.
             -     MEDIA: Media uploaded by visitor for Wix user.
             -     WIX_USER_CARD: Card template sent by the Wix User.
             -     WIX_USER_MINIMAL_BODY: Simple template sent by the Wix User.
             -     WIX_USER_FORM: Form sent by the Wix User.
             -     WIX_SYSTEM: System message from comm channels.
        - name: body | type: Body | description: Message body.  
           - name: mainText | type: string | description: Main text of the message.  | validation: maxLength 4096
           - name: footerText | type: string | description: Footer text of the message.  | validation: maxLength 4096
           - name: additionalData | type: array | description: Additional data for the message.  | validation: maxItems 30
        - name: inboxId | type: string | description: Message Id in the Inbox  | validation: maxLength 40
        - name: visitorOptions | type: array<string> | description: Options site visitor can choose from.  | validation: maxItems 10, maxLength 500
        - name: assistantActions | type: array<string> | description: List of actions that ai assistant executed on the site visitor's behalf.  | validation: maxItems 10, maxLength 500
        - name: visitorOptionsFields | type: array | description: List of detailed options the visitor can choose from.  | validation: maxItems 50
        - name: engineStatus | type: string | description: Exact status message returned by ai site chat engine,  | validation: maxLength 50
     - name: answerMessage | type: Message | description: Complete assistant answer, persisted. Sent as the final frame before the stream completes. If the conversation has reached its quota, this is a message with `messageType` `OUT_OF_QUOTA`.  
     - name: answerChunk | type: string | description: Part of the assistant's answer text, streamed as it's generated. Each chunk is additive, so concatenate the chunks in the order received to build the full answer. Sent zero or more times, between the `inputMessage` and `answerMessage` frames.  | validation: maxLength 5000


```

### Examples

### Send a question and stream the assistant's answer
Sends a site visitor's question and streams the assistant's response back as a sequence of frames.

```curl
curl -X POST \
'https://www.wixapis.com/innovation/widget/v1/messages/stream' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-H 'Accept: 'application/x-ndjson' \
-d '{
  "message": {
    "messageType": "QUESTION",
    "body": {
      "mainText": "What are your business hours?"
    }
  }
}'


{
  "inputMessage": {
    "id": "b3f1a7d2-9c14-4e58-8a2b-6d0f5c8e1a44",
    "createdDate": "2026-07-08T10:30:00.000Z",
    "sender": "SITE_VISITOR",
    "conversationId": "0f2c6e91-4a7d-4b3e-9f18-5c2a7e6b1d33",
    "messageType": "QUESTION",
    "body": {
      "mainText": "What are your business hours?"
    }
  }
}
{
  "answerChunk": "Our business hours are "
}
{
  "answerChunk": "9 AM to 5 PM, Monday through Friday."
}
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.aiSiteChat.messages.createMessageStream(message)
 Description: Creates a message and streams the assistant's response back in real time.  Use this method to send a site visitor's question and receive the assistant's answer as a stream of frames, so you can display the answer as it's generated instead of waiting for the complete response.  This method must be called using the site visitor or site member identity ([SDK](https://dev.wix.com/docs/sdk/articles/get-started/about-identities.md#site-member) | [REST](https://dev.wix.com/docs/rest/articles/getting-started/about-identities.md#site-member)) to identify the site visitor sending the message. The conversation is resolved automatically from the visitor's identity, so you don't need to provide a conversation GUID.  Set the message's `messageType` to `QUESTION` and provide the question text in `body.mainText`.  Each frame in the response stream contains one of the following: - `inputMessage`: The message you sent, persisted with its server-assigned `id`, `conversationId`, and creation timestamp. Sent as the first frame. - `answerChunk`: A part of the assistant's answer text, streamed as it's generated. Each chunk is additive, so concatenate the chunks in the order received to build the full answer. Sent zero or more times. - `answerMessage`: The complete, persisted assistant answer. Sent as the final frame before the stream completes.  The message and the assistant's answer are persisted regardless of whether the stream completes. If the connection drops or times out, retrieve both by calling [List Messages](https://dev.wix.com/docs/api-reference/business-management/ai-site-chat/messages/list-messages.md).  If the conversation has reached its quota, the answer is a message with `messageType` `OUT_OF_QUOTA`. Behavior outside the assistant's active hours depends on the site's widget settings.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  message
 Method parameters: 
   param name: message | type: Message   | required: true 
        - name: sender | type: Sender | description: Message sender type.  
             - enum:
             -     ASSISTANT: AI assistant.
             -     USER: Wix user. For example, a site admin.
             -     SYSTEM: Message was sent automatically due to widget settings. For example, a contact form.
             -     SITE_VISITOR: Site visitor.
        - name: answerTo | type: string | description: GUID of the message that this message is answering.  | validation: maxLength 40
        - name: messageType | type: MessageType | description: Message type.  
             - enum:
             -     QUESTION: Question.
             -     ANSWER: Answer.
             -     INTRO: Intro message, as defined in the widget settings.
             -     LEGAL: Legal disclaimer, as defined in the widget settings.
             -     CONTACT_FORM: Contact form.
             -     CONTACT_FORM_SUBMITTED: Message confirms that a contact form was successfully submitted.
             -     SITE_OWNER_NOTIFICATION: Notification for the site owner.
             -     OFFLINE: Message informing the site visitor that the AI assistant is offline, as defined in the widget settings.
             -     OUT_OF_QUOTA: Message that informs the Wix user that they have reached the maximum number of messages on their current plan.
             -     USER_ANSWER: User answer.
             -     SITE_NAVIGATION: Site visitor site Navigation information.
             -     NAVIGATION_ANSWER: Site visitor site Navigation information answer.
             -     IGNORED_ANSWER: AI Site Chat ignored the question.
             -     VISITOR_OPTION_SELECTED: Site visitor selected an option from  Message.visitor_options.
             -     ADD_TO_CART: Site visitor added a product to the cart.
             -     BOOK_SERVICE: Site visitor booked a service.
             -     GENERATED_QUESTION: AI assistant generated a question for the user to try.
             -     SUGGESTED_QUESTION: Suggested question, as defined in the widget settings.
             -     USER_QUESTION: Wix user question for testing and training.
             -     USER_QUESTION_ANSWER: Wix assistant answer for testing and training.
             -     WIX_USER_MEDIA: Media uploaded by Wix user for visitor.
             -     MEDIA: Media uploaded by visitor for Wix user.
             -     WIX_USER_CARD: Card template sent by the Wix User.
             -     WIX_USER_MINIMAL_BODY: Simple template sent by the Wix User.
             -     WIX_USER_FORM: Form sent by the Wix User.
             -     WIX_SYSTEM: System message from comm channels.
        - name: body | type: Body | description: Message body.  
           - name: mainText | type: string | description: Main text of the message.  | validation: maxLength 4096
           - name: footerText | type: string | description: Footer text of the message.  | validation: maxLength 4096
           - name: additionalData | type: array | description: Additional data for the message.  | validation: maxItems 30
        - name: visitorOptions | type: array<string> | description: Options site visitor can choose from.  | validation: maxItems 10, maxLength 500
        - name: assistantActions | type: array<string> | description: List of actions that ai assistant executed on the site visitor's behalf.  | validation: maxItems 10, maxLength 500
 Return type: PROMISE<CreateMessageStreamResponse>
  - ONE-OF: 
     - name: inputMessage | type: Message | description: Message you sent, persisted with its server-assigned `id`, `conversationId`, and creation timestamp. Sent as the first frame of the stream.  
        - name: _id | type: string | description: Message GUID.  | validation: maxLength 40
        - name: _createdDate | type: Date | description: Date and time the message was created.  
        - name: sender | type: Sender | description: Message sender type.  
             - enum:
             -     ASSISTANT: AI assistant.
             -     USER: Wix user. For example, a site admin.
             -     SYSTEM: Message was sent automatically due to widget settings. For example, a contact form.
             -     SITE_VISITOR: Site visitor.
        - name: conversationId | type: string | description: Conversation GUID.  | validation: format GUID
        - name: answerTo | type: string | description: GUID of the message that this message is answering.  | validation: maxLength 40
        - name: messageType | type: MessageType | description: Message type.  
             - enum:
             -     QUESTION: Question.
             -     ANSWER: Answer.
             -     INTRO: Intro message, as defined in the widget settings.
             -     LEGAL: Legal disclaimer, as defined in the widget settings.
             -     CONTACT_FORM: Contact form.
             -     CONTACT_FORM_SUBMITTED: Message confirms that a contact form was successfully submitted.
             -     SITE_OWNER_NOTIFICATION: Notification for the site owner.
             -     OFFLINE: Message informing the site visitor that the AI assistant is offline, as defined in the widget settings.
             -     OUT_OF_QUOTA: Message that informs the Wix user that they have reached the maximum number of messages on their current plan.
             -     USER_ANSWER: User answer.
             -     SITE_NAVIGATION: Site visitor site Navigation information.
             -     NAVIGATION_ANSWER: Site visitor site Navigation information answer.
             -     IGNORED_ANSWER: AI Site Chat ignored the question.
             -     VISITOR_OPTION_SELECTED: Site visitor selected an option from  Message.visitor_options.
             -     ADD_TO_CART: Site visitor added a product to the cart.
             -     BOOK_SERVICE: Site visitor booked a service.
             -     GENERATED_QUESTION: AI assistant generated a question for the user to try.
             -     SUGGESTED_QUESTION: Suggested question, as defined in the widget settings.
             -     USER_QUESTION: Wix user question for testing and training.
             -     USER_QUESTION_ANSWER: Wix assistant answer for testing and training.
             -     WIX_USER_MEDIA: Media uploaded by Wix user for visitor.
             -     MEDIA: Media uploaded by visitor for Wix user.
             -     WIX_USER_CARD: Card template sent by the Wix User.
             -     WIX_USER_MINIMAL_BODY: Simple template sent by the Wix User.
             -     WIX_USER_FORM: Form sent by the Wix User.
             -     WIX_SYSTEM: System message from comm channels.
        - name: body | type: Body | description: Message body.  
           - name: mainText | type: string | description: Main text of the message.  | validation: maxLength 4096
           - name: footerText | type: string | description: Footer text of the message.  | validation: maxLength 4096
           - name: additionalData | type: array | description: Additional data for the message.  | validation: maxItems 30
        - name: inboxId | type: string | description: Message Id in the Inbox  | validation: maxLength 40
        - name: visitorOptions | type: array<string> | description: Options site visitor can choose from.  | validation: maxItems 10, maxLength 500
        - name: assistantActions | type: array<string> | description: List of actions that ai assistant executed on the site visitor's behalf.  | validation: maxItems 10, maxLength 500
        - name: visitorOptionsFields | type: array | description: List of detailed options the visitor can choose from.  | validation: maxItems 50
        - name: engineStatus | type: string | description: Exact status message returned by ai site chat engine,  | validation: maxLength 50
     - name: answerMessage | type: Message | description: Complete assistant answer, persisted. Sent as the final frame before the stream completes. If the conversation has reached its quota, this is a message with `messageType` `OUT_OF_QUOTA`.  
     - name: answerChunk | type: string | description: Part of the assistant's answer text, streamed as it's generated. Each chunk is additive, so concatenate the chunks in the order received to build the full answer. Sent zero or more times, between the `inputMessage` and `answerMessage` frames.  | validation: maxLength 5000


```

### Examples

### Send a question and stream the assistant's answer
```javascript
import { messages } from "@wix/ai-site-chat";

const message = {
  messageType: "QUESTION",
  body: {
    mainText: "What are your business hours?",
  },
};

async function createMessageStream() {
  let answer = "";

  // The stream emits frames: first the persisted question, then additive
  // answer chunks, and finally the complete persisted answer.
  for await (const frame of messages.createMessageStream(message)) {
    if (frame.inputMessage) {
      // The visitor's question, persisted with its server-assigned ID and conversation ID.
      console.log("Question sent:", frame.inputMessage._id);
    } else if (frame.answerChunk) {
      // Additive text chunk — append it to build the full answer.
      answer += frame.answerChunk;
    } else if (frame.answerMessage) {
      // The complete, persisted answer.
      answer = frame.answerMessage.body?.mainText ?? answer;
    }
  }

  return answer;
}

```

### createMessageStream (self-hosted)
Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { messages } from '@wix/ai-site-chat';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { messages },
  // Include the auth strategy and host as relevant
});


async function createMessageStream(message) {
  const response = await myWixClient.messages.createMessageStream(message);
};
```

---