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

# Delete a message

> Deletes a specific message.

cascade=true also deletes the message immediately following
the selected message.

conversationRef can be either a conversationId or a persistent userId.




## OpenAPI

````yaml /openapi.yaml delete /agents/{agentId}/conversations/{conversationRef}/messages/{messageId}
openapi: 3.0.3
info:
  title: ReyGrid API
  version: 1.0.3
  description: |
    ReyGrid API

    ## Persistent user conversations

    If you want to build a separate conversation system for each user,
    build a wrapper layer around the ReyGrid API.

    The wrapper should manage the application's own user IDs and map them
    to ReyGrid conversations.

    The wrapper is responsible for:
    - Managing and identifying users.
    - Storing the relationship between the application's userId and
      ReyGrid conversationId.
    - Persisting conversation IDs in the application's own database.
    - Reusing the stored conversationId when the same user continues
      a conversation.
    - Verifying that conversation IDs belong to the expected user before
      using them.

    ReyGrid's userId can also be used as a stable identifier for persistent
    conversations. However, if the application requires its own user and
    conversation management, it should maintain this mapping in its own
    database.
servers:
  - url: https://reygrid.com/api/v1
security: []
paths:
  /agents/{agentId}/conversations/{conversationRef}/messages/{messageId}:
    delete:
      summary: Delete a message
      description: |
        Deletes a specific message.

        cascade=true also deletes the message immediately following
        the selected message.

        conversationRef can be either a conversationId or a persistent userId.
      operationId: deleteMessage
      parameters:
        - name: agentId
          in: path
          required: true
          description: The ID of the agent.
          schema:
            type: string
        - name: conversationRef
          in: path
          required: true
          description: |
            A conversation ID or persistent user ID.
          schema:
            type: string
        - name: messageId
          in: path
          required: true
          description: The ID of the message to delete.
          schema:
            type: string
        - name: cascade
          in: query
          required: false
          description: |
            When true, also deletes the message immediately following
            the selected message.
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: Message deleted successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeleteMessagesResponse'
              example:
                success: true
                deletedMessages:
                  count: 2
        '401':
          description: API key is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthErrorResponse'
        '404':
          description: Message not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: MESSAGE_NOT_FOUND
                  message: This message does not exist
      security:
        - apiKeyAuth: []
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >-
            curl -X DELETE
            "https://reygrid.com/api/v1/agents/{AgentId}/conversations/user_42/messages/msg_mgGdMG8f9PUjc?cascade=true"
            \
              -H "Authorization: Bearer $REYGRID_API_KEY"
        - lang: python
          label: Python SDK
          source: >-
            from reygrid import ReyGrid


            client = ReyGrid(api_key="YOUR_API_KEY")


            # cascade=True also deletes the messages after this one

            client.delete_message("{AgentId}", "user_42", "msg_mgGdMG8f9PUjc",
            cascade=True)
        - lang: javascript
          label: TypeScript SDK
          source: >-
            import { ReyGrid } from "reygrid";


            const client = new ReyGrid({ apiKey: "YOUR_API_KEY" });


            // cascade = true also deletes the messages after this one

            await client.deleteMessage("{AgentId}", "user_42",
            "msg_mgGdMG8f9PUjc", true);
components:
  schemas:
    DeleteMessagesResponse:
      type: object
      required:
        - success
        - deletedMessages
      properties:
        success:
          type: boolean
        deletedMessages:
          type: object
          required:
            - count
          properties:
            count:
              type: integer
    AuthErrorResponse:
      type: object
      required:
        - error
        - code
      properties:
        error:
          type: string
          example: Unauthorized
        code:
          type: string
          example: AUTH_REQUIRED
    ErrorResponse:
      type: object
      required:
        - success
        - error
      properties:
        success:
          type: boolean
        output:
          type: object
          additionalProperties: true
        error:
          $ref: '#/components/schemas/Error'
        usage:
          $ref: '#/components/schemas/ChatUsage'
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
        list:
          type: array
          description: |
            Validation error details.
            Present when error.code is INVALID_BODY.
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
    ChatUsage:
      type: object
      required:
        - credits
      properties:
        credits:
          type: number
    ValidationErrorItem:
      type: object
      additionalProperties: true
  securitySchemes:
    apiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API-Key
      description: ReyGrid API key sent as a Bearer token.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.