Skip to main content
POST
/
chat
curl -X POST https://api.ansa.so/chat \
  -H "Content-Type: application/json" \
  -d '{
    "agentId": "agent_xxx",
    "messages": [
      {"role": "user", "content": "What are your business hours?"}
    ]
  }'
event: message_start
data: {"type":"message_start","conversationId":"conv_xxx"}

event: content_block_start
data: {"type":"content_block_start","index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"Our business hours are "}}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"Monday through Friday, 9 AM to 5 PM."}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_stop
data: {"type":"message_stop"}

Request

Send a message to an agent and receive a streaming response.
agentId
string
required
The ID of the agent to chat with
messages
array
required
Array of message objects with role and content
conversationId
string
Optional conversation ID to continue an existing conversation

Message Object

{
  "role": "user",
  "content": "What are your business hours?"
}
Roles:
  • user - Messages from the end user
  • assistant - Previous AI responses (for context)

Response

The response is a Server-Sent Events (SSE) stream.

Event Types

EventDescription
message_startStart of assistant response
content_block_startStart of content block
content_block_deltaText chunk
tool_use_startAgent is calling a tool
tool_resultTool execution result
content_block_stopEnd of content block
message_stopEnd of message

Delta Object

{
  "type": "content_block_delta",
  "delta": {
    "type": "text_delta",
    "text": "Our business hours are "
  }
}
curl -X POST https://api.ansa.so/chat \
  -H "Content-Type: application/json" \
  -d '{
    "agentId": "agent_xxx",
    "messages": [
      {"role": "user", "content": "What are your business hours?"}
    ]
  }'
event: message_start
data: {"type":"message_start","conversationId":"conv_xxx"}

event: content_block_start
data: {"type":"content_block_start","index":0}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"Our business hours are "}}

event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"Monday through Friday, 9 AM to 5 PM."}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_stop
data: {"type":"message_stop"}