Chat API
The Chat API provides real-time conversational AI capabilities with streaming responses, conversation management, and multi-modal support. Build ChatGPT-like experiences with your AI agents.
Info: All chat endpoints require authentication using the
x-api-tokenheader.
Overview
- Conversation Management: Create, update, and manage conversations
- Real-time Streaming: Server-Sent Events (SSE) for streaming responses
- Message History: Full conversation history with pagination
- Multi-modal Support: Text and audio input support
Authentication
curl -H "x-api-token: YOUR_API_TOKEN" \
https://api.aloochat.ai/api/v1/chat/...Conversation Management
Create a New Conversation
cURL:
curl -X POST https://api.aloochat.ai/api/v1/chat/conversations \
-H "x-api-token: YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "123e4567-e89b-12d3-a456-426614174000",
"deployment_id": "456e7890-e89b-12d3-a456-426614174001",
"title": "Customer Support Chat"
}'JavaScript:
const response = await fetch('https://api.aloochat.ai/api/v1/chat/conversations', {
method: 'POST',
headers: {
'x-api-token': 'YOUR_API_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
agent_id: '123e4567-e89b-12d3-a456-426614174000',
deployment_id: '456e7890-e89b-12d3-a456-426614174001',
title: 'Customer Support Chat'
})
});Get User Conversations
cURL:
curl "https://api.aloochat.ai/api/v1/chat/conversations?limit=20" \
-H "x-api-token: YOUR_API_TOKEN"JavaScript:
const response = await fetch('https://api.aloochat.ai/api/v1/chat/conversations?limit=20', {
headers: { 'x-api-token': 'YOUR_API_TOKEN' }
});
const conversations = await response.json();Agent Chat
Non-Streaming Chat
cURL:
curl -X POST https://api.aloochat.ai/api/v1/chat/agent/chat \
-H "x-api-token: YOUR_API_TOKEN" \
-F "agent_key=agent:123e4567-e89b-12d3-a456-426614174000:voice:us-east-1" \
-F 'messages=[{"role":"user","content":"Hello"}]' \
-F "query=What are your business hours?"JavaScript:
const formData = new FormData();
formData.append('agent_key', 'agent:123e4567-e89b-12d3-a456-426614174000:voice:us-east-1');
formData.append('query', 'What are your business hours?');
const response = await fetch('https://api.aloochat.ai/api/v1/chat/agent/chat', {
method: 'POST',
headers: { 'x-api-token': 'YOUR_API_TOKEN' },
body: formData
});Streaming Chat with SSE
cURL:
curl -X POST https://api.aloochat.ai/api/v1/chat/agent/stream \
-H "x-api-token: YOUR_API_TOKEN" \
-H "Accept: text/event-stream" \
-F "agent_key=agent:123e4567-e89b-12d3-a456-426614174000:voice:us-east-1" \
-F "query=Tell me about your services"JavaScript:
const response = await fetch('https://api.aloochat.ai/api/v1/chat/agent/stream', {
method: 'POST',
headers: { 'x-api-token': 'YOUR_API_TOKEN' },
body: formData
});
const reader = response.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
// Process streaming chunks
}Response Schemas
Chat Response
{
"conversation_id": "conv_123",
"agent_response_text": "Our business hours are Monday-Friday, 9 AM to 6 PM EST.",
"response_time_ms": 1250,
"was_resolved": true
}Stream Event
{
"type": "agent_text_chunk",
"content": "Our business hours are ",
"conversation_id": "conv_123"
}Error Handling
{
"error": "ValidationError",
"message": "Invalid agent_key format",
"statusCode": 400
}Response Schemas
Chat Response
{
"conversation_id": "conv_123",
"agent_response_text": "Our business hours are Monday-Friday, 9 AM to 6 PM EST.",
"response_time_ms": 1250,
"was_resolved": true
}Stream Event
{
"type": "agent_text_chunk",
"content": "Our business hours are ",
"conversation_id": "conv_123"
}SSE Event Types
transcribed_text: Audio transcription resultagent_text_chunk: Streaming text chunk from agentchunk: Generic content chunkstart: Stream startedend: Stream completederror: Error occurred during processing
Error Handling
{
"error": "ValidationError",
"message": "Invalid agent_key format",
"statusCode": 400
}Rate Limits
- Conversation management: 100 requests/minute
- Non-streaming chat: 60 requests/minute
- Streaming chat: 30 requests/minute
Warning: Rate limits are per API token. Contact support for higher limits.