Skip to main content

Overview

The Messages API allows you to create, retrieve, update, and delete messages within conversations. Messages are the core content of conversations and can include text, images, and other content types. All message endpoints are prefixed with /api/messages.

List Messages

Retrieve messages with pagination and filtering:
GET /api/messages
Authorization: Bearer <token>

Query Parameters

conversationId
string
Filter by conversation ID
messageId
string
Get specific message by ID
Search messages by content (uses MeiliSearch)
cursor
string
Pagination cursor
pageSize
number
default:"25"
Number of results per page
sortBy
string
default:"createdAt"
Sort field: endpoint, createdAt, or updatedAt
sortDirection
string
default:"desc"
Sort direction: asc or desc

Response

messages
TMessage[]
Array of message objects
nextCursor
string | null
Cursor for next page (null if no more pages)
{
  "messages": [
    {
      "messageId": "msg123",
      "conversationId": "conv456",
      "parentMessageId": "msg122",
      "text": "What are the best practices for machine learning?",
      "content": [
        {
          "type": "text",
          "text": "What are the best practices for machine learning?"
        }
      ],
      "sender": "User",
      "isCreatedByUser": true,
      "createdAt": "2024-01-15T10:00:00Z",
      "endpoint": "openAI",
      "model": "gpt-4"
    }
  ],
  "nextCursor": "cursor_abc"
}

Get Messages by Conversation

Retrieve all messages in a specific conversation:
GET /api/messages/:conversationId
Authorization: Bearer <token>

Path Parameters

conversationId
string
required
Conversation ID

Response

Returns an array of messages ordered by creation time.
[
  {
    "messageId": "msg123",
    "conversationId": "conv456",
    "text": "Hello!",
    "isCreatedByUser": true,
    "createdAt": "2024-01-15T10:00:00Z"
  },
  {
    "messageId": "msg124",
    "parentMessageId": "msg123",
    "conversationId": "conv456",
    "text": "Hi! How can I help you today?",
    "isCreatedByUser": false,
    "sender": "Assistant",
    "createdAt": "2024-01-15T10:00:01Z"
  }
]

Get Single Message

Retrieve a specific message:
GET /api/messages/:conversationId/:messageId
Authorization: Bearer <token>

Path Parameters

conversationId
string
required
Conversation ID
messageId
string
required
Message ID

Response

messageId
string
Unique message identifier
conversationId
string
Parent conversation ID
parentMessageId
string
ID of the previous message in the conversation thread
text
string
Message text content (legacy field)
content
TMessageContentParts[]
Array of content parts (text, images, artifacts, etc.)
sender
string
Sender name or identifier
isCreatedByUser
boolean
Whether the message was created by the user (vs AI)
endpoint
string
AI endpoint used
model
string
Model identifier
tokenCount
number
Number of tokens in the message
attachments
TAttachment[]
File attachments
unfinished
boolean
Whether the message generation was interrupted
error
boolean
Whether an error occurred during generation

Create Message

Create a new message in a conversation:
POST /api/messages/:conversationId
Authorization: Bearer <token>
Content-Type: application/json

{
  "messageId": "msg125",
  "parentMessageId": "msg124",
  "text": "Tell me more about neural networks",
  "isCreatedByUser": true,
  "sender": "User"
}

Path Parameters

conversationId
string
required
Conversation ID

Request Body

messageId
string
required
Unique message identifier (UUID)
parentMessageId
string
ID of the parent message
text
string
Message text content
content
TMessageContentParts[]
Structured content parts
sender
string
required
Sender identifier
isCreatedByUser
boolean
required
Whether this is a user message
endpoint
string
AI endpoint identifier
model
string
Model identifier
attachments
TAttachment[]
File attachments

Response

Returns the created message object with HTTP status 201.

Update Message

Update an existing message’s text content:
PUT /api/messages/:conversationId/:messageId
Authorization: Bearer <token>
Content-Type: application/json

{
  "text": "Updated message text",
  "model": "gpt-4"
}

Path Parameters

conversationId
string
required
Conversation ID
messageId
string
required
Message ID to update

Request Body

text
string
required
New message text
model
string
Model used (for token counting)
index
number
Index of content part to update (for multi-part content)

Response

Returns the updated message object.

Update Content Part

To update a specific content part by index:
{
  "text": "Updated content part",
  "index": 0,
  "model": "gpt-4"
}
Only text and think content types can be updated.

Update Message Feedback

Add or update feedback (thumbs up/down) for a message:
PUT /api/messages/:conversationId/:messageId/feedback
Authorization: Bearer <token>
Content-Type: application/json

{
  "feedback": {
    "rating": "thumbsUp",
    "comment": "Very helpful response!"
  }
}

Request Body

feedback
object
Feedback object (or null to remove feedback)
feedback.rating
string
Rating: thumbsUp or thumbsDown
feedback.comment
string
Optional feedback comment

Response

{
  "messageId": "msg124",
  "conversationId": "conv456",
  "feedback": {
    "rating": "thumbsUp",
    "comment": "Very helpful response!"
  }
}

Delete Message

Delete a specific message:
DELETE /api/messages/:conversationId/:messageId
Authorization: Bearer <token>

Path Parameters

conversationId
string
required
Conversation ID
messageId
string
required
Message ID to delete

Response

HTTP 204 No Content on success.

Branch Message

Create a new message branch from parallel agent responses:
POST /api/messages/branch
Authorization: Bearer <token>
Content-Type: application/json

{
  "messageId": "msg124",
  "agentId": "agent_abc"
}

Request Body

messageId
string
required
Source message ID containing parallel responses
agentId
string
required
Agent ID to filter content by

Response

Creates a new message containing only the content from the specified agent.
{
  "messageId": "msg125",
  "parentMessageId": "msg123",
  "conversationId": "conv456",
  "content": [
    {
      "type": "text",
      "text": "Content from agent_abc only"
    }
  ],
  "sender": "Agent ABC",
  "isCreatedByUser": false
}

Update Artifact

Update code artifacts within a message:
POST /api/messages/artifact/:messageId
Authorization: Bearer <token>
Content-Type: application/json

{
  "index": 0,
  "original": "console.log('Hello')",
  "updated": "console.log('Hello, World!')"
}

Path Parameters

messageId
string
required
Message ID containing the artifact

Request Body

index
number
required
Index of the artifact to update (0-based)
original
string
required
Original artifact content (for verification)
updated
string
required
New artifact content

Response

conversationId
string
Conversation ID
content
TMessageContentParts[]
Updated message content
text
string
Updated message text
{
  "conversationId": "conv456",
  "content": [...],
  "text": "Updated message with modified artifact"
}

Message Content Types

Messages support multiple content types:

Text Content

{
  "type": "text",
  "text": "Message content"
}

Image Content

{
  "type": "image_url",
  "image_url": {
    "url": "https://example.com/image.png"
  }
}

Code Artifact

{
  "type": "code",
  "code": "console.log('Hello, World!');",
  "language": "javascript"
}

Thinking Process

{
  "type": "think",
  "think": "Internal reasoning process..."
}

Message Attachments

Messages can include file attachments:
{
  "attachments": [
    {
      "file_id": "file_abc123",
      "filename": "document.pdf",
      "type": "file",
      "size": 102400,
      "filepath": "/uploads/file_abc123.pdf"
    }
  ]
}

Search Messages

Search across all messages (requires MeiliSearch):
GET /api/messages?search=machine%20learning
Authorization: Bearer <token>
Returns messages matching the search query with conversation context.

Error Responses

Message Not Found

{
  "error": "Message not found"
}
HTTP Status: 404

Invalid Content Update

{
  "error": "Cannot update non-text content"
}
HTTP Status: 400

Cannot Branch User Message

{
  "error": "Cannot branch from user messages"
}
HTTP Status: 400

TypeScript Types

import type { TMessage, TMessageContentParts } from 'librechat-data-provider';

interface TMessage {
  messageId: string;
  conversationId: string;
  parentMessageId?: string;
  text?: string;
  content?: TMessageContentParts[];
  sender: string;
  isCreatedByUser: boolean;
  endpoint?: string;
  model?: string;
  tokenCount?: number;
  attachments?: TAttachment[];
  createdAt?: string;
  updatedAt?: string;
  unfinished?: boolean;
  error?: boolean;
  feedback?: TMessageFeedback;
}

Build docs developers (and LLMs) love