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

# Edit a message

> Replace the authenticated sender's message parts without changing its conversation sequence. User-sent messages require that user's session. Agent-sent messages require that agent's token. Messages can be edited for 15 minutes after creation and at most five times. Both the stored message and replacement must be text-bearing and cannot contain attachment parts. Relay does not send a push notification for edits.




## OpenAPI

````yaml /api-reference/openapi.yaml patch /v1/messages/{message_id}
openapi: 3.1.0
info:
  title: Relay developer API
  version: '0.1'
  description: >
    Add Relay as a channel for your agent, receive messages, and reply with
    plain HTTPS and JSON. Authenticate every request with an Agent Token unless
    the endpoint is marked public. The postback_interactions sync feature
    controls whether clients render message components interactively; component
    data parts can always be sent.
  x-relay-feature-availability:
    postback_interactions: off-by-default-preview
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.relayapp.im
    description: Production
security:
  - agentToken: []
tags:
  - name: Agent
    description: Inspect the agent controlled by the current Agent Token.
  - name: Messages
    description: Send finalized messages, pipe native agent output, and react.
  - name: Groups
    description: Propose consent-based groups and observe their terminal state.
  - name: Events
    description: >
      Receive durable inbound events, either through signed webhook receivers or
      by long-polling `GET /v1/events`. The two modes are mutually exclusive per
      agent, enforced per request; around a webhook registration or disable
      there is a brief transition window in which both paths can observe the
      same events. Delivery is at least once everywhere — always deduplicate by
      `event_id`.
  - name: Pairing
    description: >
      Device-code pairing for terminal bridges: create a pairing code on a
      computer, let the Relay app claim it, and recover the minted Agent Token
      only with that computer's poll credential. The token never travels to the
      phone.
  - name: Public
    description: Read approved Store agents and share profiles without authentication.
paths:
  /v1/messages/{message_id}:
    patch:
      tags:
        - Messages
      summary: Edit a message
      description: >
        Replace the authenticated sender's message parts without changing its
        conversation sequence. User-sent messages require that user's session.
        Agent-sent messages require that agent's token. Messages can be edited
        for 15 minutes after creation and at most five times. Both the stored
        message and replacement must be text-bearing and cannot contain
        attachment parts. Relay does not send a push notification for edits.
      operationId: editMessage
      parameters:
        - $ref: '#/components/parameters/MessageId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessageEditInput'
      responses:
        '200':
          description: >-
            Canonical edited message with revision history from oldest to
            newest.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageEditResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: The message does not exist or was not sent by this actor.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The 15-minute edit window or five-revision limit has passed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: >-
            The replacement is invalid, is not text-bearing, or contains
            attachment parts.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - agentToken: []
        - userSession: []
components:
  parameters:
    MessageId:
      name: message_id
      in: path
      required: true
      schema:
        type: string
      example: msg_01JZM4Q9VN
  schemas:
    MessageEditInput:
      type: object
      additionalProperties: false
      required:
        - parts
      properties:
        parts:
          type: array
          minItems: 1
          maxItems: 32
          description: >
            Full replacement for the stored parts. At least one text part is
            required. Media, voice memo, and all attachment references are
            rejected.
          items:
            $ref: '#/components/schemas/EditablePartInput'
          contains:
            $ref: '#/components/schemas/TextPartInput'
          minContains: 1
    MessageEditResponse:
      type: object
      additionalProperties: false
      required:
        - message
      properties:
        message:
          $ref: '#/components/schemas/EditedMessage'
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              example: invalid_request
            message:
              type: string
              example: conversation_id is required
    EditablePartInput:
      oneOf:
        - $ref: '#/components/schemas/TextPartInput'
        - $ref: '#/components/schemas/LinkPreviewPartInput'
        - $ref: '#/components/schemas/DataPartInput'
      discriminator:
        propertyName: type
    EditedMessage:
      allOf:
        - $ref: '#/components/schemas/VisibleMessage'
        - type: object
          required:
            - edited_at
            - revisions
          properties:
            edited_at:
              type: string
              format: date-time
            revisions:
              type: array
              minItems: 1
              maxItems: 5
              items:
                $ref: '#/components/schemas/MessageRevision'
    TextPartInput:
      type: object
      additionalProperties: false
      required:
        - type
        - text
      properties:
        type:
          type: string
          const: text
        text:
          type: string
          minLength: 1
          description: UTF-8 text, limited to 8 KB by the server.
    LinkPreviewPartInput:
      type: object
      additionalProperties: false
      required:
        - type
        - url
      description: URL rendered as a native rich preview when metadata is available.
      properties:
        type:
          type: string
          const: link_preview
        url:
          type: string
          format: uri
          pattern: ^https://
          maxLength: 2048
    DataPartInput:
      type: object
      additionalProperties: false
      required:
        - type
        - data
      properties:
        type:
          type: string
          const: data
        data:
          description: >
            Integration-defined JSON, limited to 16 KB by the server. Relay
            validates recognized component kinds (buttons, select, card,
            confirm, and agent_permission_request), synthesizes their fallback
            string when absent, and leaves unknown kinds unchanged for client
            fallback rendering. Consumers must ignore unknown fields inside
            known kinds. The option_ids array name is reserved for a future
            multi-select tap-result shape; v1 does not implement multi-select.
            Component parts are valid only in 1:1 conversations. See the Message
            components documentation. group_invite is a separate internal
            component committed only by the invite endpoint; ordinary agent
            message sends that contain it return 422.
    VisibleMessage:
      type: object
      additionalProperties: false
      required:
        - id
        - conversation_id
        - sequence
        - sender
        - parts
        - fallback_text
        - status
        - created_at
      properties:
        id:
          type: string
          example: msg_01JZM3T8AH
        conversation_id:
          type: string
          example: cnv_01JZC7K4RQ
        sequence:
          type: integer
          description: Order inside the conversation. It is unrelated to webhook event IDs.
        sender:
          $ref: '#/components/schemas/Sender'
        parts:
          type: array
          items:
            $ref: '#/components/schemas/Part'
        reply_to:
          $ref: '#/components/schemas/ReplyRef'
        invoked_agents:
          type: array
          uniqueItems: true
          items:
            type: string
          description: Agents explicitly invoked by this human group message.
        suggestions:
          type: array
          maxItems: 8
          description: >
            Agent-attached quick-reply chips. Clients render them only while
            this message is the newest in the conversation.
          items:
            $ref: '#/components/schemas/Suggestion'
        reactions:
          type: array
          description: >-
            Current reactions. History and bootstrap projections include this
            array.
          items:
            $ref: '#/components/schemas/ProjectedReaction'
        fallback_text:
          type: string
          description: Plain-language representation used by notifications and search.
        status:
          type: string
          enum:
            - sent
            - delivered
            - read
            - completed
            - failed
          example: sent
        delivered_at:
          type: string
          format: date-time
        read_at:
          type: string
          format: date-time
        edited_at:
          type: string
          format: date-time
          description: >-
            Time of the latest edit. Omitted when the message has never been
            edited.
        revisions:
          type: array
          maxItems: 5
          description: >
            Prior canonical parts and fallback text, ordered from oldest to
            newest. History and bootstrap projections include an empty array for
            unedited messages.
          items:
            $ref: '#/components/schemas/MessageRevision'
        created_at:
          type: string
          format: date-time
    MessageRevision:
      type: object
      additionalProperties: false
      required:
        - parts
        - fallback_text
        - replaced_at
      properties:
        parts:
          type: array
          items:
            $ref: '#/components/schemas/Part'
        fallback_text:
          type: string
        replaced_at:
          type: string
          format: date-time
          description: Time this snapshot stopped being the canonical content.
    Sender:
      type: object
      required:
        - kind
        - id
      properties:
        kind:
          type: string
          enum:
            - user
            - agent
            - system
        id:
          type: string
          example: usr_01JZU1F0BD
    Part:
      oneOf:
        - $ref: '#/components/schemas/TextPart'
        - $ref: '#/components/schemas/MediaPart'
        - $ref: '#/components/schemas/VoiceMemoPart'
        - $ref: '#/components/schemas/LinkPreviewPart'
        - $ref: '#/components/schemas/DataPart'
      discriminator:
        propertyName: type
    ReplyRef:
      type:
        - object
        - 'null'
      properties:
        message_id:
          type: string
          example: msg_01JZM3T8AH
        part_index:
          type: integer
          example: 0
    Suggestion:
      type: object
      additionalProperties: false
      required:
        - text
      properties:
        text:
          type: string
          minLength: 1
          maxLength: 96
          description: Chip label; also the exact text sent when the user taps it.
          example: Everyone
    ProjectedReaction:
      type: object
      additionalProperties: false
      required:
        - part_index
        - emoji
        - actor_kind
        - actor_id
      properties:
        part_index:
          type:
            - integer
            - 'null'
          minimum: 0
        emoji:
          type: string
        actor_kind:
          type: string
          enum:
            - user
            - contact
        actor_id:
          type: string
          pattern: ^(usr|agt)_
    TextPart:
      type: object
      additionalProperties: false
      required:
        - part_index
        - type
        - text
      properties:
        part_index:
          type: integer
          minimum: 0
        type:
          type: string
          const: text
        text:
          type: string
    MediaPart:
      type: object
      additionalProperties: false
      required:
        - part_index
        - type
        - url
      properties:
        part_index:
          type: integer
          minimum: 0
        type:
          type: string
          const: media
        url:
          type: string
          format: uri
        attachment_id:
          type: string
          pattern: ^att_
    VoiceMemoPart:
      type: object
      additionalProperties: false
      required:
        - part_index
        - type
        - url
      properties:
        part_index:
          type: integer
          minimum: 0
        type:
          type: string
          const: voice_memo
        url:
          type: string
          format: uri
        attachment_id:
          type: string
          pattern: ^att_
        duration_ms:
          type: integer
          minimum: 0
    LinkPreviewPart:
      type: object
      additionalProperties: false
      required:
        - part_index
        - type
        - url
      properties:
        part_index:
          type: integer
          minimum: 0
        type:
          type: string
          const: link_preview
        url:
          type: string
          format: uri
          maxLength: 2048
    DataPart:
      type: object
      additionalProperties: false
      required:
        - part_index
        - type
        - data
      properties:
        part_index:
          type: integer
          minimum: 0
        type:
          type: string
          const: data
        data:
          anyOf:
            - $ref: '#/components/schemas/GroupInviteComponentData'
            - description: Other integration-defined JSON data.
    GroupInviteComponentData:
      type: object
      additionalProperties: false
      description: >
        Internal consent card committed by POST /v1/groups/invites. Ordinary
        agent message sends cannot supply this component.
      required:
        - type
        - invite_id
        - title
        - expires_at
        - members
      properties:
        type:
          type: string
          const: group_invite
        invite_id:
          type: string
          pattern: ^inv_
        title:
          type: string
          minLength: 1
          maxLength: 100
        reason:
          type: string
          minLength: 1
          maxLength: 200
        expires_at:
          type: string
          format: date-time
        conversation:
          type: object
          additionalProperties: false
          required:
            - id
            - title
          properties:
            id:
              type: string
              pattern: ^cnv_
            title:
              type: string
              minLength: 1
              maxLength: 100
        members:
          type: array
          minItems: 1
          maxItems: 24
          items:
            $ref: '#/components/schemas/GroupInviteMember'
    GroupInviteMember:
      type: object
      additionalProperties: false
      required:
        - user_id
        - display_name
        - avatar_url
        - state
      properties:
        user_id:
          type: string
          pattern: ^usr_
        display_name:
          type: string
        avatar_url:
          type:
            - string
            - 'null'
        state:
          type: string
          enum:
            - invited
            - accepted
            - declined
          description: >
            invited has not answered yet, accepted is in the live conversation,
            and declined answered no.
  responses:
    Unauthorized:
      description: Token is absent or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    agentToken:
      type: http
      scheme: bearer
      description: Agent Token (`rly_live_…`), shown once at agent creation.
    userSession:
      type: http
      scheme: bearer
      description: >-
        Better Auth user-session bearer used by the Relay app; never an Agent
        Token.

````