Skip to main content
GET
List Messages

List Messages

Retrieves messages from a chat session with support for pagination, filtering, and sorting. This endpoint is essential for displaying conversation history and implementing real-time chat interfaces.

Endpoint

Authentication

string
required
Your Nexus API key for authentication

Path Parameters

string
required
The session ID to retrieve messages from

Query Parameters

number
default:"20"
Number of messages to return (1-100)
string
default:"asc"
Sort order for messages
  • asc - Oldest messages first (chronological)
  • desc - Newest messages first (reverse chronological)
string
Cursor for pagination. Returns messages after this message ID.
string
Cursor for pagination. Returns messages before this message ID.

Response Fields

Message[]
required
Array of message objects

Example Usage

Pagination Patterns

Forward Pagination

Backward Pagination

Real-time Polling

Message Types

User Messages

Assistant Messages

Tool Messages

System Messages

Error Responses

Best Practices

  • Use cursors (after/before) instead of offset-based pagination
  • Request only as many messages as needed
  • Cache messages client-side to reduce API calls
  • Use appropriate page sizes (20-50 messages)
  • Implement exponential backoff for polling
  • Track the latest message ID to fetch only new messages
  • Handle duplicate messages gracefully
  • Sanitize message content before displaying
  • Handle different message types appropriately
  • Show loading states during message fetching
  • Implement virtual scrolling for large conversations
  • Fetch messages in batches
  • Implement lazy loading for conversation history
  • Use descending order for recent messages
  • Minimize API calls with smart caching