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.
curl --request POST \
--url https://{api_base_url}/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"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"
}
'{
"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"
}Authorizations
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
Request body to send a chat message.
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.
When a file or file-list input is omitted or null, the app uses the default configured for that input.
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.
Auto-generate conversation title. If false, use the Rename Conversation API with auto_generate: true for async title generation.
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.
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.
Show child attributes
Show child attributes
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
streamingonly; ablockingrequest fails with 400.
streaming, blocking Response
Successful response. The content type and structure depend on the response_mode parameter in the request.
- If
response_modeisblocking, returnsapplication/jsonwith aChatCompletionResponseobject. - If
response_modeisstreaming, returnstext/event-streamwith a stream of Server-Sent Events.
Was this page helpful?
curl --request POST \
--url https://{api_base_url}/chat-messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"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"
}
'{
"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"
}