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

# Send Chat Message

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

Sends a message to a chat app and returns the assistant's reply. The events in the streaming response vary by app type.



## OpenAPI

````yaml /en/api-reference/openapi_service.json post /chat-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:
  /chat-messages:
    post:
      tags:
        - Chat Messages
      summary: Send Chat Message
      description: >-
        **Available for**: Chatflow, Agent, Chatbot, Legacy Agent apps.


        Sends a message to a chat app and returns the assistant's reply. The
        events in the streaming response vary by app type.
      operationId: sendChatMessage
      requestBody:
        content:
          application/json:
            examples:
              blocking_example:
                summary: Request Example - Blocking mode
                value:
                  conversation_id: 45701982-8118-4bc5-8e9b-64562b4555f2
                  inputs: {}
                  query: What are the specs of the iPhone 13 Pro Max?
                  response_mode: blocking
                  user: abc-123
              streaming_example:
                summary: Request Example - Streaming mode
                value:
                  conversation_id: ''
                  files:
                    - transfer_method: remote_url
                      type: image
                      url: https://cloud.dify.ai/logo/logo-site.png
                  inputs:
                    city: San Francisco
                  query: What are the specs of the iPhone 13 Pro Max?
                  response_mode: streaming
                  user: abc-123
            schema:
              $ref: '#/components/schemas/ChatRequest'
        description: Request body to send a chat message.
        required: true
      responses:
        '200':
          content:
            application/json:
              examples:
                blockingResponse:
                  summary: Response Example - Blocking mode
                  value:
                    answer: iPhone 13 Pro Max specs are listed here:...
                    conversation_id: 45701982-8118-4bc5-8e9b-64562b4555f2
                    created_at: 1705407629
                    event: message
                    id: b01a39de-3480-4f3e-9f1e-4841a80f8e5e
                    message_id: 9da23599-e713-473b-982c-4328d4f5c78a
                    metadata:
                      retriever_resources:
                        - content: >-
                            "Model","Release Date","Display
                            Size","Resolution","Processor","RAM","Storage","Camera","Battery","Operating
                            System" "iPhone 13 Pro Max","September 24,
                            2021","6.7 inch","1284 x 2778","Hexa-core (2x3.23
                            GHz Avalanche + 4x1.82 GHz Blizzard)","6 GB","128,
                            256, 512 GB, 1TB","12 MP","4352 mAh","iOS 15"
                          dataset_id: 101b4c97-fc2e-463c-90b1-5261a4cdcafb
                          dataset_name: iPhone
                          doc_metadata:
                            category: Smartphones
                            release_year: 2021
                          document_id: 8dd1ad74-0b5f-4175-b735-7d98bbbb4e00
                          document_name: iPhone List
                          position: 1
                          score: 0.98457545
                          segment_id: ed599c7f-2766-4294-9d1d-e5235a61270a
                      usage:
                        completion_price: '0.0002560'
                        completion_price_unit: '0.001'
                        completion_tokens: 128
                        completion_unit_price: '0.002'
                        currency: USD
                        latency: 0.7682376249867957
                        prompt_price: '0.0010330'
                        prompt_price_unit: '0.001'
                        prompt_tokens: 1033
                        prompt_unit_price: '0.001'
                        total_price: '0.0012890'
                        total_tokens: 1161
                    mode: chat
                    task_id: c3800678-a077-43df-a102-53f23ed20b88
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              examples:
                humanInputPause:
                  summary: Response Example - Human Input pause
                  value: >-
                    event: ping


                    data: {"event": "workflow_started", "task_id":
                    "c3800678-a077-43df-a102-53f23ed20b88", "message_id":
                    "2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b", "conversation_id":
                    "9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7", "created_at":
                    1705407629, "workflow_run_id":
                    "fb47b2e6-5e43-4f90-be01-d5c5a088d156", "data": {"id":
                    "fb47b2e6-5e43-4f90-be01-d5c5a088d156", "workflow_id":
                    "7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345", "inputs": {"draft":
                    "Hello"}, "created_at": 1705407629, "reason": "initial"}}


                    data: {"event": "human_input_required", "conversation_id":
                    "9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7", "message_id":
                    "2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b", "created_at":
                    1705407629, "task_id":
                    "c3800678-a077-43df-a102-53f23ed20b88", "workflow_run_id":
                    "fb47b2e6-5e43-4f90-be01-d5c5a088d156", "data":
                    {"form_version": "2", "form_id":
                    "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "node_id":
                    "approval_node", "node_title": "Approval", "form_content":
                    "Please review the draft.\n\n{{#$output.comment#}}",
                    "inputs": [{"output_variable_name": "comment", "type":
                    "paragraph", "default": {"type": "constant", "selector": [],
                    "value": ""}}], "actions": [{"id": "approve", "title":
                    "Approve", "button_style": "primary"}], "display_in_ui":
                    true, "form_token":
                    "pX3v9QeL2mZr8TnB4yWc6Hk1sD5fJ7gA0uRtYbNq2Ve",
                    "approval_channels": [], "resolved_default_values": {},
                    "expiration_time": 1705494029}}


                    data: {"event": "workflow_paused", "conversation_id":
                    "9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7", "message_id":
                    "2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b", "created_at":
                    1705407629, "task_id":
                    "c3800678-a077-43df-a102-53f23ed20b88", "workflow_run_id":
                    "fb47b2e6-5e43-4f90-be01-d5c5a088d156", "data":
                    {"workflow_run_id": "fb47b2e6-5e43-4f90-be01-d5c5a088d156",
                    "paused_nodes": ["approval_node"], "outputs": {}, "reasons":
                    [{"form_version": "2", "TYPE": "human_input_required",
                    "form_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
                    "form_content": "Please review the
                    draft.\n\n{{#$output.comment#}}", "inputs":
                    [{"output_variable_name": "comment", "type": "paragraph",
                    "default": {"type": "constant", "selector": [], "value":
                    ""}}], "actions": [{"id": "approve", "title": "Approve",
                    "button_style": "primary"}], "node_id": "approval_node",
                    "node_title": "Approval", "resolved_default_values": {},
                    "display_in_ui": true, "form_token":
                    "pX3v9QeL2mZr8TnB4yWc6Hk1sD5fJ7gA0uRtYbNq2Ve",
                    "approval_channels": [], "expiration_time": 1705494029}],
                    "status": "paused", "created_at": 1705407629,
                    "elapsed_time": 0.5, "total_tokens": 0, "total_steps": 2}}
                streamingResponseAgent:
                  summary: Response Example - Streaming (Legacy Agent)
                  value: >-
                    data: {"event": "agent_thought", "id": "agent_thought_id_1",
                    "task_id": "task123", "message_id": "msg123",
                    "conversation_id": "conv123", "position": 1, "thought":
                    "Thinking about calling a tool...", "tool": "dalle3",
                    "tool_input": "{\"dalle3\": {\"prompt\": \"a cute cat\"}}",
                    "created_at": 1705395332}


                    data: {"event": "message_file", "task_id": "task123",
                    "message_id": "msg123", "conversation_id": "conv123", "id":
                    "file_id_1", "type": "image", "belongs_to": "assistant",
                    "url": "https://example.com/cat.png", "created_at":
                    1705395332}


                    data: {"event": "agent_message", "task_id": "task123",
                    "message_id": "msg123", "conversation_id": "conv123",
                    "answer": "Here is the image: ", "created_at": 1705395333}


                    data: {"event": "message_end", "task_id":"task123",
                    "message_id": "msg123", "conversation_id": "conv123",
                    "metadata": {"usage": {"total_tokens": 50, "latency": 2.5}}}
                streamingResponseBasic:
                  summary: Response Example - Streaming (Basic)
                  value: >-
                    data: {"event": "message", "task_id": "mock_task_id",
                    "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
                    "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
                    "answer": " I", "created_at": 1679586595}


                    data: {"event": "message_end", "task_id": "mock_task_id",
                    "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
                    "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
                    "created_at": 1679586595, "metadata": {"usage":
                    {"total_tokens": 10, "latency": 1.0}}}
                streamingResponseWorkflow:
                  summary: Response Example - Streaming (Workflow)
                  value: >-
                    event: ping


                    data: {"event": "workflow_started", "task_id": "task123",
                    "workflow_run_id": "wfr_abc123", "message_id": "msg123",
                    "conversation_id": "conv123", "created_at": 1705395332,
                    "data": {"id": "wfr_abc123", "workflow_id": "wf_def456",
                    "inputs": {"city": "San Francisco"}, "created_at":
                    1705395332}}


                    data: {"event": "node_started", "task_id": "task123",
                    "workflow_run_id": "wfr_abc123", "message_id": "msg123",
                    "conversation_id": "conv123", "created_at": 1705395332,
                    "data": {"id": "ne_001", "node_id": "node_llm_1",
                    "node_type": "llm", "title": "LLM", "index": 1,
                    "created_at": 1705395332}}


                    data: {"event": "reasoning_chunk", "task_id": "task123",
                    "message_id": "msg123", "conversation_id": "conv123",
                    "created_at": 1705395333, "data": {"message_id": "msg123",
                    "reasoning": "The user greeted me, so", "node_id":
                    "node_llm_1", "is_final": false}}


                    data: {"event": "reasoning_chunk", "task_id": "task123",
                    "message_id": "msg123", "conversation_id": "conv123",
                    "created_at": 1705395333, "data": {"message_id": "msg123",
                    "reasoning": "", "node_id": "node_llm_1", "is_final": true}}


                    data: {"event": "message", "task_id": "task123",
                    "message_id": "msg123", "conversation_id": "conv123",
                    "answer": " I", "created_at": 1705395333}


                    data: {"event": "node_finished", "task_id": "task123",
                    "workflow_run_id": "wfr_abc123", "message_id": "msg123",
                    "conversation_id": "conv123", "created_at": 1705395334,
                    "data": {"id": "ne_001", "node_id": "node_llm_1",
                    "node_type": "llm", "title": "LLM", "index": 1, "status":
                    "succeeded", "elapsed_time": 1.5, "created_at": 1705395332,
                    "finished_at": 1705395334}}


                    data: {"event": "message_end", "task_id": "task123",
                    "message_id": "msg123", "conversation_id": "conv123",
                    "created_at": 1705395334, "metadata": {"usage":
                    {"total_tokens": 50, "latency": 2.5}}}


                    data: {"event": "workflow_finished", "task_id": "task123",
                    "workflow_run_id": "wfr_abc123", "message_id": "msg123",
                    "conversation_id": "conv123", "created_at": 1705395335,
                    "data": {"id": "wfr_abc123", "workflow_id": "wf_def456",
                    "status": "succeeded", "elapsed_time": 2.5, "total_tokens":
                    50, "total_steps": 2, "created_at": 1705395332,
                    "finished_at": 1705395335}}
              schema:
                description: >-
                  A stream of Server-Sent Events. Parse it per the [SSE
                  Streaming guide](/en/api-reference/guides/streaming): read
                  `data:` lines, dispatch on the `event` field, skip `ping`
                  (keep-alive; a Chatflow stream opens with one, then more
                  arrive roughly every 10 seconds).


                  **Events by app type** (the reply events, then how the stream
                  closes):


                  - **Chatbot**: `message` chunks (concatenate in order) →
                  `message_end`.

                  - **Legacy Agent**: `agent_thought` reasoning and tool-call
                  steps alongside `agent_message` chunks → `message_end`.

                  - **Agent**: `agent_message` chunks with `agent_thought` steps
                  alongside → one closing `message` carrying the complete answer
                  (treat it as the final answer, not extra text to append) →
                  `message_end`. Its `message_end` metadata carries `usage`
                  (plus `annotation_reply` on an annotation match) and never
                  `retriever_resources`.

                  - **Chatflow**: `workflow_started` → node events
                  (`node_started`, `node_finished`, plus iteration and loop
                  variants) alongside `message` chunks → then, by outcome:
                    - **Success**: `message_end`, then `workflow_finished`
                    - **Failure**: `workflow_finished` with status `failed`, then `error`; no `message_end`
                    - **Pause**: `human_input_required`, then `workflow_paused` (the stream ends here; the run resumes separately)
                  - **Direct reply** (an annotation match, or input moderation
                  with a preset reply): Chatbot and Legacy Agent apps send
                  `message` chunks → `message_end`. A Chatflow app runs no
                  workflow, so one `message` carries the whole reply →
                  `message_end`, with no workflow or node events and no
                  `workflow_run_id`.


                  **Add-ons**:


                  - Text-to-speech auto-play: `tts_message` audio chunks
                  interleave, and `tts_message_end` trails the closing event.

                  - Chatflow LLM nodes with `reasoning_format: separated` also
                  emit `reasoning_chunk` deltas carrying the model's reasoning.


                  **Common fields**: apart from `ping`, every event includes
                  `conversation_id`, `message_id`, and `created_at` (Unix epoch
                  seconds); all but `error` also include `task_id`. Workflow,
                  node, and human-input events (Chatflow apps) nest their
                  payload under `data` and, except for `agent_log`, carry a
                  top-level `workflow_run_id`.


                  **Reply events**


                  | Event | App | Fires on | Key fields |

                  |:---|:---|:---|:---|

                  | `message` | Chatbot, Chatflow, Agent; Legacy Agent for
                  direct replies | each answer chunk (concatenate in order); for
                  Agent, one closing chunk with the complete answer | `answer` |

                  | `agent_message` | Legacy Agent, Agent | each answer chunk
                  (concatenate in order) | `answer` |

                  | `agent_thought` | Legacy Agent, Agent | each reasoning or
                  tool-call step | `position`, `thought`, `tool`, `tool_input`
                  (JSON), `observation`, `message_files` |

                  | `message_replace` | All | output moderation replaces the
                  answer so far | `answer`; Chatflow also `reason` |

                  | `reasoning_chunk` | Chatflow | each reasoning-content delta,
                  when an LLM node uses `reasoning_format: separated`
                  (concatenate in order; a final `is_final: true` event marks
                  reasoning finished and may carry an empty `reasoning`) |
                  `data.message_id`, `data.reasoning`, `data.node_id`,
                  `data.is_final` |

                  | `message_file` | Chatbot, Legacy Agent | the assistant
                  returns a file | `type`, `belongs_to`, `url` |

                  | `message_end` | All | the answer is complete | `metadata`
                  (`usage`, `retriever_resources`) |

                  | `tts_message`, `tts_message_end` | Chatbot, Legacy Agent,
                  Chatflow | audio chunk / end, when TTS auto-play is on |
                  `audio` |


                  **Workflow and node events** (Chatflow apps only)


                  Each event nests its payload under a `data` object.


                  | Event | Fires on | Key `data` fields |

                  |:---|:---|:---|

                  | `workflow_started` | the run begins | `inputs` |

                  | `node_started` | a node begins | `node_id`, `node_type`,
                  `title` |

                  | `node_finished` | a node ends | `status`, `outputs`,
                  `execution_metadata` |

                  | `node_retry` | a node retries after a failure |
                  `retry_index` |

                  | `iteration_started`, `iteration_next`, `iteration_completed`
                  | Iteration node progress (informational) | `data` |

                  | `loop_started`, `loop_next`, `loop_completed` | Loop node
                  progress (informational) | `data` |

                  | `agent_log` | an Agent node step log (informational; no
                  `workflow_run_id`) | `data` |

                  | `workflow_finished` | the run ends | `status` (`succeeded`,
                  `failed`, `partial-succeeded`, `stopped`), `outputs`,
                  `total_tokens` |

                  | `workflow_paused` | the run pauses | `paused_nodes`,
                  `reasons` |

                  | `human_input_required` | the run reaches a Human Input node
                  | `form_token`, `form_content`, `expiration_time` |


                  After a pause this stream ends at `workflow_paused`. Submit
                  the form via [Submit Human Input
                  Form](/en/api-reference/human-input/submit-human-input-form)
                  or let it time out; the resumed run, including
                  `human_input_form_filled`/`human_input_form_timeout` through
                  `workflow_finished`, streams from [Stream Workflow
                  Events](/en/api-reference/workflow-runs/stream-workflow-events).


                  **Transport events**


                  | Event | Fires on | Key fields |

                  |:---|:---|:---|

                  | `error` | a failure ends the stream; HTTP stays `200` |
                  `status` (e.g. `400`), `code` (e.g. `invalid_param`),
                  `message` |

                  | `ping` | keep-alive; opens every Chatflow stream, then
                  roughly every 10 seconds | none |
                type: string
          description: >-
            Successful response. The content type and structure depend on the
            `response_mode` parameter in the request.


            - If `response_mode` is `blocking`, returns `application/json` with
            a `ChatCompletionResponse` object.

            - If `response_mode` is `streaming`, returns `text/event-stream`
            with a stream of Server-Sent Events.
        '400':
          content:
            application/json:
              examples:
                app_unavailable:
                  summary: app_unavailable
                  value:
                    code: app_unavailable
                    message: App unavailable, please check your app configurations.
                    status: 400
                completion_request_error:
                  summary: completion_request_error
                  value:
                    code: completion_request_error
                    message: Completion request failed.
                    status: 400
                conversation_completed:
                  summary: conversation_completed
                  value:
                    code: conversation_completed
                    message: >-
                      The conversation has ended. Please start a new
                      conversation.
                    status: 400
                is_draft_workflow:
                  summary: bad_request
                  value:
                    code: bad_request
                    message: >-
                      Cannot use draft workflow version. Workflow ID:
                      a1b2c3d4-5678-90ab-cdef-1234567890ab. 
                    status: 400
                model_currently_not_support:
                  summary: model_currently_not_support
                  value:
                    code: model_currently_not_support
                    message: >-
                      Dify Hosted OpenAI trial currently not support the GPT-4
                      model.
                    status: 400
                new_agent_not_bound:
                  summary: invalid_param
                  value:
                    code: invalid_param
                    message: Agent App has no bound Agent
                    status: 400
                new_agent_not_published:
                  summary: agent_not_published
                  value:
                    code: agent_not_published
                    message: >-
                      Agent has not been published. Please publish the Agent
                      before using the API.
                    status: 400
                new_agent_streaming_only:
                  summary: bad_request
                  value:
                    code: bad_request
                    message: Agent App only supports streaming response mode.
                    status: 400
                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
                provider_not_initialize:
                  summary: provider_not_initialize
                  value:
                    code: provider_not_initialize
                    message: >-
                      No valid model provider credentials found. Please go to
                      Settings -> Model Provider to complete your provider
                      credentials.
                    status: 400
                provider_quota_exceeded:
                  summary: provider_quota_exceeded
                  value:
                    code: provider_quota_exceeded
                    message: >-
                      Your quota for Dify Hosted OpenAI has been exhausted.
                      Please go to Settings -> Model Provider to complete your
                      own provider credentials.
                    status: 400
                workflow_id_format_error:
                  summary: bad_request
                  value:
                    code: bad_request
                    message: 'Invalid workflow_id format: ''not-a-valid-id''. '
                    status: 400
          description: >-
            - `app_unavailable` : App unavailable or misconfigured.

            - `not_chat_app` : App mode does not match the API route.

            - `provider_not_initialize` : No valid model provider credentials
            found.

            - `provider_quota_exceeded` : Model provider quota exhausted.

            - `model_currently_not_support` : Current model unavailable.

            - `completion_request_error` : Text generation failed.

            - `bad_request` : Cannot use draft workflow version.

            - `bad_request` : Invalid `workflow_id` format.

            - `bad_request` : `blocking` response mode with an Agent app.

            - `invalid_param` : The Agent app has no bound Agent.

            - `agent_not_published` : The bound Agent has no published version.
            (Agent apps)

            - `conversation_completed` : The conversation has ended; start a new
            one by omitting `conversation_id`.
        '403':
          content:
            application/json:
              examples:
                workflow_version_execution_not_allowed:
                  summary: workflow_version_execution_not_allowed
                  value:
                    code: workflow_version_execution_not_allowed
                    message: >-
                      Workflow version execution is not available on your
                      current plan. Please upgrade to a paid plan.
                    status: 403
          description: >-
            `workflow_version_execution_not_allowed` : A Chatflow request pinned
            a workflow version via `workflow_id` on the Dify Cloud Sandbox plan.
        '404':
          content:
            application/json:
              examples:
                conversation_not_exists:
                  summary: not_found
                  value:
                    code: not_found
                    message: Conversation Not Exists.
                    status: 404
                workflow_not_found:
                  summary: not_found
                  value:
                    code: not_found
                    message: >-
                      Workflow not found with id:
                      a1b2c3d4-5678-90ab-cdef-1234567890ab
                    status: 404
          description: |-
            - `not_found` : Conversation does not exist.
            - `not_found` : Workflow not found with the specified `workflow_id`.
        '429':
          content:
            application/json:
              examples:
                rate_limit_error:
                  summary: rate_limit_error
                  value:
                    code: rate_limit_error
                    message: >-
                      Workflow execution quota limit reached for tenant
                      8f1e2a90-3b7c-4d55-9a01-6c2f4e8b1d33
                    status: 429
                too_many_requests:
                  summary: too_many_requests
                  value:
                    code: too_many_requests
                    message: Too many requests. Please try again later.
                    status: 429
          description: >-
            - `too_many_requests` : Too many concurrent requests for this app.

            - `rate_limit_error` : The Dify Cloud workflow execution quota for
            this workspace has been reached.
        '500':
          content:
            application/json:
              examples:
                internal_server_error:
                  summary: internal_server_error
                  value:
                    code: internal_server_error
                    message: >-
                      The server encountered an internal error and was unable to
                      complete your request. Either the server is overloaded or
                      there is an error in the application.
                    status: 500
          description: '`internal_server_error` : Internal server error.'
        '503':
          content:
            application/json:
              examples:
                moderation_unavailable:
                  summary: moderation_unavailable
                  value:
                    code: moderation_unavailable
                    message: >-
                      This message can’t be processed right now. Please try
                      again later.
                    status: 503
          description: >-
            - `moderation_unavailable` : The app's content moderation, set to
            Keywords or Custom Endpoint, couldn't complete its check on the
            input or output, for example because the endpoint couldn't be
            reached or returned an invalid response.

            - `moderation_unavailable` : On Dify Cloud, Dify's own moderation
            couldn't complete its check on the input or output of a model
            running on AI credits. (Chatbot and Legacy Agent apps)

            - `moderation_unavailable` : The app's content moderation is set to
            OpenAI Moderation, and the workspace has no working OpenAI API key
            in Model Provider. On Dify Cloud, this happens only in Chatbot and
            Legacy Agent apps whose model uses the workspace's own API key.
components:
  schemas:
    ChatRequest:
      properties:
        auto_generate_name:
          default: true
          description: >-
            Auto-generate conversation title. If `false`, use the [Rename
            Conversation](/en/api-reference/conversations/rename-conversation)
            API with `auto_generate: true` for async title generation.
          type: boolean
        conversation_id:
          description: >-
            ID of the conversation to continue. Omit it or pass an empty string
            to start a new conversation; the response returns a
            `conversation_id` to send with the next message. To resume an
            earlier conversation, get its ID from [List
            Conversations](/en/api-reference/conversations/list-conversations).
          type: string
        files:
          description: >-
            Files to attach to the message. For a local file, first upload it
            via [Upload File](/en/api-reference/files/upload-file), then
            reference the returned `id` as `upload_file_id` with
            `transfer_method: local_file`. Agent apps accept file references but
            do not process their contents.
          items:
            properties:
              transfer_method:
                description: >-
                  Transfer method: `remote_url` for file URL, `local_file` for
                  uploaded file.
                enum:
                  - remote_url
                  - local_file
                type: string
              type:
                description: File type.
                enum:
                  - image
                  - document
                  - audio
                  - video
                  - custom
                type: string
              upload_file_id:
                description: >-
                  Uploaded file ID obtained from the [Upload
                  File](/en/api-reference/files/upload-file) API (required when
                  `transfer_method` is `local_file`).
                type: string
              url:
                description: File URL (required when `transfer_method` is `remote_url`).
                format: url
                type: string
            required:
              - type
              - transfer_method
            type: object
          type: array
        inputs:
          additionalProperties: true
          description: >-
            Values for the app's input variables, keyed by variable name. The
            expected names and types come from the `user_input_form` field of
            [Get App
            Parameters](/en/api-reference/applications/get-app-parameters).


            When a file or file-list input is omitted or `null`, the app uses
            the default configured for that input.
          type: object
        query:
          description: The user's message.
          type: string
        response_mode:
          description: >-
            Response mode. Defaults to `blocking` when omitted.


            - `streaming` (recommended): the reply arrives as Server-Sent
            Events.

            - `blocking`: returns once generation completes. Long generations
            risk interruption: on Dify Cloud, the edge proxy may end the
            connection if the response doesn't arrive within its timeout.

            - Legacy Agent and Agent apps support `streaming` only; a `blocking`
            request fails with 400.
          enum:
            - streaming
            - blocking
          type: string
        user:
          description: >-
            End-user identifier, defined by your app and unique within it.
            Conversations, messages, and files are visible only to requests
            carrying the same `user`. See [End User
            Identity](/en/api-reference/guides/end-user-identity).
          type: string
        workflow_id:
          description: >-
            Chatflow apps only. Specify a published workflow version ID to
            execute. If not provided, the latest published version is used. On
            Dify Cloud, pinning a version requires a paid plan.
          type: string
      required:
        - inputs
        - query
        - user
      type: object
    ChatCompletionResponse:
      properties:
        answer:
          description: Complete response content.
          type: string
        conversation_id:
          description: Conversation ID.
          format: uuid
          type: string
        created_at:
          description: Message creation timestamp (Unix epoch seconds).
          format: int64
          type: integer
        event:
          description: Event type, fixed as `message`.
          type: string
        id:
          description: Unique ID of this response event.
          format: uuid
          type: string
        message_id:
          description: >-
            Unique message ID. Use this as the `message_id` parameter when
            calling feedback or suggested questions endpoints.
          format: uuid
          type: string
        metadata:
          description: Metadata including usage and retriever resources.
          properties:
            retriever_resources:
              description: List of retriever resources used.
              items:
                $ref: '#/components/schemas/RetrieverResource'
              type: array
            usage:
              $ref: '#/components/schemas/Usage'
          type: object
        mode:
          description: >-
            App mode. `chat` for Chatbot apps, `agent-chat` for Legacy Agent
            apps, `advanced-chat` for Chatflow apps.
          type: string
        task_id:
          description: Task ID for request tracking and stop response API.
          format: uuid
          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
    Usage:
      description: Model usage information.
      properties:
        completion_price:
          description: Total price for completion tokens.
          format: decimal
          type: string
        completion_price_unit:
          description: Price unit for completion tokens.
          format: decimal
          type: string
        completion_tokens:
          description: Number of tokens in the completion.
          type: integer
        completion_unit_price:
          description: Unit price per completion token.
          format: decimal
          type: string
        currency:
          description: Currency for pricing.
          type: string
        latency:
          description: Latency in seconds.
          format: double
          type: number
        prompt_price:
          description: Total price for prompt tokens.
          format: decimal
          type: string
        prompt_price_unit:
          description: Price unit for prompt tokens.
          format: decimal
          type: string
        prompt_tokens:
          description: Number of tokens in the prompt.
          type: integer
        prompt_unit_price:
          description: Unit price per prompt token.
          format: decimal
          type: string
        total_price:
          description: Total price for all tokens.
          format: decimal
          type: string
        total_tokens:
          description: Total number of tokens used.
          type: integer
      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.