Docs
Messages API
Messages API
API endpoint for retrieving chat messages
The Messages API allows you to retrieve all messages for a specific chat. This endpoint returns the complete message history for a given chat ID, providing access to the conversation between the user and the AI assistant.
Endpoint
GET /faas/api/messages?chatId={chatId}Authentication
All requests must include an API key in the Authorization header:
Authorization: Bearer sk_your_api_keyAPI keys must start with the prefix sk_ and can be generated from your account dashboard.
Request Format
| Parameter | Type | Description | 
|---|---|---|
chatId | string | The ID of the chat to retrieve messages for | 
Example Request
GET /faas/api/messages?chatId=chat_12345Response Format
The response is an array of message objects directly from the database, each containing the following fields:
| Field | Type | Description | 
|---|---|---|
id | string | The unique identifier for the message | 
chatId | string | The ID of the chat this message belongs to | 
role | string | The role of the message sender (user or assistant) | 
content | object | The content of the message (may include various fields depending on message type) | 
createdAt | string | The timestamp when the message was created | 
updatedAt | string | The timestamp when the message was last updated | 
Example Response
[
  {
    "id": "msg_12345",
    "chatId": "chat_12345",
    "role": "user",
    "content": {
      "type": "text",
      "text": "How many users registered last month?"
    },
    "createdAt": "2023-06-15T10:30:00Z",
    "updatedAt": "2023-06-15T10:30:00Z"
  },
  {
    "id": "msg_67890",
    "chatId": "chat_12345",
    "role": "assistant",
    "content": {
      "type": "text",
      "text": "Based on the database, 157 users registered last month. Here's the SQL query I used:\n\n```sql\nSELECT COUNT(*) FROM users WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH);\n```\n\nThe results show that 157 new users registered in the past 30 days."
    },
    "createdAt": "2023-06-15T10:30:05Z",
    "updatedAt": "2023-06-15T10:30:05Z"
  }
]Error Codes
| Status Code | Description | 
|---|---|
| 400 | Missing or invalid chatId parameter | 
| 401 | Missing or invalid API key | 
| 403 | Unauthorized access to chat | 
| 404 | Chat not found | 
| 500 | Server error | 
Limitations
- The API returns all messages for the specified chat
 - For private chats, only the chat owner can access the messages
 - Public chats can be accessed by any authenticated user with a valid API key
 - The message content structure may vary depending on the message type
 
Example Usage
// Fetching messages for a specific chat
const response = await fetch('https://app.chatdb.live/faas/api/messages?chatId=chat_12345', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer sk_your_api_key'
  }
});
 
const messages = await response.json();
console.log(messages);