Create Chat
This endpoint creates a new chat session for a user. The chat session can then be used for real-time messaging via WebSocket connections.
Authentication
Authentication header with your tenant’s API key
Request Body
The ID of the user creating the chat session
Optional custom title for the chat. If not provided, a title will be auto-generated.
Optional metadata object to store additional information about the chat
Response
Unique identifier for the chat session (UUID format)
The ID of the user who owns this chat
The tenant identifier (automatically determined from API key)
The title of the chat session
Configuration object containing metadata and other chat settings
Timestamp when the chat was created
Timestamp when the chat was last updated
Timestamp of the last message in this chat (null for new chats)
{
"id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
"user_id": "user123",
"tenant_id": "tenant-uuid-here",
"title": "Support Session",
"config": {
"metadata": {
"department": "technical",
"priority": "high"
}
},
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"last_message_at": null
}
Error Responses
Invalid request body or missing required fields
Invalid or missing API key
500: Internal Server Error
Server error processing the request
Example Usage
cURL
curl -X POST "http://localhost:8000/api/v1/chats/" \
-H "X-API-Key: your-tenant-api-key" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user123",
"title": "Support Session",
"metadata": {
"department": "technical",
"priority": "high"
}
}'
JavaScript
fetch('http://localhost:8000/api/v1/chats/', {
method: 'POST',
headers: {
'X-API-Key': 'your-tenant-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
user_id: 'user123',
title: 'Support Session',
metadata: {
department: 'technical',
priority: 'high'
}
})
})
.then(response => response.json())
.then(data => {
console.log('Chat created:', data);
const chatId = data.id;
// Use chatId for WebSocket connection
})
.catch(error => console.error('Error:', error));
Python
import requests
import json
url = "http://localhost:8000/api/v1/chats/"
headers = {
"X-API-Key": "your-tenant-api-key",
"Content-Type": "application/json"
}
data = {
"user_id": "user123",
"title": "Support Session",
"metadata": {
"department": "technical",
"priority": "high"
}
}
response = requests.post(url, headers=headers, json=data)
chat_data = response.json()
print(f"Chat created with ID: {chat_data['id']}")
Notes
- Only
user_id is required in the request body
- If
title is not provided, the system will auto-generate one
- The
tenant_id is automatically determined from the API key
- If the user doesn’t exist, a user entity will be auto-created
- The chat ID returned should be used for subsequent WebSocket connections
- Metadata can contain any custom key-value pairs for your application needs