Skip to main content
post/chat-messages
Request example
Response
post/chat-messages

Authorization

Authorizationstringheaderrequired#

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

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

Body

application/json
auto_generate_nameboolean#
Auto-generate conversation title. If false, use the Rename Conversation API with auto_generate: true for async title generation.

Default: true

conversation_idstring#
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.
filesobject[]#
Files to attach to the message. For a local file, first upload it via 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.
inputsobjectrequired#
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.
querystringrequired#
The user's message.
response_modeenum<string>#

Mode of response return. 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.
Options:streamingblocking
userstringrequired#
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.
workflow_idstring#
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.

Responses

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.
answerstring#
Complete response content.
conversation_idstring#
Conversation ID.
created_atinteger#
Message creation timestamp (Unix epoch seconds).
eventstring#
Event type, fixed as message.
idstring#
Unique ID of this response event.
message_idstring#
Unique message ID. Use this as the message_id parameter when calling feedback or suggested questions endpoints.
metadataobject#
Metadata including usage and retriever resources.
modestring#
App mode. chat for Chatbot apps, agent-chat for Legacy Agent apps, advanced-chat for Chatflow apps.
task_idstring#
Task ID for request tracking and stop response API.