Create Chat
curl --request POST \
--url https://api.example.com/api/v1/chats/ \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <x-api-key>' \
--data '
{
"user_id": "<string>",
"title": "<string>",
"metadata": {}
}
'import requests
url = "https://api.example.com/api/v1/chats/"
payload = {
"user_id": "<string>",
"title": "<string>",
"metadata": {}
}
headers = {
"X-API-Key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({user_id: '<string>', title: '<string>', metadata: {}})
};
fetch('https://api.example.com/api/v1/chats/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/chats/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'user_id' => '<string>',
'title' => '<string>',
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/chats/"
payload := strings.NewReader("{\n \"user_id\": \"<string>\",\n \"title\": \"<string>\",\n \"metadata\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/chats/")
.header("X-API-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"title\": \"<string>\",\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/chats/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"title\": \"<string>\",\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"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
}
Chats
Create Chat
POST
/
api
/
v1
/
chats
/
Create Chat
curl --request POST \
--url https://api.example.com/api/v1/chats/ \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <x-api-key>' \
--data '
{
"user_id": "<string>",
"title": "<string>",
"metadata": {}
}
'import requests
url = "https://api.example.com/api/v1/chats/"
payload = {
"user_id": "<string>",
"title": "<string>",
"metadata": {}
}
headers = {
"X-API-Key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({user_id: '<string>', title: '<string>', metadata: {}})
};
fetch('https://api.example.com/api/v1/chats/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/chats/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'user_id' => '<string>',
'title' => '<string>',
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/chats/"
payload := strings.NewReader("{\n \"user_id\": \"<string>\",\n \"title\": \"<string>\",\n \"metadata\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/chats/")
.header("X-API-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"title\": \"<string>\",\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/chats/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"title\": \"<string>\",\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"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
}
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
string
required
Authentication header with your tenant’s API key
Request Body
string
required
The ID of the user creating the chat session
string
Optional custom title for the chat. If not provided, a title will be auto-generated.
object
Optional metadata object to store additional information about the chat
Response
string
Unique identifier for the chat session (UUID format)
string
The ID of the user who owns this chat
string
The tenant identifier (automatically determined from API key)
string
The title of the chat session
object
Configuration object containing metadata and other chat settings
string
Timestamp when the chat was created
string
Timestamp when the chat was last updated
string | null
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
400: Bad Request
400: Bad Request
Invalid request body or missing required fields
401: Unauthorized
401: Unauthorized
Invalid or missing API key
500: Internal Server Error
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_idis required in the request body - If
titleis not provided, the system will auto-generate one - The
tenant_idis 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