πŸ’¬Chat with Chatbot

Send a question to a chatbot and receive a response. By default, the endpoint returns JSON. If you set stream: true, it returns a server-sent event (SSE) stream that can be consumed from a server with fetch(). This endpoint also returns a chatlogId for maintaining conversation context and a list of sources used for the answer (max 5), ordered by relevance.

Endpoint

POST https://app.wonderchat.io/api/v1/chat

Request Parameters

Parameter
Type
Required
Description

chatbotId

string

βœ… Yes

The ID of the chatbot you want to chat with

question

string

βœ… Yes

The question you wish to ask your chatbot

chatlogId

string

❌ No

The ID of your current chat session for conversation continuity

context

string

❌ No

Additional custom context about the chat session (e.g., user information)

contextUrl

string

❌ No

URL of the page the user is on to provide additional context

stream

boolean

❌ No

Set to true to receive the answer as an SSE stream instead of JSON

Example Request (JSON Response)

curl --location --request POST 'https://app.wonderchat.io/api/v1/chat' \
--header 'Content-Type: application/json' \
--data-raw '{
  "chatbotId": "YOUR_CHATBOT_ID",
  "question": "Hello there!",
  "chatlogId": "YOUR_CHATLOG_ID",
  "context": "You are speaking with John, a 28 year old salesperson from Canada. English is not his native language, so please refrain from using complicated words.",
  "contextUrl": "https://yourwebsite.com/john-info",
  "stream": false
}'

JSON Response Format

Response Fields

Field
Type
Description

id

string

Unique identifier for this message

response

string

The chatbot's response to your question

chatlogId

string

Unique identifier for this chat session

sources

array

List of sources used to generate the response (max 5)

sources[].url

string

URL of the source document

sources[].title

string

Title of the source document

Streaming

When stream is set to true, the response content type is text/event-stream.

Streaming Request

Streaming Event Types

Event
Data Shape
Description

metadata

{"chatlogId": "..."}

Initial metadata with chatlog ID

chunk

{"delta": "partial response text"}

Partial response text

done

{"id": "...", "response": "...", "chatlogId": "...", "sources": [...]}

Final payload with full response

error

{"error": "message"}

Error message if something failed

Example Stream

Server Consumption Example (Node.js)

Use fetch() and read the response body as a stream. EventSource is not suitable here because this endpoint uses POST.

Use Cases

  • Customer Support: Integrate chatbot responses into your support system

  • Website Chat: Power your website's chat widget

  • Mobile Apps: Add conversational AI to your mobile applications

  • Workflow Automation: Chain chatbot responses with other automated processes

  • Real-time Streaming: Display responses progressively for better UX

Last updated

Was this helpful?