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?"}
]
}'
const response = await fetch('https://api.ansa.so/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
agentId: 'agent_xxx',
messages: [
{ role: 'user', content: 'What are your business hours?' }
]
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
// Parse SSE events
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (data.delta?.text) {
process.stdout.write(data.delta.text);
}
}
}
}
import requests
import json
response = requests.post(
'https://api.ansa.so/chat',
json={
'agentId': 'agent_xxx',
'messages': [
{'role': 'user', 'content': 'What are your business hours?'}
]
},
stream=True
)
for line in response.iter_lines():
if line:
line = line.decode('utf-8')
if line.startswith('data: '):
data = json.loads(line[6:])
if 'delta' in data and 'text' in data['delta']:
print(data['delta']['text'], end='')
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"}
API Reference
Chat
Send messages and receive AI responses
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?"}
]
}'
const response = await fetch('https://api.ansa.so/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
agentId: 'agent_xxx',
messages: [
{ role: 'user', content: 'What are your business hours?' }
]
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
// Parse SSE events
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (data.delta?.text) {
process.stdout.write(data.delta.text);
}
}
}
}
import requests
import json
response = requests.post(
'https://api.ansa.so/chat',
json={
'agentId': 'agent_xxx',
'messages': [
{'role': 'user', 'content': 'What are your business hours?'}
]
},
stream=True
)
for line in response.iter_lines():
if line:
line = line.decode('utf-8')
if line.startswith('data: '):
data = json.loads(line[6:])
if 'delta' in data and 'text' in data['delta']:
print(data['delta']['text'], end='')
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.Message Object
{
"role": "user",
"content": "What are your business hours?"
}
user- Messages from the end userassistant- Previous AI responses (for context)
Response
The response is a Server-Sent Events (SSE) stream.Event Types
| Event | Description |
|---|---|
message_start | Start of assistant response |
content_block_start | Start of content block |
content_block_delta | Text chunk |
tool_use_start | Agent is calling a tool |
tool_result | Tool execution result |
content_block_stop | End of content block |
message_stop | End 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?"}
]
}'
const response = await fetch('https://api.ansa.so/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
agentId: 'agent_xxx',
messages: [
{ role: 'user', content: 'What are your business hours?' }
]
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
// Parse SSE events
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (data.delta?.text) {
process.stdout.write(data.delta.text);
}
}
}
}
import requests
import json
response = requests.post(
'https://api.ansa.so/chat',
json={
'agentId': 'agent_xxx',
'messages': [
{'role': 'user', 'content': 'What are your business hours?'}
]
},
stream=True
)
for line in response.iter_lines():
if line:
line = line.decode('utf-8')
if line.startswith('data: '):
data = json.loads(line[6:])
if 'delta' in data and 'text' in data['delta']:
print(data['delta']['text'], end='')
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"}