> ## 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.

# Add multiple messages to a chat via API key

> Bulk insert multiple messages into a chat using API key authentication. MessageIndex values are auto-calculated sequentially. Requires CHAT scope.



## OpenAPI

````yaml post /api/chat-messages/chat/id/{chatId}/bulk
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}/bulk:
    post:
      tags:
        - chat-messages-api-key
      summary: Add multiple messages to a chat via API key
      description: >-
        Bulk insert multiple messages into a chat using API key authentication.
        MessageIndex values are auto-calculated sequentially. Requires CHAT
        scope.
      operationId: ChatMessagesApiKeyController_addMultipleMessages
      parameters:
        - name: chatId
          required: true
          in: path
          description: Chat ID
          schema:
            example: c1a83d84-7154-464c-bd19-a9f10e0a067f
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BulkCreateMessagesDto'
      responses:
        '201':
          description: Messages added to chat successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BulkCreateResponse'
        '404':
          description: Chat not found or access denied
      security:
        - ApiKeyAuth: []
components:
  schemas:
    BulkCreateMessagesDto:
      type: object
      properties:
        messages:
          description: Array of messages to create
          type: array
          items:
            $ref: '#/components/schemas/CreateMessageForChatDto'
      required:
        - messages
    BulkCreateResponse:
      type: object
      properties:
        messages:
          description: Created messages
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
        count:
          type: number
          description: Number of messages created
        chatId:
          type: string
          description: Chat ID where messages were added
          example: c1a83d84-7154-464c-bd19-a9f10e0a067f
      required:
        - messages
        - count
        - chatId
    CreateMessageForChatDto:
      type: object
      properties:
        role:
          type: string
          description: Role of the message sender
          enum:
            - system
            - assistant
            - user
          example: user
        content:
          type: string
          description: Content of the message
          example: Hello, can you help me with my project?
        metadata:
          type: object
          description: Optional metadata as key-value pairs
          example:
            model: claude-3-sonnet
            tokens: 150
        fileIds:
          description: Array of file IDs to associate with this message
          example:
            - f1a83d84-7154-464c-bd19-a9f10e0a067f
            - f2b94e95-8265-575d-ce2a-b0f21f1b178g
          type: array
          items:
            type: string
      required:
        - role
        - content
    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

````