Web Widget

The browser API behind the Careflow chat widget. Use it to build your own chat window on your website instead of the ready-made widget. Calls come from the visitor's browser: the publishable key is public, and Careflow checks that the page's website is on the widget's **Allowed website origins**.

Get the widget's settings
GET /v1/web/config
Start a visitor session
POST /v1/web/session
Send a visitor's message
POST /v1/web/messages
List the visitor's conversations
GET /v1/web/conversations
Get a conversation's messages
GET /v1/web/conversations/{id}
List help pages
GET /v1/web/help
Get a help page
GET /v1/web/help/{id}
Talk to the agent by voice (WebSocket)
GET /v1/web/voice/stream

The Web Widget object

Returned by the web widget endpoints.

Attributes
tokenstring
The session token. Send it as `Authorization: Bearer <token>` on the message and conversation endpoints, and as `token` on the voice stream.
visitorIdstring
This visitor's ID. Store it in the browser and send it next time to keep their history.
assistantNamestring
—
expiresIninteger
Seconds until the token stops working. Always 1800 (30 minutes). Using the token doesn't extend it.
The Web Widget object
{
  "token": "3b9f0c2e7a1d4f6b8c5e9a2d0f7b1c3e6a8d4f2b9c0e5a7d1f3b6c8e2a4d9f0b",
  "visitorId": "vis_7d2a9c4e1b8f3a6d5c0e2b71",
  "assistantName": "Harbour View Concierge",
  "expiresIn": 1800
}

Get the widget's settings

GET https://api.trycareflow.com/v1/web/config

Returns the look and behaviour you set for the widget in the dashboard, plus the agent's name. Call it when the page loads, before the visitor opens the chat, so your chat window can show your colours and greeting straight away. It doesn't create a session or count as a message. If the page isn't on the widget's **Allowed website origins**, or the widget is switched off, the call fails. Show nothing in that case.

Query parameters
keystringrequired
Your widget's publishable key, starting with `pk_`. Find it under **Agents → your agent → Deploy → Web → Install**.
curl https://api.trycareflow.com/v1/web/config?key=pk_live_xxx
const Web widget = await careflow.webwidget.list({ key: 'pk_live_xxx' })
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "config": {
      "type": "chat",
      "renderMode": "widget",
      "brandName": "Harbour View Hotel",
      "agentName": "Mara",
      "hero": {
        "style": "brand",
        "headline": "How can we help?",
        "subline": "Ask about rooms, parking and check-in."
      },
      "content": {
        "hideHelp": false,
        "hideRecent": false,
        "hideSearch": false
      },
      "disableHandoff": false,
      "header": {
        "hideImage": false
      },
      "banner": {
        "hide": false
      },
      "avatar": {
        "hide": false
      },
      "inputPlaceholder": "Type a message…",
      "launcher": {
        "style": "bubble",
        "type": "icon"
      },
      "footer": {
        "hide": false
      },
      "color": "#1f4e5f",
      "palette": {},
      "fontFamily": "system-ui, -apple-system, sans-serif",
      "side": "right",
      "spacing": {
        "side": "20px",
        "bottom": "20px"
      },
      "aiDisclaimer": {
        "hide": false,
        "text": "You're chatting with an AI assistant."
      },
      "streamingDisabled": false,
      "persistence": "localStorage"
    },
    "assistantName": "Harbour View Concierge"
  }
}
{
  "code": "ERROR",
  "message": "invalid_request",
  "error": "key query param is required"
}
{
  "code": "ERROR",
  "message": "unknown_key",
  "error": "unknown publishable key"
}
{
  "code": "ERROR",
  "message": "origin_rejected",
  "error": "origin is not on this channel's allowlist"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for public. Please try again in 8s."
}

Start a visitor session

POST https://api.trycareflow.com/v1/web/session

Exchanges the publishable key for a session token for one visitor. Call it when the visitor opens the chat. The token lasts 30 minutes from when it's created. When a later call returns `session_expired`, call this again with the same `visitorId` and retry. The `visitorId` is what ties a visitor to their past conversations, so treat it like a password: use the one Careflow gives you, or your own long random value, never an email address or customer number. Keep it in the visitor's browser and send it each time. The page must be on the widget's **Allowed website origins**, the widget must be switched on, and the agent must be published.

Parameters
publishableKeystringrequired
Your widget's publishable key.
visitorIdstringoptional
The visitor ID you got from an earlier session, so a returning visitor sees their past conversations. Leave it out for a new visitor and Careflow creates one. A value longer than 64 characters is replaced with a new one.
curl https://api.trycareflow.com/v1/web/session \
  -d publishableKey=pk_live_xxx \
  -d visitorId=vis_7d2a9c4e1b8f3a6d5c0e2b71
const Web widget = await careflow.webwidget.create({
  publishableKey: 'pk_live_xxx',
  visitorId: 'vis_7d2a9c4e1b8f3a6d5c0e2b71',
})
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "token": "3b9f0c2e7a1d4f6b8c5e9a2d0f7b1c3e6a8d4f2b9c0e5a7d1f3b6c8e2a4d9f0b",
    "visitorId": "vis_7d2a9c4e1b8f3a6d5c0e2b71",
    "assistantName": "Harbour View Concierge",
    "expiresIn": 1800
  }
}
{
  "code": "ERROR",
  "message": "invalid_request",
  "error": "publishableKey is required"
}
{
  "code": "ERROR",
  "message": "unknown_key",
  "error": "unknown publishable key"
}
{
  "code": "ERROR",
  "message": "origin_rejected",
  "error": "origin is not on this channel's allowlist"
}
{
  "code": "ERROR",
  "message": "not_found",
  "error": "assistant no longer exists"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for public. Please try again in 8s."
}
{
  "code": "ERROR",
  "message": "internal_error",
  "error": "could not create session"
}

Send a visitor's message

POST https://api.trycareflow.com/v1/web/messages

Sends one message from the visitor and waits for the agent's reply. Allow up to two minutes for slow replies. Choose the conversation with the body: - Send `conversationId` to continue one of the visitor's conversations. - Send `new: true` to start a fresh one. - Send neither to continue the visitor's open conversation if it had activity in the last 30 minutes, or start a new one if not. Each widget can take 1,000 messages a day (UTC). After that, messages fail with `cap_exceeded` until the next day.

Parameters
messagestringrequired
What the visitor typed. It can't be empty.
conversationIdstringoptional
Continue this conversation. It must be one of this visitor's conversations. Otherwise Careflow ignores it and picks the conversation as if you'd left it out.
newbooleanoptional
`true` starts a fresh conversation. Ignored when `conversationId` matches one of the visitor's conversations.
curl https://api.trycareflow.com/v1/web/messages \
  -H "Authorization: Bearer sk_live_••••" \
  -d message=Is there parking at the hotel? \
  -d conversationId=6710b3e2c4a1f09d8e7b6a52 \
  -d new=false
const Web widget = await careflow.webwidget.create({
  message: 'Is there parking at the hotel?',
  conversationId: '6710b3e2c4a1f09d8e7b6a52',
  new: 'false',
})
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "reply": "Yes, we have an underground car park. Parking is £18 a night and you can pay at the front desk.",
    "conversationId": "6710b3e2c4a1f09d8e7b6a52"
  }
}
{
  "code": "ERROR",
  "message": "invalid_request",
  "error": "message is required"
}
{
  "code": "ERROR",
  "message": "session_expired",
  "error": "session expired — mint a new one"
}
{
  "code": "ERROR",
  "message": "not_published",
  "error": "this assistant is not published"
}
{
  "code": "ERROR",
  "message": "not_found",
  "error": "assistant no longer exists"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for public. Please try again in 8s."
}
{
  "code": "ERROR",
  "message": "upstream_error",
  "error": "the assistant could not process this message; retry shortly"
}

List the visitor's conversations

GET https://api.trycareflow.com/v1/web/conversations

Returns up to 30 of this visitor's most recent conversations with the widget's agent, newest activity first, each with its last message. Use it for a list of past chats. There are no further pages.

curl https://api.trycareflow.com/v1/web/conversations \
  -H "Authorization: Bearer sk_live_••••"
const Web widget = await careflow.webwidget.list()
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "conversations": [
      {
        "id": "6710b3e2c4a1f09d8e7b6a52",
        "preview": "Yes, we have an underground car park. Parking is £18 a night and you can pay at the front desk.",
        "role": "bot",
        "status": "active",
        "updatedAt": "2026-10-06T09:41:12Z"
      },
      {
        "id": "670fe1a8b2c3d4e5f6a7b8c9",
        "preview": "Thanks, that's all I needed.",
        "role": "user",
        "status": "success",
        "updatedAt": "2026-10-02T17:05:48Z"
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "session_expired",
  "error": "session expired — mint a new one"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for public. Please try again in 8s."
}
{
  "code": "ERROR",
  "message": "db error"
}

Get a conversation's messages

GET https://api.trycareflow.com/v1/web/conversations/{id}

Returns every message in one of the visitor's conversations, oldest first. A visitor can only read their own conversations.

Path parameters
idstringrequired
The conversation's ID, from the list or from a message reply.
curl https://api.trycareflow.com/v1/web/conversations/6710b3e2c4a1f09d8e7b6a52 \
  -H "Authorization: Bearer sk_live_••••"
const Web widget = await careflow.webwidget.retrieve('6710b3e2c4a1f09d8e7b6a52')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "id": "6710b3e2c4a1f09d8e7b6a52",
    "messages": [
      {
        "role": "user",
        "text": "Is there parking at the hotel?"
      },
      {
        "role": "bot",
        "text": "Yes, we have an underground car park. Parking is £18 a night and you can pay at the front desk."
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "bad conversation id"
}
{
  "code": "ERROR",
  "message": "session_expired",
  "error": "session expired — mint a new one"
}
{
  "code": "ERROR",
  "message": "forbidden",
  "error": "not your conversation"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "conversation not found"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for public. Please try again in 8s."
}

List help pages

GET https://api.trycareflow.com/v1/web/help

Returns the knowledge sources you've made public in the widget's Help tab (**Deploy → Web → Content**), each with a title and a short excerpt. Nothing appears here until you switch a source on. Pass `q` to keep only the sources whose title or excerpt contains those words.

Query parameters
keystringrequired
Your widget's publishable key, starting with `pk_`. Find it under **Agents → your agent → Deploy → Web → Install**.
qstringoptional
Search text, matched case-insensitively against each title and excerpt.
curl https://api.trycareflow.com/v1/web/help?key=pk_live_xxx
const Web widget = await careflow.webwidget.list({ key: 'pk_live_xxx' })
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "articles": [
      {
        "id": "66f8d2b1c9e0a3f4b5c6d7e8",
        "title": "Guest guide",
        "excerpt": "Check-in is from 3pm and check-out is by 11am. Early check-in from 11am is possible when your room is ready…"
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "invalid_request",
  "error": "key query param is required"
}
{
  "code": "ERROR",
  "message": "unknown_key",
  "error": "unknown publishable key"
}
{
  "code": "ERROR",
  "message": "origin_rejected",
  "error": "origin is not on this channel's allowlist"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for public. Please try again in 8s."
}
{
  "code": "ERROR",
  "message": "db error"
}

Get a help page

GET https://api.trycareflow.com/v1/web/help/{id}

Returns the full text of one public help page. It must be switched on for Help and available to the widget's agent.

Path parameters
idstringrequired
The help page's ID, from the list.
Query parameters
keystringrequired
Your widget's publishable key, starting with `pk_`. Find it under **Agents → your agent → Deploy → Web → Install**.
curl https://api.trycareflow.com/v1/web/help/66f8d2b1c9e0a3f4b5c6d7e8?key=pk_live_xxx
const Web widget = await careflow.webwidget.retrieve('66f8d2b1c9e0a3f4b5c6d7e8')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "id": "66f8d2b1c9e0a3f4b5c6d7e8",
    "title": "Guest guide",
    "body": "Check-in is from 3pm and check-out is by 11am.

Early check-in from 11am is possible when your room is ready."
  }
}
{
  "code": "ERROR",
  "message": "invalid_request",
  "error": "key query param is required"
}
{
  "code": "ERROR",
  "message": "unknown_key",
  "error": "unknown publishable key"
}
{
  "code": "ERROR",
  "message": "origin_rejected",
  "error": "origin is not on this channel's allowlist"
}
{
  "code": "ERROR",
  "message": "not_found",
  "error": "article not found"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for public. Please try again in 8s."
}

Talk to the agent by voice (WebSocket)

GET https://api.trycareflow.com/v1/web/voice/stream

Opens a voice call with the agent over a WebSocket. Connect to `wss://api.trycareflow.com/v1/web/voice/stream?token=<session token>`. The agent must be published and have voice turned on. The call shows in your Inbox like any other conversation. All messages are JSON text frames. Audio in both directions is 16-bit PCM, mono, 24,000 samples a second, little-endian, base64-encoded. **You send** - `{"type": "audio", "audio": "<base64 PCM>"}`: microphone audio, in small chunks as you capture it. - `{"type": "end"}`: hang up. **You receive** - `{"type": "ready"}`: the call is connected. Start sending audio. - `{"type": "audio", "audio": "<base64 PCM>"}`: the agent's voice. Play chunks back to back. - `{"type": "transcript", "role": "user" | "assistant", "text": "...", "isFinal": "true" | "false", "timestamp": "..."}`: live captions. `isFinal` is the string `"true"` once a line is complete. - `{"type": "speech_start"}`: the visitor started talking. Stop playing the agent's audio so they can interrupt. - `{"type": "function_call", "name": "...", "arguments": "..."}`: the agent used a tool. - `{"type": "error", "message": "..."}`: something went wrong with the call. - `{"type": "ended", "by": "agent"}` or `{"type": "ended", "duration": 94}`: the call is over and the socket closes. Careflow pings the socket every 30 seconds, and closes the call if the connection stops responding for 5 minutes. If the request fails before the WebSocket opens, you get a normal JSON error response.

Query parameters
tokenstringrequired
The session token from `POST /v1/web/session`.
conversationIdstringoptional
Continue this chat conversation by voice, so the call joins the same thread.
curl https://api.trycareflow.com/v1/web/voice/stream?token=3b9f0c2e7a1d4f6b8c5e9a2d0f7b1c3e6a8d4f2b9c0e5a7d1f3b6c8e2a4d9f0b
const Web widget = await careflow.webwidget.list({ token: '3b9f0c2e7a1d4f6b8c5e9a2d0f7b1c3e6a8d4f2b9c0e5a7d1f3b6c8e2a4d9f0b' })
Response
{
  "code": "ERROR",
  "message": "session_expired",
  "error": "session expired — mint a new one"
}
{
  "code": "ERROR",
  "message": "not_published",
  "error": "this assistant is not published"
}
{
  "code": "ERROR",
  "message": "not_found",
  "error": "assistant no longer exists"
}
{
  "code": "ERROR",
  "message": "voice_unavailable",
  "error": "voice is not enabled for this assistant"
}