Skip to main content

Chat API

Send messages to AI agents and receive streaming responses.

Send Message

POST /v1/chat/completions

Scope required: chat

Request Body

{
"message": "I need help with my invoice",
"space": "soporte",
"chat_id": "optional-existing-chat-id"
}
FieldTypeRequiredDescription
messagestringThe user's message
spacestringSpace code or ID. Uses API key's default or first space
chat_idstringContinue an existing conversation

Response (SSE Stream)

The response is a Server-Sent Events stream:

data: {"text": "Hello"}

data: {"text": "! How can"}

data: {"text": " I help you?"}

data: [DONE]

Event Types

EventDescription
{"text": "..."}Text token (streaming)
{"type": "agent_info", "agent_id": "..."}Which agent was selected by the router
{"type": "system_alert", "data": {...}}Action execution notification
{"type": "component", "component_name": "...", "props": {...}}Generative UI widget
[DONE]Stream complete

cURL Example

curl -N -X POST https://senda.telar.ai/api/v1/chat/completions \
-H "Authorization: Bearer sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"message": "What are your business hours?", "space": "soporte"}'

JavaScript Example

const res = await fetch('https://senda.telar.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_live_YOUR_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ message: 'Hello', space: 'soporte' })
});

const reader = res.body.getReader();
const decoder = new TextDecoder();

while (true) {
const { value, done } = await reader.read();
if (done) break;
const text = decoder.decode(value);
// Parse SSE events
for (const line of text.split('\n\n')) {
if (line.startsWith('data: ') && line !== 'data: [DONE]') {
const data = JSON.parse(line.slice(6));
if (data.text) process.stdout.write(data.text);
}
}
}

Chat History

GET /v1/chat/history/:chatId

Returns the full message history for a chat session.

Response

{
"chat_id": "chat_abc123",
"messages": [
{
"id": "msg_1",
"role": "user",
"content": "Hello",
"created_at": "2026-05-07T12:00:00Z"
},
{
"id": "msg_2",
"role": "agent",
"content": "Hi! How can I help?",
"agent_id": "agent_soporte",
"created_at": "2026-05-07T12:00:01Z"
}
]
}