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

# List Conversation Messages

> **Available for**: Chatflow, Agent, Chatbot, Legacy Agent apps.

Returns a conversation's message history, newest first. Pass `first_id` to page backward into older messages.



## OpenAPI

````yaml /en/api-reference/openapi_service.json get /messages
openapi: 3.0.1
info:
  description: >-
    REST API for Dify applications and knowledge bases. Application endpoints
    authenticate with an app API key; knowledge endpoints authenticate with a
    dataset API key.
  title: Dify Service API
  version: 1.0.0
servers:
  - description: >-
      Base URL of the Dify Service API. For self-hosted deployments, replace it
      with your own API base URL.
    url: https://{api_base_url}
    variables:
      api_base_url:
        default: api.dify.ai/v1
        description: Host and path of the API base URL, without the `https://` prefix.
security:
  - ApiKeyAuth: []
tags:
  - description: Operations related to chat messages and interactions.
    name: Chat Messages
  - description: File upload and preview operations.
    name: Files
  - description: Operations related to end user information.
    name: End Users
  - description: User feedback operations.
    name: Feedback
  - description: Operations related to managing conversations.
    name: Conversations
  - description: Text-to-Speech and Speech-to-Text operations.
    name: Audio
  - description: Operations to retrieve application settings and information.
    name: Applications
  - description: Operations related to managing annotations for direct replies.
    name: Annotations
  - description: Endpoints for resuming paused workflows that require human input.
    name: Human Input
  - description: Operations for executing and managing workflows.
    name: Workflow Runs
  - description: Operations related to text generation and completion.
    name: Completion Messages
  - description: >-
      Operations for managing knowledge bases, including creation,
      configuration, and retrieval.
    name: Knowledge Bases
  - description: >-
      Operations for creating, updating, and managing documents within a
      knowledge base.
    name: Documents
  - description: Operations for managing document chunks and child chunks.
    name: Chunks
  - description: >-
      Operations for managing knowledge base metadata fields and document
      metadata values.
    name: Metadata
  - description: Operations for managing knowledge base tags and tag bindings.
    name: Tags
  - description: Operations for retrieving available models.
    name: Models
  - description: >-
      Operations for managing and running knowledge pipelines, including
      datasource plugins and pipeline execution.
    name: Knowledge Pipeline
  - description: Ask a knowledge base a question and stream the answer.
    name: Queries
  - description: Inspect what a query retrieved and why.
    name: Query Records
  - description: Run a research question in the background and collect its results.
    name: Research Tasks
  - description: >-
      Read the documents in a knowledge base, their files, revisions, and
      chunks; label documents with metadata.
    name: Documents and Chunks
  - description: >-
      Follow, cancel, or retry indexing, and list the knowledge base's
      background tasks.
    name: Indexing Tasks
  - description: >-
      Follow the deletion of a document file, a batch of files, or a source
      until it finishes.
    name: Deletion Jobs
  - description: >-
      Manage the sources that feed a knowledge base, their sync schedules, and
      their connections.
    name: Sources
  - description: >-
      Sync a source now, import website pages or provider items, and follow,
      cancel, or retry the runs.
    name: Source Syncs and Imports
  - description: >-
      Read and change the knowledge base's models and retrieval settings, and
      follow the migration a change starts.
    name: Settings
paths:
  /messages:
    get:
      tags:
        - Conversations
      summary: List Conversation Messages
      description: >-
        **Available for**: Chatflow, Agent, Chatbot, Legacy Agent apps.


        Returns a conversation's message history, newest first. Pass `first_id`
        to page backward into older messages.
      operationId: getConversationHistory
      parameters:
        - description: >-
            ID of the conversation to read. Get conversation IDs from [List
            Conversations](/en/api-reference/conversations/list-conversations).
          in: query
          name: conversation_id
          required: true
          schema:
            type: string
        - description: >-
            End-user identifier, defined by your app and unique within it. See
            [End User Identity](/en/api-reference/guides/end-user-identity).
          in: query
          name: user
          required: false
          schema:
            type: string
        - description: >-
            Pagination cursor: the `id` of the first message on the current
            page. Pass it to fetch the previous (older) page; omit to fetch the
            latest messages.
          in: query
          name: first_id
          required: false
          schema:
            type: string
        - description: Number of chat history messages to return per request.
          in: query
          name: limit
          required: false
          schema:
            default: 20
            maximum: 100
            minimum: 1
            type: integer
      responses:
        '200':
          content:
            application/json:
              examples:
                conversationHistory:
                  summary: Response Example
                  value:
                    data:
                      - agent_thoughts: []
                        answer: iPhone 13 Pro Max specs are listed here:...
                        answer_tokens: 58
                        conversation_id: 45701982-8118-4bc5-8e9b-64562b4555f2
                        created_at: 1705407629
                        currency: USD
                        error: null
                        extra_contents: []
                        feedback:
                          rating: like
                        id: 9da23599-e713-473b-982c-4328d4f5c78a
                        inputs:
                          city: San Francisco
                        message_files: []
                        message_tokens: 100
                        parent_message_id: null
                        provider_response_latency: 1.234
                        query: What are the specs of the iPhone 13 Pro Max?
                        retriever_resources: []
                        status: normal
                        total_price: '0.0012825'
                        total_tokens: 158
                    has_more: false
                    limit: 20
              schema:
                $ref: '#/components/schemas/ConversationHistoryResponse'
          description: Successfully retrieved conversation history.
        '400':
          content:
            application/json:
              examples:
                not_chat_app:
                  summary: not_chat_app
                  value:
                    code: not_chat_app
                    message: Please check if your app mode matches the right API route.
                    status: 400
          description: '`not_chat_app` : App mode does not match the API route.'
        '403':
          content:
            application/json:
              examples:
                app_abnormal_status:
                  summary: app_abnormal_status
                  value:
                    code: app_abnormal_status
                    message: The app's status is abnormal.
                    status: 403
                app_api_disabled:
                  summary: app_api_disabled
                  value:
                    code: app_api_disabled
                    message: The app's API service has been disabled.
                    status: 403
                app_not_found:
                  summary: app_not_found
                  value:
                    code: app_not_found
                    message: The app no longer exists.
                    status: 403
                workspace_archived:
                  summary: workspace_archived
                  value:
                    code: workspace_archived
                    message: The workspace's status is archived.
                    status: 403
          description: |-
            - `app_not_found` : The app no longer exists.
            - `app_abnormal_status` : The app's status is abnormal.
            - `app_api_disabled` : API access is disabled for the app.
            - `workspace_archived` : The app's workspace is archived.
        '404':
          content:
            application/json:
              examples:
                conversation_not_exists:
                  summary: not_found
                  value:
                    code: not_found
                    message: Conversation Not Exists.
                    status: 404
                first_message_not_exists:
                  summary: not_found
                  value:
                    code: not_found
                    message: First Message Not Exists.
                    status: 404
          description: |-
            - `not_found` : Conversation does not exist.
            - `not_found` : First message does not exist (invalid `first_id`).
components:
  schemas:
    ConversationHistoryResponse:
      properties:
        data:
          description: List of messages.
          items:
            $ref: '#/components/schemas/ConversationMessageItem'
          type: array
        has_more:
          description: Whether there are more messages.
          type: boolean
        limit:
          description: Number of items per page.
          type: integer
      type: object
    ConversationMessageItem:
      properties:
        agent_thoughts:
          description: Agent thoughts for this message.
          items:
            $ref: '#/components/schemas/AgentThoughtItem'
          type: array
        answer:
          description: Assistant answer text.
          type: string
        answer_tokens:
          description: Number of tokens in the generated answer.
          type: integer
        conversation_id:
          description: Conversation ID.
          format: uuid
          type: string
        created_at:
          description: Creation timestamp (Unix epoch seconds).
          format: int64
          type: integer
        currency:
          description: >-
            Currency for `total_price` (for example, `USD`), or `null` when
            pricing is unavailable.
          nullable: true
          type: string
        error:
          description: Error message if `status` is `error`.
          nullable: true
          type: string
        extra_contents:
          description: >-
            Additional execution content associated with this message, such as
            human input form data from Human Input nodes in Chatflow workflows.
          items:
            $ref: '#/components/schemas/HumanInputContent'
          type: array
        feedback:
          description: User feedback for this message.
          nullable: true
          properties:
            rating:
              description: Feedback rating. `like` for positive, `dislike` for negative.
              type: string
          type: object
        id:
          description: Message ID.
          format: uuid
          type: string
        inputs:
          additionalProperties: true
          description: Input variables for this message.
          type: object
        message_files:
          description: Files attached to this message.
          items:
            $ref: '#/components/schemas/MessageFileItem'
          type: array
        message_tokens:
          description: Number of tokens in the input message.
          type: integer
        parent_message_id:
          description: Parent message ID for threaded conversations.
          format: uuid
          nullable: true
          type: string
        provider_response_latency:
          description: Model provider response latency in seconds.
          format: double
          type: number
        query:
          description: User query text.
          type: string
        retriever_resources:
          description: Retriever resources used for this message.
          items:
            $ref: '#/components/schemas/RetrieverResource'
          type: array
        status:
          description: >-
            Message status. `normal` for successful messages, `error` when
            generation failed.
          type: string
        total_price:
          description: >-
            Total price for the tokens used, or `null` when pricing is
            unavailable.
          format: decimal
          nullable: true
          type: string
        total_tokens:
          description: Total tokens used, the sum of `message_tokens` and `answer_tokens`.
          type: integer
      type: object
    AgentThoughtItem:
      description: An agent thought step in the message.
      properties:
        chain_id:
          description: Chain ID for this thought.
          nullable: true
          type: string
        created_at:
          description: Creation timestamp.
          format: int64
          type: integer
        files:
          description: File IDs related to this thought.
          items:
            type: string
          type: array
        id:
          description: Agent thought ID.
          format: uuid
          type: string
        message_id:
          description: Unique message ID this thought belongs to.
          format: uuid
          type: string
        observation:
          description: Response from tool calls.
          type: string
        position:
          description: Position of this thought.
          type: integer
        thought:
          description: What LLM is thinking.
          type: string
        tool:
          description: Tools called, split by `;`.
          type: string
        tool_input:
          description: Input of tools in JSON format.
          type: string
        tool_labels:
          additionalProperties: true
          description: Labels for tools used.
          nullable: true
          type: object
      type: object
    HumanInputContent:
      description: >-
        Execution content from a Human Input node, including form definition and
        submission data.
      properties:
        form_definition:
          $ref: '#/components/schemas/HumanInputFormDefinition'
          description: >-
            The form as the Human Input node sent it, whether or not it has been
            submitted.
        form_submission_data:
          $ref: '#/components/schemas/HumanInputFormSubmissionData'
          description: >-
            Submitted form data. `null` when the form has not been submitted
            yet.
          nullable: true
        submitted:
          description: Whether the human input form has been submitted.
          type: boolean
        type:
          description: '`human_input` for human input content.'
          type: string
        workflow_run_id:
          description: ID of the workflow run this content belongs to.
          type: string
      type: object
    MessageFileItem:
      description: A file attached to a message.
      properties:
        belongs_to:
          description: >-
            Who this file belongs to. `user` for user-uploaded files,
            `assistant` for assistant-generated files.
          nullable: true
          type: string
        filename:
          description: Original filename.
          type: string
        id:
          description: File ID.
          format: uuid
          type: string
        mime_type:
          description: MIME type of the file.
          nullable: true
          type: string
        size:
          description: File size in bytes.
          nullable: true
          type: integer
        transfer_method:
          description: >-
            Transfer method used. `remote_url` for URL-based files, `local_file`
            for uploaded files, `tool_file` for tool-generated files.
          type: string
        type:
          description: File type, e.g., `image`.
          type: string
        upload_file_id:
          description: Upload file ID if transferred via `local_file`.
          format: uuid
          nullable: true
          type: string
        url:
          description: Preview URL for the file.
          format: url
          nullable: true
          type: string
      type: object
    RetrieverResource:
      description: Citation and attribution information for a retriever resource.
      properties:
        content:
          description: Content snippet from the resource.
          type: string
        created_at:
          description: Creation timestamp (Unix epoch seconds).
          format: int64
          type: integer
        data_source_type:
          description: Type of the data source.
          type: string
        dataset_id:
          description: ID of the knowledge base.
          format: uuid
          type: string
        dataset_name:
          description: Name of the knowledge base.
          type: string
        doc_metadata:
          description: >-
            Metadata values of the source document, keyed by metadata field
            name. Includes the built-in fields when they are enabled for the
            knowledge base. `null` if the document has no metadata.


            For a record from an external knowledge base, it's filled in
            Chatflow, Chatbot, and Text Generator apps, with the record's
            `metadata` from the external knowledge API plus the `score`,
            `title`, `dataset_id`, and `dataset_name` that Dify adds. In Legacy
            Agent apps it's `null` for external records.
          nullable: true
          type: object
        document_id:
          description: ID of the document.
          format: uuid
          type: string
        document_name:
          description: Name of the document.
          type: string
        files:
          description: >-
            Images in the retrieved chunk that matched the query. Returned only
            by Chatflow apps, and only when the match came from an image; `null`
            otherwise, including when the chunk matched on its text.
          items:
            properties:
              extension:
                description: >-
                  File extension, including the leading dot (for example,
                  `.png`).
                type: string
              id:
                description: ID of the uploaded image file.
                format: uuid
                type: string
              mime_type:
                description: MIME type of the file.
                type: string
              name:
                description: File name.
                type: string
              size:
                description: File size in bytes.
                type: integer
              source_url:
                description: >-
                  Signed preview URL for the image, valid for the time set by
                  the `FILES_ACCESS_TIMEOUT` [environment
                  variable](/en/self-host/deploy/configuration/environments#files_access_timeout)
                  (300 seconds by default).
                type: string
            type: object
          nullable: true
          type: array
        hit_count:
          description: Number of times this chunk was hit.
          type: integer
        id:
          description: Unique ID of the retriever resource.
          format: uuid
          type: string
        index_node_hash:
          description: Hash of the index node.
          type: string
        message_id:
          description: ID of the message this resource belongs to.
          format: uuid
          type: string
        position:
          description: Position of the resource in the list.
          type: integer
        score:
          description: Similarity score of the resource.
          format: float
          type: number
        segment_id:
          description: ID of the specific chunk within the document.
          format: uuid
          type: string
        segment_position:
          description: Position of the chunk within the document.
          type: integer
        summary:
          description: Summary of the chunk content.
          nullable: true
          type: string
        title:
          description: >-
            Title of the external knowledge base record, the same value as
            `document_name`. Returned only for external knowledge base records
            retrieved by Legacy Agent apps; otherwise `null`.
          nullable: true
          type: string
        word_count:
          description: Word count of the chunk.
          type: integer
      type: object
    HumanInputFormDefinition:
      description: Definition of a human input form rendered by a Human Input node.
      properties:
        actions:
          description: Action buttons available on the form.
          items:
            $ref: '#/components/schemas/UserAction'
          type: array
        display_in_ui:
          description: >-
            Whether your end user can answer the form. On a form from the old
            Human Input node, it stays `true` after the form is submitted; check
            `form_token` to tell whether the form still takes an answer.
          type: boolean
        expiration_time:
          description: Unix timestamp when the form expires.
          type: integer
        form_content:
          description: >-
            The form's body in Markdown, with the run's variables already filled
            in. Place each input where its placeholder,
            `{{#$output.<output_variable_name>#}}`, appears.


            The placeholders remain after the form is submitted. To show the
            body with the answers filled in, use
            `form_submission_data.rendered_content`.
          type: string
        form_id:
          description: Unique form identifier.
          type: string
        form_token:
          description: >-
            Access token for [Get Human Input
            Form](/en/api-reference/human-input/get-human-input-form) and
            [Submit Human Input
            Form](/en/api-reference/human-input/submit-human-input-form). `null`
            once the form is no longer waiting for a response, and when the
            Human Input node doesn't send it to your end user.
          nullable: true
          type: string
        form_version:
          description: >-
            Which Human Input node made the form: `"1"` for the old Human Input
            node, `"2"` for the new one.
          type: string
        inputs:
          description: The fields the recipient fills in.
          items:
            $ref: '#/components/schemas/FormInput'
          type: array
        node_id:
          description: ID of the Human Input node that generated this form.
          type: string
        node_title:
          description: Title of the Human Input node.
          type: string
        resolved_default_values:
          additionalProperties: true
          description: >-
            This run's values for `paragraph` defaults, keyed by
            `output_variable_name`. Pre-fill a field from here when its
            `default.type` is `variable`. If its key is missing, leave the field
            empty.


            On forms from the old Human Input node, each value keeps the
            variable's JSON type, such as a number or an object: convert it to
            text before you pre-fill the field. The new node sends strings.
          type: object
      type: object
    HumanInputFormSubmissionData:
      description: Data from a submitted human input form.
      properties:
        action_id:
          description: ID of the action button that was clicked.
          type: string
        action_text:
          description: Display text of the action button that was clicked.
          type: string
        node_id:
          description: ID of the Human Input node.
          type: string
        node_title:
          description: Title of the Human Input node.
          type: string
        rendered_content:
          description: The form's body with the submitted answers filled in.
          type: string
        submitted_data:
          additionalProperties: true
          description: >-
            The submitted values, keyed by each input's `output_variable_name`.
            `{}` when the form had no inputs.
          type: object
      type: object
    UserAction:
      description: An action button on a human input form.
      properties:
        button_style:
          description: '`primary`, `default`, `accent`, or `ghost`.'
          type: string
        id:
          description: Unique action identifier.
          type: string
        title:
          description: Button display text.
          type: string
      type: object
    FormInput:
      description: A form input field definition.
      properties:
        allowed_file_extensions:
          description: >-
            File extensions allowed when `allowed_file_types` includes `custom`,
            as the builder entered them, such as `.md`. Dify ignores case and
            the leading `.` when it checks a file against them. Present for
            `file` and `file-list` inputs.
          items:
            type: string
          type: array
        allowed_file_types:
          description: >-
            File categories the recipient may upload. Present for `file` and
            `file-list` inputs. Values: `image`, `document`, `audio`, `video`,
            `custom`.
          items:
            type: string
          type: array
        allowed_file_upload_methods:
          description: >-
            Upload methods the recipient may use. Values: `local_file`,
            `remote_url`. Present for `file` and `file-list` inputs.
          items:
            type: string
          type: array
        default:
          $ref: '#/components/schemas/FormInputDefault'
          description: >-
            A `paragraph` input's default; absent from other input types.


            To pre-fill the field, use `value` when `type` is `constant`, and
            `resolved_default_values[output_variable_name]` when `type` is
            `variable`. Leave the field empty when `default` is `null`.
          nullable: true
        number_limits:
          description: >-
            Maximum number of files the recipient may upload. Present only for
            `file-list` inputs.
          type: integer
        option_source:
          description: >-
            A `select` input's options, listed in `value`. Absent from other
            input types.
          properties:
            selector:
              description: >-
                Can hold a variable's path on forms from the old Human Input
                node. To list the options, use `value` instead.
              items:
                type: string
              type: array
            type:
              description: >-
                `constant` once Dify has resolved the options. On a form from
                the old Human Input node, it stays `variable` when the options'
                variable is missing from the run, and `value` then holds the
                options as the builder configured them.


                You don't need to branch on this field: either way, offer the
                options in `value`.
              type: string
            value:
              description: >-
                The options the recipient can choose from, already resolved when
                the builder took them from a variable.
              items:
                type: string
              type: array
          type: object
        output_variable_name:
          description: >-
            Variable name used to reference this input's submitted value inside
            the workflow. Corresponds to the key in the submission `inputs`
            object.
          type: string
        type:
          description: >-
            Form input control type. Available values: `paragraph` (multi-line
            text input), `select` (single-choice from a list), `file` (single
            file upload), and `file-list` (multiple file uploads).
          type: string
      type: object
    FormInputDefault:
      description: Default value configuration for a form input.
      properties:
        selector:
          description: >-
            The variable's path when `type` is `variable`. You don't need it to
            pre-fill the field.
          items:
            type: string
          type: array
        type:
          description: >-
            `constant` when the text to pre-fill is in `value`, or `variable`
            when it's in `resolved_default_values`.
          type: string
        value:
          description: >-
            The text to pre-fill when `type` is `constant`. When `type` is
            `variable`, ignore it: it isn't the run's value and is often `""`.
          type: string
      type: object
  securitySchemes:
    ApiKeyAuth:
      bearerFormat: API_KEY
      description: >-
        Every request authenticates with an API key: `Authorization: Bearer
        {API_KEY}`. App endpoints take an app API key; knowledge endpoints take
        a knowledge base API key ([Get
        Started](/en/api-reference/guides/get-started)).


        Keep keys server-side; never embed them in client code. Requests with a
        missing or invalid key fail with HTTP `401` (`unauthorized`).
      scheme: bearer
      type: http

````

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