> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Post a message to a thread

> Same streaming contract as /api/chat when stream is true.

Same streaming contract as `/api/chat` when `stream` is true.

### Path parameters

<ParamField path="id" type="string" required>
  Thread id
</ParamField>

### Request body

`ThreadMessage`

<ParamField body="message" type="string" required />

<ParamField body="stream" type="boolean" />

<ParamField body="provider" type="string" />

### Response

`ChatResponse`

<ResponseField name="ok" type="boolean" required />

<ResponseField name="reply" type="string" required>
  The assistant reply, rendered as markdown
</ResponseField>

<ResponseField name="threadId" type="string" />

<ResponseField name="suggestions" type="string[]" />

<ResponseField name="provider" type="string" />

<ResponseField name="model" type="string" />

<ResponseField name="toolCalls" type="object[]" />

<ResponseField name="sources" type="object[]">
  <Expandable title="sources">
    <ResponseField name="title" type="string" />

    <ResponseField name="url" type="string" />
  </Expandable>
</ResponseField>

<ResponseField name="outcomes" type="Outcome[]">
  <Expandable title="Outcome">
    <ResponseField name="name" type="string">
      e.g. `order.cancelled`, `cart.added`, `checkout.started`, `purchase.completed`
    </ResponseField>

    <ResponseField name="resourceType" type="string" />

    <ResponseField name="resourceId" type="string" />

    <ResponseField name="quantity" type="number" />

    <ResponseField name="amount" type="number">
      Minor units
    </ResponseField>

    <ResponseField name="revenue" type="number">
      Minor units
    </ResponseField>

    <ResponseField name="currency" type="string" />
  </Expandable>
</ResponseField>

<ResponseField name="type" type="string">
  Rich message type: `product_cards` or `order_cards`
</ResponseField>

<ResponseField name="content" type="object">
  Payload for the rich message type

  <Expandable title="content">
    <ResponseField name="headline" type="string" />

    <ResponseField name="products" type="object[]">
      <Expandable title="products">
        <ResponseField name="id" type="string" />

        <ResponseField name="title" type="string" />

        <ResponseField name="price" type="string" />
      </Expandable>
    </ResponseField>

    <ResponseField name="orders" type="object[]" />
  </Expandable>
</ResponseField>

### Status codes

| Code  | Meaning |
| ----- | ------- |
| `200` | OK      |
| `400` | Error   |
| `401` | Error   |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.example.com/api/threads/{id}/messages' \
    --header 'x-widget-token: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "message": "Two-person tent, green — replacement for damaged pole set.",
    "stream": true,
    "provider": "string"
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "ok": true,
    "reply": "string",
    "threadId": "string",
    "suggestions": [
      "string"
    ],
    "provider": "string",
    "model": "string",
    "toolCalls": [
      {}
    ],
    "sources": [
      {
        "title": "Replacement tent pole set",
        "url": "https://example.com/webhooks/stateset"
      }
    ],
    "outcomes": [
      {
        "name": "Two-Person Tent",
        "resourceType": "string",
        "resourceId": "string",
        "quantity": 2,
        "amount": 49,
        "revenue": 49,
        "currency": "USD"
      }
    ],
    "type": "standard",
    "content": {
      "headline": "Replacement tent pole set",
      "products": [
        {
          "id": null,
          "title": null,
          "price": null
        }
      ],
      "orders": [
        {}
      ]
    }
  }
  ```
</ResponseExample>
