Skip to main content
GET
/
api
/
v1
/
chats
/
{chat_id}
Get Chat
curl --request GET \
  --url https://api.example.com/api/v1/chats/{chat_id} \
  --header 'X-API-Key: <x-api-key>'
{
  "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "user_id": "user123",
  "tenant_id": "tenant-uuid-here",
  "title": "Support Session",
  "config": {
    "metadata": {
      "department": "technical",
      "priority": "high",
      "category": "account_issue"
    }
  },
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:35:00Z",
  "last_message_at": "2024-01-15T10:35:00Z",
  "message_count": 12,
  "status": "active"
}

Get Chat

This endpoint retrieves detailed information about a specific chat session, including its configuration and metadata.

Authentication

X-API-Key
string
required
Authentication header with your tenant’s API key

Path Parameters

chat_id
string
required
The unique identifier (UUID) of the chat to retrieve

Response

id
string
Unique identifier for the chat session
user_id
string
The ID of the user who owns this chat
tenant_id
string
The tenant identifier
title
string
The title of the chat session
config
object
Configuration object containing metadata and chat settings
created_at
string
Timestamp when the chat was created
updated_at
string
Timestamp when the chat was last updated
last_message_at
string | null
Timestamp of the last message in this chat
message_count
integer
Total number of messages in this chat
status
string
Current status of the chat (e.g., “active”, “closed”)
{
  "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "user_id": "user123",
  "tenant_id": "tenant-uuid-here",
  "title": "Support Session",
  "config": {
    "metadata": {
      "department": "technical",
      "priority": "high",
      "category": "account_issue"
    }
  },
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:35:00Z",
  "last_message_at": "2024-01-15T10:35:00Z",
  "message_count": 12,
  "status": "active"
}

Error Responses

Invalid or missing API key
Chat not found or doesn’t belong to your tenant
Server error processing the request

Example Usage

cURL

curl -X GET "http://localhost:8000/api/v1/chats/a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d" \
  -H "X-API-Key: your-tenant-api-key"

JavaScript

const chatId = 'a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d';

fetch(`http://localhost:8000/api/v1/chats/${chatId}`, {
  method: 'GET',
  headers: {
    'X-API-Key': 'your-tenant-api-key'
  }
})
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return response.json();
})
.then(chat => {
  console.log(`Chat: ${chat.title}`);
  console.log(`Messages: ${chat.message_count}`);
  console.log(`Last activity: ${chat.last_message_at}`);
  console.log(`Status: ${chat.status}`);
})
.catch(error => console.error('Error:', error));

Python

import requests

chat_id = "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"
url = f"http://localhost:8000/api/v1/chats/{chat_id}"
headers = {"X-API-Key": "your-tenant-api-key"}

response = requests.get(url, headers=headers)

if response.status_code == 200:
    chat = response.json()
    print(f"Chat: {chat['title']}")
    print(f"Messages: {chat['message_count']}")
    print(f"Last activity: {chat['last_message_at']}")
    print(f"Status: {chat['status']}")
elif response.status_code == 404:
    print("Chat not found")
else:
    print(f"Error: {response.status_code}")

React Hook Example

import { useState, useEffect } from 'react';

function useChat(chatId) {
  const [chat, setChat] = useState(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() => {
    if (!chatId) return;

    fetch(`http://localhost:8000/api/v1/chats/${chatId}`, {
      headers: {
        'X-API-Key': 'your-tenant-api-key'
      }
    })
    .then(response => {
      if (!response.ok) {
        throw new Error('Chat not found');
      }
      return response.json();
    })
    .then(setChat)
    .catch(setError)
    .finally(() => setLoading(false));
  }, [chatId]);

  return { chat, loading, error };
}

// Usage in component
function ChatHeader({ chatId }) {
  const { chat, loading, error } = useChat(chatId);

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;
  if (!chat) return null;

  return (
    <div>
      <h1>{chat.title}</h1>
      <p>{chat.message_count} messages</p>
      <p>Status: {chat.status}</p>
    </div>
  );
}

Notes

  • Only chats belonging to your tenant can be accessed
  • This endpoint is useful for retrieving chat metadata before connecting via WebSocket
  • The config object contains any custom metadata you stored when creating the chat
  • message_count gives you a quick overview without fetching all messages
  • Use this endpoint to validate chat existence before establishing WebSocket connections