template_chat.en.mdx 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # Chat App API
  4. Chat applications support session persistence, allowing previous chat history to be used as context for responses. This can be applicable for chatbot, customer service AI, etc.
  5. <div>
  6. ### Base URL
  7. <CodeGroup title="Code" targetCode={props.appDetail.api_base_url}>
  8. ```javascript
  9. ```
  10. </CodeGroup>
  11. ### Authentication
  12. The Service API uses `API-Key` authentication.
  13. <i>**Strongly recommend storing your API Key on the server-side, not shared or stored on the client-side, to avoid possible API-Key leakage that can lead to serious consequences.**</i>
  14. For all API requests, include your API Key in the `Authorization`HTTP Header, as shown below:
  15. <CodeGroup title="Code">
  16. ```javascript
  17. Authorization: Bearer {API_KEY}
  18. ```
  19. </CodeGroup>
  20. </div>
  21. ---
  22. <Heading
  23. url='/chat-messages'
  24. method='POST'
  25. title='Send Chat Message'
  26. name='#Send-Chat-Message'
  27. />
  28. <Row>
  29. <Col>
  30. Send a request to the chat application.
  31. ### Request Body
  32. <Properties>
  33. <Property name='query' type='string' key='query'>
  34. User Input/Question content
  35. </Property>
  36. <Property name='inputs' type='object' key='inputs'>
  37. Allows the entry of various variable values defined by the App.
  38. The `inputs` parameter contains multiple key/value pairs, with each key corresponding to a specific variable and each value being the specific value for that variable. Default `{}`
  39. </Property>
  40. <Property name='response_mode' type='string' key='response_mode'>
  41. The mode of response return, supporting:
  42. - `streaming` Streaming mode (recommended), implements a typewriter-like output through SSE ([Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)).
  43. - `blocking` Blocking mode, returns result after execution is complete. (Requests may be interrupted if the process is long)
  44. Due to Cloudflare restrictions, the request will be interrupted without a return after 100 seconds.
  45. <i>Note: blocking mode is not supported in Agent Assistant mode</i>
  46. </Property>
  47. <Property name='user' type='string' key='user'>
  48. User identifier, used to define the identity of the end-user for retrieval and statistics.
  49. Should be uniquely defined by the developer within the application.
  50. </Property>
  51. <Property name='conversation_id' type='string' key='conversation_id'>
  52. Conversation ID, to continue the conversation based on previous chat records, it is necessary to pass the previous message's conversation_id.
  53. </Property>
  54. <Property name='files' type='array[object]' key='files'>
  55. File list, suitable for inputting files (images) combined with text understanding and answering questions, available only when the model supports Vision capability.
  56. - `type` (string) Supported type: `image` (currently only supports image type)
  57. - `transfer_method` (string) Transfer method, `remote_url` for image URL / `local_file` for file upload
  58. - `url` (string) Image URL (when the transfer method is `remote_url`)
  59. - `upload_file_id` (string) Uploaded file ID, which must be obtained by uploading through the File Upload API in advance (when the transfer method is `local_file`)
  60. </Property>
  61. <Property name='auto_generate_name' type='bool' key='auto_generate_name'>
  62. Auto-generate title, default is `true`.
  63. If set to `false`, can achieve async title generation by calling the conversation rename API and setting `auto_generate` to `true`.
  64. </Property>
  65. </Properties>
  66. ### Response
  67. When response_mode is blocking, return a CompletionResponse object.
  68. When response_mode is streaming, return a ChunkCompletionResponse stream.
  69. ### ChatCompletionResponse
  70. Returns the complete App result, `Content-Type` is `application/json`.
  71. - `message_id` (string) Unique message ID
  72. - `conversation_id` (string) Conversation ID
  73. - `mode` (string) App mode, fixed as `chat`
  74. - `answer` (string) Complete response content
  75. - `metadata` (object) Metadata
  76. - `usage` (Usage) Model usage information
  77. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  78. - `created_at` (int) Message creation timestamp, e.g., 1705395332
  79. ### ChunkChatCompletionResponse
  80. Returns the stream chunks outputted by the App, `Content-Type` is `text/event-stream`.
  81. Each streaming chunk starts with `data:`, separated by two newline characters `\n\n`, as shown below:
  82. <CodeGroup>
  83. ```streaming {{ title: 'Response' }}
  84. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  85. ```
  86. </CodeGroup>
  87. The structure of the streaming chunks varies depending on the `event`:
  88. - `event: message` LLM returns text chunk event, i.e., the complete text is output in a chunked fashion.
  89. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  90. - `message_id` (string) Unique message ID
  91. - `conversation_id` (string) Conversation ID
  92. - `answer` (string) LLM returned text chunk content
  93. - `created_at` (int) Creation timestamp, e.g., 1705395332
  94. - `event: agent_message` LLM returns text chunk event, i.e., with Agent Assistant enabled, the complete text is output in a chunked fashion (Only supported in Agent mode)
  95. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  96. - `message_id` (string) Unique message ID
  97. - `conversation_id` (string) Conversation ID
  98. - `answer` (string) LLM returned text chunk content
  99. - `created_at` (int) Creation timestamp, e.g., 1705395332
  100. - `event: tts_message` TTS audio stream event, that is, speech synthesis output. The content is an audio block in Mp3 format, encoded as a base64 string. When playing, simply decode the base64 and feed it into the player. (This message is available only when auto-play is enabled)
  101. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  102. - `message_id` (string) Unique message ID
  103. - `audio` (string) The audio after speech synthesis, encoded in base64 text content, when playing, simply decode the base64 and feed it into the player
  104. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  105. - `event: tts_message_end` TTS audio stream end event, receiving this event indicates the end of the audio stream.
  106. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  107. - `message_id` (string) Unique message ID
  108. - `audio` (string) The end event has no audio, so this is an empty string
  109. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  110. - `event: agent_thought` thought of Agent, contains the thought of LLM, input and output of tool calls (Only supported in Agent mode)
  111. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  112. - `task_id` (string) (string) Task ID, used for request tracking and the below Stop Generate API
  113. - `message_id` (string) Unique message ID
  114. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  115. - `thought` (string) What LLM is thinking about
  116. - `observation` (string) Response from tool calls
  117. - `tool` (string) A list of tools represents which tools are called,split by ;
  118. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  119. - `created_at` (int) Creation timestamp, e.g., 1705395332
  120. - `message_files` (array[string]) Refer to message_file event
  121. - `file_id` (string) File ID
  122. - `conversation_id` (string) Conversation ID
  123. - `event: message_file` Message file event, a new file has created by tool
  124. - `id` (string) File unique ID
  125. - `type` (string) File type,only allow "image" currently
  126. - `belongs_to` (string) Belongs to, it will only be an 'assistant' here
  127. - `url` (string) Remote url of file
  128. - `conversation_id` (string) Conversation ID
  129. - `event: message_end` Message end event, receiving this event means streaming has ended.
  130. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  131. - `message_id` (string) Unique message ID
  132. - `conversation_id` (string) Conversation ID
  133. - `metadata` (object) Metadata
  134. - `usage` (Usage) Model usage information
  135. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  136. - `event: message_replace` Message content replacement event.
  137. When output content moderation is enabled, if the content is flagged, then the message content will be replaced with a preset reply through this event.
  138. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  139. - `message_id` (string) Unique message ID
  140. - `conversation_id` (string) Conversation ID
  141. - `answer` (string) Replacement content (directly replaces all LLM reply text)
  142. - `created_at` (int) Creation timestamp, e.g., 1705395332
  143. - `event: error`
  144. Exceptions that occur during the streaming process will be output in the form of stream events, and reception of an error event will end the stream.
  145. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  146. - `message_id` (string) Unique message ID
  147. - `status` (int) HTTP status code
  148. - `code` (string) Error code
  149. - `message` (string) Error message
  150. - `event: ping` Ping event every 10 seconds to keep the connection alive.
  151. ### Errors
  152. - 404, Conversation does not exists
  153. - 400, `invalid_param`, abnormal parameter input
  154. - 400, `app_unavailable`, App configuration unavailable
  155. - 400, `provider_not_initialize`, no available model credential configuration
  156. - 400, `provider_quota_exceeded`, model invocation quota insufficient
  157. - 400, `model_currently_not_support`, current model unavailable
  158. - 400, `completion_request_error`, text generation failed
  159. - 500, internal server error
  160. </Col>
  161. <Col sticky>
  162. <CodeGroup title="Request" tag="POST" label="/chat-messages" targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "query": "What are the specs of the iPhone 13 Pro Max?",\n "response_mode": "streaming",\n "conversation_id": "",\n "user": "abc-123",\n "files": [\n {\n "type": "image",\n "transfer_method": "remote_url",\n "url": "https://cloud.dify.ai/logo/logo-site.png"\n }\n ]\n}'`}>
  163. ```bash {{ title: 'cURL' }}
  164. curl -X POST '${props.appDetail.api_base_url}/chat-messages' \
  165. --header 'Authorization: Bearer {api_key}' \
  166. --header 'Content-Type: application/json' \
  167. --data-raw '{
  168. "inputs": {},
  169. "query": "eh",
  170. "response_mode": "streaming",
  171. "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
  172. "user": "abc-123"
  173. }'
  174. ```
  175. </CodeGroup>
  176. ### Blocking Mode
  177. <CodeGroup title="Response">
  178. ```json {{ title: 'Response' }}
  179. {
  180. "event": "message",
  181. "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  182. "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
  183. "mode": "chat",
  184. "answer": "iPhone 13 Pro Max specs are listed here:...",
  185. "metadata": {
  186. "usage": {
  187. "prompt_tokens": 1033,
  188. "prompt_unit_price": "0.001",
  189. "prompt_price_unit": "0.001",
  190. "prompt_price": "0.0010330",
  191. "completion_tokens": 128,
  192. "completion_unit_price": "0.002",
  193. "completion_price_unit": "0.001",
  194. "completion_price": "0.0002560",
  195. "total_tokens": 1161,
  196. "total_price": "0.0012890",
  197. "currency": "USD",
  198. "latency": 0.7682376249867957
  199. },
  200. "retriever_resources": [
  201. {
  202. "position": 1,
  203. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  204. "dataset_name": "iPhone",
  205. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  206. "document_name": "iPhone List",
  207. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  208. "score": 0.98457545,
  209. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"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\""
  210. }
  211. ]
  212. },
  213. "created_at": 1705407629
  214. }
  215. ```
  216. </CodeGroup>
  217. ### Streaming Mode ( Basic Assistant )
  218. <CodeGroup title="Response">
  219. ```streaming {{ title: 'Response' }}
  220. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  221. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  222. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  223. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  224. data: {"event": "message", "message_id": : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  225. data: {"event": "message", "message_id": : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  226. data: {"event": "message_end", "id": "5e52ce04-874b-4d27-9045-b3bc80def685", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "metadata": {"usage": {"prompt_tokens": 1033, "prompt_unit_price": "0.001", "prompt_price_unit": "0.001", "prompt_price": "0.0010330", "completion_tokens": 135, "completion_unit_price": "0.002", "completion_price_unit": "0.001", "completion_price": "0.0002700", "total_tokens": 1168, "total_price": "0.0013030", "currency": "USD", "latency": 1.381760165997548}, "retriever_resources": [{"position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"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\""}]}}
  227. data: {"event": "tts_message", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"}
  228. data: {"event": "tts_message_end", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": ""}
  229. ```
  230. </CodeGroup>
  231. ### Response Example(Agent Assistant)
  232. <CodeGroup title="Response">
  233. ```streaming {{ title: 'Response' }}
  234. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  235. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  236. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  237. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  238. data: {"event": "message", "message_id": : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  239. data: {"event": "message", "message_id": : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  240. data: {"event": "message_end", "id": "5e52ce04-874b-4d27-9045-b3bc80def685", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "metadata": {"usage": {"prompt_tokens": 1033, "prompt_unit_price": "0.001", "prompt_price_unit": "0.001", "prompt_price": "0.0010330", "completion_tokens": 135, "completion_unit_price": "0.002", "completion_price_unit": "0.001", "completion_price": "0.0002700", "total_tokens": 1168, "total_price": "0.0013030", "currency": "USD", "latency": 1.381760165997548}, "retriever_resources": [{"position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"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\""}]}}
  241. data: {"event": "tts_message", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"}
  242. data: {"event": "tts_message_end", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": ""}
  243. ```
  244. </CodeGroup>
  245. </Col>
  246. </Row>
  247. ---
  248. <Heading
  249. url='/files/upload'
  250. method='POST'
  251. title='File Upload'
  252. name='#file-upload'
  253. />
  254. <Row>
  255. <Col>
  256. Upload a file (currently only images are supported) for use when sending messages, enabling multimodal understanding of images and text.
  257. Supports png, jpg, jpeg, webp, gif formats.
  258. Uploaded files are for use by the current end-user only.
  259. ### Request Body
  260. This interface requires a `multipart/form-data` request.
  261. - `file` (File) Required
  262. The file to be uploaded.
  263. - `user` (string) Required
  264. User identifier, defined by the developer's rules, must be unique within the application.
  265. ### Response
  266. After a successful upload, the server will return the file's ID and related information.
  267. - `id` (uuid) ID
  268. - `name` (string) File name
  269. - `size` (int) File size (bytes)
  270. - `extension` (string) File extension
  271. - `mime_type` (string) File mime-type
  272. - `created_by` (uuid) End-user ID
  273. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  274. ### Errors
  275. - 400, `no_file_uploaded`, a file must be provided
  276. - 400, `too_many_files`, currently only one file is accepted
  277. - 400, `unsupported_preview`, the file does not support preview
  278. - 400, `unsupported_estimate`, the file does not support estimation
  279. - 413, `file_too_large`, the file is too large
  280. - 415, `unsupported_file_type`, unsupported extension, currently only document files are accepted
  281. - 503, `s3_connection_failed`, unable to connect to S3 service
  282. - 503, `s3_permission_denied`, no permission to upload files to S3
  283. - 503, `s3_file_too_large`, file exceeds S3 size limit
  284. - 500, internal server error
  285. </Col>
  286. <Col sticky>
  287. ### Request Example
  288. <CodeGroup title="Request" tag="POST" label="/files/upload" targetCode={`curl -X POST '${props.appDetail.api_base_url}/files/upload' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'file=@localfile;type=image/[png|jpeg|jpg|webp|gif] \\\n--form 'user=abc-123'`}>
  289. ```bash {{ title: 'cURL' }}
  290. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  291. --header 'Authorization: Bearer {api_key}' \
  292. --form 'file=@"/path/to/file"'
  293. ```
  294. </CodeGroup>
  295. ### Response Example
  296. <CodeGroup title="Response">
  297. ```json {{ title: 'Response' }}
  298. {
  299. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  300. "name": "example.png",
  301. "size": 1024,
  302. "extension": "png",
  303. "mime_type": "image/png",
  304. "created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
  305. "created_at": 1577836800,
  306. }
  307. ```
  308. </CodeGroup>
  309. </Col>
  310. </Row>
  311. ---
  312. <Heading
  313. url='/chat-messages/:task_id/stop'
  314. method='POST'
  315. title='Stop Generate'
  316. name='#stop-generatebacks'
  317. />
  318. <Row>
  319. <Col>
  320. Only supported in streaming mode.
  321. ### Path
  322. - `task_id` (string) Task ID, can be obtained from the streaming chunk return
  323. ### Request Body
  324. - `user` (string) Required
  325. User identifier, used to define the identity of the end-user, must be consistent with the user passed in the send message interface.
  326. ### Response
  327. - `result` (string) Always returns "success"
  328. </Col>
  329. <Col sticky>
  330. ### Request Example
  331. <CodeGroup title="Request" tag="POST" label="/chat-messages/:task_id/stop" targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json' \\\n--data-raw '{"user": "abc-123"}'`}>
  332. ```bash {{ title: 'cURL' }}
  333. curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \
  334. -H 'Authorization: Bearer {api_key}' \
  335. -H 'Content-Type: application/json' \
  336. --data-raw '{
  337. "user": "abc-123"
  338. }'
  339. ```
  340. </CodeGroup>
  341. ### Response Example
  342. <CodeGroup title="Response">
  343. ```json {{ title: 'Response' }}
  344. {
  345. "result": "success"
  346. }
  347. ```
  348. </CodeGroup>
  349. </Col>
  350. </Row>
  351. ---
  352. <Heading
  353. url='/messages/:message_id/feedbacks'
  354. method='POST'
  355. title='Message Feedback'
  356. name='#feedbacks'
  357. />
  358. <Row>
  359. <Col>
  360. End-users can provide feedback messages, facilitating application developers to optimize expected outputs.
  361. ### Path
  362. <Properties>
  363. <Property name='message_id' type='string' key='message_id'>
  364. Message ID
  365. </Property>
  366. </Properties>
  367. ### Request Body
  368. <Properties>
  369. <Property name='rating' type='string' key='rating'>
  370. Upvote as `like`, downvote as `dislike`, revoke upvote as `null`
  371. </Property>
  372. <Property name='user' type='string' key='user'>
  373. User identifier, defined by the developer's rules, must be unique within the application.
  374. </Property>
  375. </Properties>
  376. ### Response
  377. - `result` (string) Always returns "success"
  378. </Col>
  379. <Col sticky>
  380. <CodeGroup title="Request" tag="POST" label="/messages/:message_id/feedbacks" targetCode={`curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks \\\n --header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "rating": "like",\n "user": "abc-123"\n}'`}>
  381. ```bash {{ title: 'cURL' }}
  382. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  383. --header 'Authorization: Bearer {api_key}' \
  384. --header 'Content-Type: application/json' \
  385. --data-raw '{
  386. "rating": "like",
  387. "user": "abc-123"
  388. }'
  389. ```
  390. </CodeGroup>
  391. <CodeGroup title="Response">
  392. ```json {{ title: 'Response' }}
  393. {
  394. "result": "success"
  395. }
  396. ```
  397. </CodeGroup>
  398. </Col>
  399. </Row>
  400. ---
  401. <Heading
  402. url='/messages/{message_id}/suggested'
  403. method='GET'
  404. title='next suggested questions'
  405. name='#suggested'
  406. />
  407. <Row>
  408. <Col>
  409. Get next questions suggestions for the current message
  410. ### Path Params
  411. <Properties>
  412. <Property name='message_id' type='string' key='message_id'>
  413. Message ID
  414. </Property>
  415. </Properties>
  416. ### Query
  417. <Properties>
  418. <Property name='user' type='string' key='user'>
  419. User identifier, used to define the identity of the end-user for retrieval and statistics.
  420. Should be uniquely defined by the developer within the application.
  421. </Property>
  422. </Properties>
  423. </Col>
  424. <Col sticky>
  425. <CodeGroup title="Request" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested?user=abc-123& \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}>
  426. ```bash {{ title: 'cURL' }}
  427. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
  428. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  429. --header 'Content-Type: application/json' \
  430. ```
  431. </CodeGroup>
  432. <CodeGroup title="Response">
  433. ```json {{ title: 'Response' }}
  434. {
  435. "result": "success",
  436. "data": [
  437. "a",
  438. "b",
  439. "c"
  440. ]
  441. }
  442. ```
  443. </CodeGroup>
  444. </Col>
  445. </Row>
  446. ---
  447. <Heading
  448. url='/messages'
  449. method='GET'
  450. title='Get Conversation History Messages'
  451. name='#messages'
  452. />
  453. <Row>
  454. <Col>
  455. Returns historical chat records in a scrolling load format, with the first page returning the latest `{limit}` messages, i.e., in reverse order.
  456. ### Query
  457. <Properties>
  458. <Property name='conversation_id' type='string' key='conversation_id'>
  459. Conversation ID
  460. </Property>
  461. <Property name='user' type='string' key='user'>
  462. User identifier, used to define the identity of the end-user for retrieval and statistics.
  463. Should be uniquely defined by the developer within the application.
  464. </Property>
  465. <Property name='first_id' type='string' key='first_id'>
  466. The ID of the first chat record on the current page, default is null.
  467. </Property>
  468. <Property name='limit' type='int' key='limit'>
  469. How many chat history messages to return in one request, default is 20.
  470. </Property>
  471. </Properties>
  472. ### Response
  473. - `data` (array[object]) Message list
  474. - `id` (string) Message ID
  475. - `conversation_id` (string) Conversation ID
  476. - `inputs` (array[object]) User input parameters.
  477. - `query` (string) User input / question content.
  478. - `message_files` (array[object]) Message files
  479. - `id` (string) ID
  480. - `type` (string) File type, image for images
  481. - `url` (string) Preview image URL
  482. - `belongs_to` (string) belongs to,user or assistant
  483. - `agent_thoughts` (array[object]) Agent thought(Empty if it's a Basic Assistant)
  484. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  485. - `message_id` (string) Unique message ID
  486. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  487. - `thought` (string) What LLM is thinking about
  488. - `observation` (string) Response from tool calls
  489. - `tool` (string) A list of tools represents which tools are called,split by ;
  490. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  491. - `created_at` (int) Creation timestamp, e.g., 1705395332
  492. - `message_files` (array[string]) Refer to message_file event
  493. - `file_id` (string) File ID
  494. - `answer` (string) Response message content
  495. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  496. - `feedback` (object) Feedback information
  497. - `rating` (string) Upvote as `like` / Downvote as `dislike`
  498. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  499. - `has_more` (bool) Whether there is a next page
  500. - `limit` (int) Number of returned items, if input exceeds system limit, returns system limit amount
  501. </Col>
  502. <Col sticky>
  503. <CodeGroup title="Request" tag="GET" label="/messages" targetCode={`curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='\\\n --header 'Authorization: Bearer {api_key}'`}>
  504. ```bash {{ title: 'cURL' }}
  505. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  506. --header 'Authorization: Bearer {api_key}'
  507. ```
  508. </CodeGroup>
  509. ### Response Example (Basic Assistant)
  510. <CodeGroup title="Response">
  511. ```json {{ title: 'Response' }}
  512. {
  513. "limit": 20,
  514. "has_more": false,
  515. "data": [
  516. {
  517. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  518. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  519. "inputs": {
  520. "name": "dify"
  521. },
  522. "query": "iphone 13 pro",
  523. "answer": "The iPhone 13 Pro, released on September 24, 2021, features a 6.1-inch display with a resolution of 1170 x 2532. It is equipped with a Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard) processor, 6 GB of RAM, and offers storage options of 128 GB, 256 GB, 512 GB, and 1 TB. The camera is 12 MP, the battery capacity is 3095 mAh, and it runs on iOS 15.",
  524. "message_files": [],
  525. "feedback": null,
  526. "retriever_resources": [
  527. {
  528. "position": 1,
  529. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  530. "dataset_name": "iPhone",
  531. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  532. "document_name": "iPhone List",
  533. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  534. "score": 0.98457545,
  535. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"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\""
  536. }
  537. ],
  538. "agent_thoughts": [],
  539. "created_at": 1705569239,
  540. }
  541. ]
  542. }
  543. ```
  544. </CodeGroup>
  545. ### Response Example (Agent Assistant)
  546. <CodeGroup title="Response">
  547. ```json {{ title: 'Response' }}
  548. {
  549. "limit": 20,
  550. "has_more": false,
  551. "data": [
  552. {
  553. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  554. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  555. "inputs": {},
  556. "query": "draw a cat",
  557. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  558. "message_files": [
  559. {
  560. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  561. "type": "image",
  562. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  563. "belongs_to": "assistant"
  564. }
  565. ],
  566. "feedback": null,
  567. "retriever_resources": [],
  568. "created_at": 1705988187,
  569. "agent_thoughts": [
  570. {
  571. "id": "592c84cf-07ee-441c-9dcc-ffc66c033469",
  572. "chain_id": null,
  573. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  574. "position": 1,
  575. "thought": "",
  576. "tool": "dalle2",
  577. "tool_input": "{\"dalle2\": {\"prompt\": \"cat\"}}",
  578. "created_at": 1705988186,
  579. "observation": "image has been created and sent to user already, you should tell user to check it now.",
  580. "message_files": [
  581. "976990d2-5294-47e6-8f14-7356ba9d2d76"
  582. ]
  583. },
  584. {
  585. "id": "73ead60d-2370-4780-b5ed-532d2762b0e5",
  586. "chain_id": null,
  587. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  588. "position": 2,
  589. "thought": "I have generated an image of a cat for you. Please check your messages to view the image.",
  590. "tool": "",
  591. "tool_input": "",
  592. "created_at": 1705988199,
  593. "observation": "",
  594. "message_files": []
  595. }
  596. ]
  597. }
  598. ]
  599. }
  600. ```
  601. </CodeGroup>
  602. </Col>
  603. </Row>
  604. ---
  605. <Heading
  606. url='/conversations'
  607. method='GET'
  608. title='Get Conversations'
  609. name='#conversations'
  610. />
  611. <Row>
  612. <Col>
  613. Retrieve the conversation list for the current user, defaulting to the most recent 20 entries.
  614. ### Query
  615. <Properties>
  616. <Property name='user' type='string' key='user'>
  617. User identifier, used to define the identity of the end-user for retrieval and statistics.
  618. Should be uniquely defined by the developer within the application.
  619. </Property>
  620. <Property name='last_id' type='string' key='last_id'>
  621. The ID of the last record on the current page, default is null.
  622. </Property>
  623. <Property name='limit' type='int' key='limit'>
  624. How many records to return in one request, default is the most recent 20 entries.
  625. </Property>
  626. <Property name='pinned' type='bool' key='pinned'>
  627. Return only pinned conversations as `true`, only non-pinned as `false`
  628. </Property>
  629. </Properties>
  630. ### Response
  631. - `data` (array[object]) List of conversations
  632. - `id` (string) Conversation ID
  633. - `name` (string) Conversation name, by default, is a snippet of the first question asked by the user in the conversation.
  634. - `inputs` (array[object]) User input parameters.
  635. - `introduction` (string) Introduction
  636. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  637. - `has_more` (bool)
  638. - `limit` (int) Number of entries returned, if input exceeds system limit, system limit number is returned
  639. </Col>
  640. <Col sticky>
  641. <CodeGroup title="Request" tag="GET" label="/conversations" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20'`}>
  642. ```bash {{ title: 'cURL' }}
  643. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  644. --header 'Authorization: Bearer {api_key}'
  645. ```
  646. </CodeGroup>
  647. <CodeGroup title="Response">
  648. ```json {{ title: 'Response' }}
  649. {
  650. "limit": 20,
  651. "has_more": false,
  652. "data": [
  653. {
  654. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  655. "name": "New chat",
  656. "inputs": {
  657. "book": "book",
  658. "myName": "Lucy"
  659. },
  660. "status": "normal",
  661. "created_at": 1679667915
  662. },
  663. {
  664. "id": "hSIhXBhNe8X1d8Et"
  665. // ...
  666. }
  667. ]
  668. }
  669. ```
  670. </CodeGroup>
  671. </Col>
  672. </Row>
  673. ---
  674. <Heading
  675. url='/conversations/:conversation_id'
  676. method='DELETE'
  677. title='Delete Conversation'
  678. name='#delete'
  679. />
  680. <Row>
  681. <Col>
  682. Delete a conversation.
  683. ### Path
  684. - `conversation_id` (string) Conversation ID
  685. ### Request Body
  686. <Properties>
  687. <Property name='user' type='string' key='user'>
  688. The user identifier, defined by the developer, must ensure uniqueness within the application.
  689. </Property>
  690. </Properties>
  691. ### Response
  692. - `result` (string) Always returns "success"
  693. </Col>
  694. <Col sticky>
  695. <CodeGroup title="Request" tag="DELETE" label="/conversations/:conversation_id" targetCode={`curl -X DELETE '${props.appDetail.api_base_url}/conversations/:conversation_id' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "user": "abc-123"\n}'`}>
  696. ```bash {{ title: 'cURL' }}
  697. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  698. --header 'Content-Type: application/json' \
  699. --header 'Accept: application/json' \
  700. --header 'Authorization: Bearer {api_key}' \
  701. --data '{
  702. "user": "abc-123"
  703. }'
  704. ```
  705. </CodeGroup>
  706. <CodeGroup title="Response">
  707. ```json {{ title: 'Response' }}
  708. {
  709. "result": "success"
  710. }
  711. ```
  712. </CodeGroup>
  713. </Col>
  714. </Row>
  715. ---
  716. <Heading
  717. url='/conversations/:conversation_id/name'
  718. method='POST'
  719. title='Conversation Rename'
  720. name='#rename'
  721. />
  722. <Row>
  723. <Col>
  724. ### Request Body
  725. <Properties>
  726. <Property name='name' type='string' key='name'>
  727. The name of the conversation. This parameter can be omitted if `auto_generate` is set to `true`.
  728. </Property>
  729. <Property name='auto_generate' type='bool' key='auto_generate'>
  730. Automatically generate the title, default is `false`
  731. </Property>
  732. <Property name='user' type='string' key='user'>
  733. The user identifier, defined by the developer, must ensure uniqueness within the application.
  734. </Property>
  735. </Properties>
  736. ### Response
  737. - `id` (string) Conversation ID
  738. - `name` (string) Conversation name
  739. - `inputs` array[object] User input parameters.
  740. - `introduction` (string) Introduction
  741. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  742. </Col>
  743. <Col sticky>
  744. <CodeGroup title="Request" tag="POST" label="/conversations/:conversation_id/name" targetCode={`curl -X POST '${props.appDetail.api_base_url}/conversations/name' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "user": "abc-123"\n}'`}>
  745. ```bash {{ title: 'cURL' }}
  746. curl -X POST '${props.appDetail.api_base_url}/conversations/:conversation_id/name' \
  747. --header 'Content-Type: application/json' \
  748. --header 'Authorization: Bearer {api_key}' \
  749. --data-raw '{
  750. "name": "",
  751. "user": "abc-123"
  752. }'
  753. ```
  754. </CodeGroup>
  755. <CodeGroup title="Response">
  756. ```json {{ title: 'Response' }}
  757. {
  758. "id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  759. "name": "Chat vs AI",
  760. "inputs": {},
  761. "introduction": "",
  762. "created_at": 1705569238
  763. }
  764. ```
  765. </CodeGroup>
  766. </Col>
  767. </Row>
  768. ---
  769. <Heading
  770. url='/audio-to-text'
  771. method='POST'
  772. title='Speech to Text'
  773. name='#audio'
  774. />
  775. <Row>
  776. <Col>
  777. This endpoint requires a multipart/form-data request.
  778. ### Request Body
  779. <Properties>
  780. <Property name='file' type='file' key='file'>
  781. Audio file.
  782. Supported formats: `['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  783. File size limit: 15MB
  784. </Property>
  785. <Property name='user' type='string' key='user'>
  786. User identifier, defined by the developer's rules, must be unique within the application.
  787. </Property>
  788. </Properties>
  789. ### Response
  790. - `text` (string) Output text
  791. </Col>
  792. <Col sticky>
  793. <CodeGroup title="Request" tag="POST" label="/audio-to-text" targetCode={`curl -X POST '${props.appDetail.api_base_url}/audio-to-text' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'file=@localfile;type=audio/[mp3|mp4|mpeg|mpga|m4a|wav|webm]'`}>
  794. ```bash {{ title: 'cURL' }}
  795. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  796. --header 'Authorization: Bearer {api_key}' \
  797. --form 'file=@localfile;type=audio/mp3'
  798. ```
  799. </CodeGroup>
  800. <CodeGroup title="Response">
  801. ```json {{ text: 'hello' }}
  802. {
  803. "text": ""
  804. }
  805. ```
  806. </CodeGroup>
  807. </Col>
  808. </Row>
  809. ---
  810. <Heading
  811. url='/text-to-audio'
  812. method='POST'
  813. title='text to audio'
  814. name='#audio'
  815. />
  816. <Row>
  817. <Col>
  818. Text to speech.
  819. ### Request Body
  820. <Properties>
  821. <Property name='message_id' type='str' key='text'>
  822. For text messages generated by Dify, simply pass the generated message-id directly. The backend will use the message-id to look up the corresponding content and synthesize the voice information directly. If both message_id and text are provided simultaneously, the message_id is given priority.
  823. </Property>
  824. <Property name='text' type='str' key='text'>
  825. Speech generated content。
  826. </Property>
  827. <Property name='user' type='string' key='user'>
  828. The user identifier, defined by the developer, must ensure uniqueness within the app.
  829. </Property>
  830. </Properties>
  831. </Col>
  832. <Col sticky>
  833. <CodeGroup title="Request" tag="POST" label="/text-to-audio" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--form 'text=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290`}>
  834. ```bash {{ title: 'cURL' }}
  835. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  836. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  837. --form 'file=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290'
  838. ```
  839. </CodeGroup>
  840. <CodeGroup title="headers">
  841. ```json {{ title: 'headers' }}
  842. {
  843. "Content-Type": "audio/wav"
  844. }
  845. ```
  846. </CodeGroup>
  847. </Col>
  848. </Row>
  849. ---
  850. <Heading
  851. url='/parameters'
  852. method='GET'
  853. title='Get Application Information'
  854. name='#parameters'
  855. />
  856. <Row>
  857. <Col>
  858. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  859. ### Query
  860. <Properties>
  861. <Property name='user' type='string' key='user'>
  862. User identifier, defined by the developer's rules, must be unique within the application.
  863. </Property>
  864. </Properties>
  865. ### Response
  866. - `opening_statement` (string) Opening statement
  867. - `suggested_questions` (array[string]) List of suggested questions for the opening
  868. - `suggested_questions_after_answer` (object) Suggest questions after enabling the answer.
  869. - `enabled` (bool) Whether it is enabled
  870. - `speech_to_text` (object) Speech to text
  871. - `enabled` (bool) Whether it is enabled
  872. - `retriever_resource` (object) Citation and Attribution
  873. - `enabled` (bool) Whether it is enabled
  874. - `annotation_reply` (object) Annotation reply
  875. - `enabled` (bool) Whether it is enabled
  876. - `user_input_form` (array[object]) User input form configuration
  877. - `text-input` (object) Text input control
  878. - `label` (string) Variable display label name
  879. - `variable` (string) Variable ID
  880. - `required` (bool) Whether it is required
  881. - `default` (string) Default value
  882. - `paragraph` (object) Paragraph text input control
  883. - `label` (string) Variable display label name
  884. - `variable` (string) Variable ID
  885. - `required` (bool) Whether it is required
  886. - `default` (string) Default value
  887. - `select` (object) Dropdown control
  888. - `label` (string) Variable display label name
  889. - `variable` (string) Variable ID
  890. - `required` (bool) Whether it is required
  891. - `default` (string) Default value
  892. - `options` (array[string]) Option values
  893. - `file_upload` (object) File upload configuration
  894. - `image` (object) Image settings
  895. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`
  896. - `enabled` (bool) Whether it is enabled
  897. - `number_limits` (int) Image number limit, default is 3
  898. - `transfer_methods` (array[string]) List of transfer methods, remote_url, local_file, must choose one
  899. - `system_parameters` (object) System parameters
  900. - `file_size_limit` (int) Document upload size limit (MB)
  901. - `image_file_size_limit` (int) Image file upload size limit (MB)
  902. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  903. - `video_file_size_limit` (int) Video file upload size limit (MB)
  904. </Col>
  905. <Col sticky>
  906. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123'`}>
  907. ```bash {{ title: 'cURL' }}
  908. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  909. --header 'Authorization: Bearer {api_key}'
  910. ```
  911. </CodeGroup>
  912. <CodeGroup title="Response">
  913. ```json {{ title: 'Response' }}
  914. {
  915. "opening_statement": "Hello!",
  916. "suggested_questions_after_answer": {
  917. "enabled": true
  918. },
  919. "speech_to_text": {
  920. "enabled": true
  921. },
  922. "retriever_resource": {
  923. "enabled": true
  924. },
  925. "annotation_reply": {
  926. "enabled": true
  927. },
  928. "user_input_form": [
  929. {
  930. "paragraph": {
  931. "label": "Query",
  932. "variable": "query",
  933. "required": true,
  934. "default": ""
  935. }
  936. }
  937. ],
  938. "file_upload": {
  939. "image": {
  940. "enabled": false,
  941. "number_limits": 3,
  942. "detail": "high",
  943. "transfer_methods": [
  944. "remote_url",
  945. "local_file"
  946. ]
  947. }
  948. },
  949. "system_parameters": {
  950. "file_size_limit": 15,
  951. "image_file_size_limit": 10,
  952. "audio_file_size_limit": 50,
  953. "video_file_size_limit": 100
  954. }
  955. }
  956. ```
  957. </CodeGroup>
  958. </Col>
  959. </Row>
  960. ---
  961. <Heading
  962. url='/meta'
  963. method='GET'
  964. title='Get Application Meta Information'
  965. name='#meta'
  966. />
  967. <Row>
  968. <Col>
  969. Used to get icons of tools in this application
  970. ### Query
  971. <Properties>
  972. <Property name='user' type='string' key='user'>
  973. User identifier, defined by the developer's rules, must be unique within the application.
  974. </Property>
  975. </Properties>
  976. ### Response
  977. - `tool_icons`(object[string]) tool icons
  978. - `tool_name` (string)
  979. - `icon` (object|string)
  980. - (object) icon object
  981. - `background` (string) background color in hex format
  982. - `content`(string) emoji
  983. - (string) url of icon
  984. </Col>
  985. <Col>
  986. <CodeGroup title="Request" tag="GET" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \\\n-H 'Authorization: Bearer {api_key}'`}>
  987. ```bash {{ title: 'cURL' }}
  988. curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \
  989. -H 'Authorization: Bearer {api_key}'
  990. ```
  991. </CodeGroup>
  992. <CodeGroup title="Response">
  993. ```json {{ title: 'Response' }}
  994. {
  995. "tool_icons": {
  996. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  997. "api_tool": {
  998. "background": "#252525",
  999. "content": "\ud83d\ude01"
  1000. }
  1001. }
  1002. }
  1003. ```
  1004. </CodeGroup>
  1005. </Col>
  1006. </Row>