> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leanmcp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get all messages for a chat via API key

> Returns all messages for a specific chat ordered by messageIndex using API key authentication. Requires CHAT scope.



## OpenAPI

````yaml get /api/chat-messages/chat/id/{chatId}
openapi: 3.0.0
info:
  title: LeanMCP SDK API
  description: >-
    API endpoints for LeanMCP SDK integration. These endpoints use API key
    authentication and are designed for programmatic access from the CLI and
    SDK.
  version: 1.0.0
servers:
  - url: https://api.leanmcp.com
    description: Production
  - url: http://localhost:3001
    description: Local Development
security: []
tags:
  - name: builds-sdk
  - name: chat-messages-api-key
  - name: chats-api-key
  - name: deployments-api-key
  - name: deployments-sdk
  - name: mapping-sdk
  - name: projects-api-key
paths:
  /api/chat-messages/chat/id/{chatId}:
    get:
      tags:
        - chat-messages-api-key
      summary: Get all messages for a chat via API key
      description: >-
        Returns all messages for a specific chat ordered by messageIndex using
        API key authentication. Requires CHAT scope.
      operationId: ChatMessagesApiKeyController_getMessagesForChat
      parameters:
        - name: chatId
          required: true
          in: path
          description: Chat ID
          schema:
            example: c1a83d84-7154-464c-bd19-a9f10e0a067f
            type: string
      responses:
        '200':
          description: Messages retrieved successfully
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ChatMessage'
        '404':
          description: Chat not found or access denied
      security:
        - ApiKeyAuth: []
components:
  schemas:
    ChatMessage:
      type: object
      properties:
        id:
          type: string
          description: Unique message identifier (UUID)
        chatId:
          type: string
          description: Chat ID this message belongs to (UUID)
          example: c1a83d84-7154-464c-bd19-a9f10e0a067f
        userId:
          type: string
          description: User ID who owns this message
        role:
          type: string
          enum:
            - system
            - assistant
            - user
          description: Role of the message sender
        content:
          type: string
          description: Message content/text
        messageIndex:
          type: number
          description: Order of message in the chat (0-based)
          minimum: 0
        createdAt:
          type: string
          description: Timestamp when message was created
        updatedAt:
          type: string
          description: Timestamp when message was last updated
        metadata:
          type: object
          description: Additional metadata for the message
          additionalProperties: true
      required:
        - id
        - chatId
        - userId
        - role
        - content
        - messageIndex
        - createdAt
        - updatedAt
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Enter your LeanMCP API key

````