template_chat.en.mdx 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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` (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. (Optional) The ID of the last record on the current page, default is null.
  622. </Property>
  623. <Property name='limit' type='int' key='limit'>
  624. (Optional) How many records to return in one request, default is the most recent 20 entries. Maximum 100, minimum 1.
  625. </Property>
  626. <Property name='sort_by' type='string' key='sort_by'>
  627. (Optional) Sorting Field, Default: -updated_at (sorted in descending order by update time)
  628. - Available Values: created_at, -created_at, updated_at, -updated_at
  629. - The symbol before the field represents the order or reverse, "-" represents reverse order.
  630. </Property>
  631. </Properties>
  632. ### Response
  633. - `data` (array[object]) List of conversations
  634. - `id` (string) Conversation ID
  635. - `name` (string) Conversation name, by default, is a snippet of the first question asked by the user in the conversation.
  636. - `inputs` (object) User input parameters.
  637. - `status` (string) Conversation status
  638. - `introduction` (string) Introduction
  639. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  640. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  641. - `has_more` (bool)
  642. - `limit` (int) Number of entries returned, if input exceeds system limit, system limit number is returned
  643. </Col>
  644. <Col sticky>
  645. <CodeGroup title="Request" tag="GET" label="/conversations" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20'`}>
  646. ```bash {{ title: 'cURL' }}
  647. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  648. --header 'Authorization: Bearer {api_key}'
  649. ```
  650. </CodeGroup>
  651. <CodeGroup title="Response">
  652. ```json {{ title: 'Response' }}
  653. {
  654. "limit": 20,
  655. "has_more": false,
  656. "data": [
  657. {
  658. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  659. "name": "New chat",
  660. "inputs": {
  661. "book": "book",
  662. "myName": "Lucy"
  663. },
  664. "status": "normal",
  665. "created_at": 1679667915,
  666. "updated_at": 1679667915
  667. },
  668. {
  669. "id": "hSIhXBhNe8X1d8Et"
  670. // ...
  671. }
  672. ]
  673. }
  674. ```
  675. </CodeGroup>
  676. </Col>
  677. </Row>
  678. ---
  679. <Heading
  680. url='/conversations/:conversation_id'
  681. method='DELETE'
  682. title='Delete Conversation'
  683. name='#delete'
  684. />
  685. <Row>
  686. <Col>
  687. Delete a conversation.
  688. ### Path
  689. - `conversation_id` (string) Conversation ID
  690. ### Request Body
  691. <Properties>
  692. <Property name='user' type='string' key='user'>
  693. The user identifier, defined by the developer, must ensure uniqueness within the application.
  694. </Property>
  695. </Properties>
  696. ### Response
  697. - `result` (string) Always returns "success"
  698. </Col>
  699. <Col sticky>
  700. <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}'`}>
  701. ```bash {{ title: 'cURL' }}
  702. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  703. --header 'Content-Type: application/json' \
  704. --header 'Accept: application/json' \
  705. --header 'Authorization: Bearer {api_key}' \
  706. --data '{
  707. "user": "abc-123"
  708. }'
  709. ```
  710. </CodeGroup>
  711. <CodeGroup title="Response">
  712. ```json {{ title: 'Response' }}
  713. {
  714. "result": "success"
  715. }
  716. ```
  717. </CodeGroup>
  718. </Col>
  719. </Row>
  720. ---
  721. <Heading
  722. url='/conversations/:conversation_id/name'
  723. method='POST'
  724. title='Conversation Rename'
  725. name='#rename'
  726. />
  727. <Row>
  728. <Col>
  729. ### Request Body
  730. Rename the session, the session name is used for display on clients that support multiple sessions.
  731. ### Path
  732. - `conversation_id` (string) Conversation ID
  733. <Properties>
  734. <Property name='name' type='string' key='name'>
  735. (Optional) The name of the conversation. This parameter can be omitted if `auto_generate` is set to `true`.
  736. </Property>
  737. <Property name='auto_generate' type='bool' key='auto_generate'>
  738. (Optional) Automatically generate the title, default is `false`
  739. </Property>
  740. <Property name='user' type='string' key='user'>
  741. The user identifier, defined by the developer, must ensure uniqueness within the application.
  742. </Property>
  743. </Properties>
  744. ### Response
  745. - `id` (string) Conversation ID
  746. - `name` (string) Conversation name
  747. - `inputs` (object) User input parameters
  748. - `status` (string) Conversation status
  749. - `introduction` (string) Introduction
  750. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  751. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  752. </Col>
  753. <Col sticky>
  754. <CodeGroup title="Request" tag="POST" label="/conversations/:conversation_id/name" targetCode={`curl -X POST '${props.appDetail.api_base_url}/conversations/:conversation_id/name' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "auto_generate": true, \n "user": "abc-123"\n}'`}>
  755. ```bash {{ title: 'cURL' }}
  756. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  757. --header 'Content-Type: application/json' \
  758. --header 'Authorization: Bearer {api_key}' \
  759. --data-raw '{
  760. "name": "",
  761. "auto_generate": true,
  762. "user": "abc-123"
  763. }'
  764. ```
  765. </CodeGroup>
  766. <CodeGroup title="Response">
  767. ```json {{ title: 'Response' }}
  768. {
  769. "id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  770. "name": "Chat vs AI",
  771. "inputs": {},
  772. "status": "normal",
  773. "introduction": "",
  774. "created_at": 1705569238,
  775. "updated_at": 1705569238
  776. }
  777. ```
  778. </CodeGroup>
  779. </Col>
  780. </Row>
  781. ---
  782. <Heading
  783. url='/audio-to-text'
  784. method='POST'
  785. title='Speech to Text'
  786. name='#audio'
  787. />
  788. <Row>
  789. <Col>
  790. This endpoint requires a multipart/form-data request.
  791. ### Request Body
  792. <Properties>
  793. <Property name='file' type='file' key='file'>
  794. Audio file.
  795. Supported formats: `['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  796. File size limit: 15MB
  797. </Property>
  798. <Property name='user' type='string' key='user'>
  799. User identifier, defined by the developer's rules, must be unique within the application.
  800. </Property>
  801. </Properties>
  802. ### Response
  803. - `text` (string) Output text
  804. </Col>
  805. <Col sticky>
  806. <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]'`}>
  807. ```bash {{ title: 'cURL' }}
  808. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  809. --header 'Authorization: Bearer {api_key}' \
  810. --form 'file=@localfile;type=audio/mp3'
  811. ```
  812. </CodeGroup>
  813. <CodeGroup title="Response">
  814. ```json {{ text: 'hello' }}
  815. {
  816. "text": ""
  817. }
  818. ```
  819. </CodeGroup>
  820. </Col>
  821. </Row>
  822. ---
  823. <Heading
  824. url='/text-to-audio'
  825. method='POST'
  826. title='Text to Audio'
  827. name='#audio'
  828. />
  829. <Row>
  830. <Col>
  831. Text to speech.
  832. ### Request Body
  833. <Properties>
  834. <Property name='message_id' type='str' key='text'>
  835. 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.
  836. </Property>
  837. <Property name='text' type='str' key='text'>
  838. Speech generated content。
  839. </Property>
  840. <Property name='user' type='string' key='user'>
  841. The user identifier, defined by the developer, must ensure uniqueness within the app.
  842. </Property>
  843. </Properties>
  844. </Col>
  845. <Col sticky>
  846. <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`}>
  847. ```bash {{ title: 'cURL' }}
  848. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  849. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  850. --form 'file=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290'
  851. ```
  852. </CodeGroup>
  853. <CodeGroup title="headers">
  854. ```json {{ title: 'headers' }}
  855. {
  856. "Content-Type": "audio/wav"
  857. }
  858. ```
  859. </CodeGroup>
  860. </Col>
  861. </Row>
  862. ---
  863. <Heading
  864. url='/info'
  865. method='GET'
  866. title='Get Application Basic Information'
  867. name='#info'
  868. />
  869. <Row>
  870. <Col>
  871. Used to get basic information about this application
  872. ### Query
  873. <Properties>
  874. <Property name='user' type='string' key='user'>
  875. User identifier, defined by the developer's rules, must be unique within the application.
  876. </Property>
  877. </Properties>
  878. ### Response
  879. - `name` (string) application name
  880. - `description` (string) application description
  881. - `tags` (array[string]) application tags
  882. </Col>
  883. <Col>
  884. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info?user=abc-123' \\\n-H 'Authorization: Bearer {api_key}'`}>
  885. ```bash {{ title: 'cURL' }}
  886. curl -X GET '${props.appDetail.api_base_url}/info?user=abc-123' \
  887. -H 'Authorization: Bearer {api_key}'
  888. ```
  889. </CodeGroup>
  890. <CodeGroup title="Response">
  891. ```json {{ title: 'Response' }}
  892. {
  893. "name": "My App",
  894. "description": "This is my app.",
  895. "tags": [
  896. "tag1",
  897. "tag2"
  898. ]
  899. }
  900. ```
  901. </CodeGroup>
  902. </Col>
  903. </Row>
  904. ---
  905. <Heading
  906. url='/parameters'
  907. method='GET'
  908. title='Get Application Parameters Information'
  909. name='#parameters'
  910. />
  911. <Row>
  912. <Col>
  913. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  914. ### Query
  915. <Properties>
  916. <Property name='user' type='string' key='user'>
  917. User identifier, defined by the developer's rules, must be unique within the application.
  918. </Property>
  919. </Properties>
  920. ### Response
  921. - `opening_statement` (string) Opening statement
  922. - `suggested_questions` (array[string]) List of suggested questions for the opening
  923. - `suggested_questions_after_answer` (object) Suggest questions after enabling the answer.
  924. - `enabled` (bool) Whether it is enabled
  925. - `speech_to_text` (object) Speech to text
  926. - `enabled` (bool) Whether it is enabled
  927. - `retriever_resource` (object) Citation and Attribution
  928. - `enabled` (bool) Whether it is enabled
  929. - `annotation_reply` (object) Annotation reply
  930. - `enabled` (bool) Whether it is enabled
  931. - `user_input_form` (array[object]) User input form configuration
  932. - `text-input` (object) Text input control
  933. - `label` (string) Variable display label name
  934. - `variable` (string) Variable ID
  935. - `required` (bool) Whether it is required
  936. - `default` (string) Default value
  937. - `paragraph` (object) Paragraph text input control
  938. - `label` (string) Variable display label name
  939. - `variable` (string) Variable ID
  940. - `required` (bool) Whether it is required
  941. - `default` (string) Default value
  942. - `select` (object) Dropdown control
  943. - `label` (string) Variable display label name
  944. - `variable` (string) Variable ID
  945. - `required` (bool) Whether it is required
  946. - `default` (string) Default value
  947. - `options` (array[string]) Option values
  948. - `file_upload` (object) File upload configuration
  949. - `image` (object) Image settings
  950. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`
  951. - `enabled` (bool) Whether it is enabled
  952. - `number_limits` (int) Image number limit, default is 3
  953. - `transfer_methods` (array[string]) List of transfer methods, remote_url, local_file, must choose one
  954. - `system_parameters` (object) System parameters
  955. - `file_size_limit` (int) Document upload size limit (MB)
  956. - `image_file_size_limit` (int) Image file upload size limit (MB)
  957. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  958. - `video_file_size_limit` (int) Video file upload size limit (MB)
  959. </Col>
  960. <Col sticky>
  961. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123'`}>
  962. ```bash {{ title: 'cURL' }}
  963. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  964. --header 'Authorization: Bearer {api_key}'
  965. ```
  966. </CodeGroup>
  967. <CodeGroup title="Response">
  968. ```json {{ title: 'Response' }}
  969. {
  970. "opening_statement": "Hello!",
  971. "suggested_questions_after_answer": {
  972. "enabled": true
  973. },
  974. "speech_to_text": {
  975. "enabled": true
  976. },
  977. "retriever_resource": {
  978. "enabled": true
  979. },
  980. "annotation_reply": {
  981. "enabled": true
  982. },
  983. "user_input_form": [
  984. {
  985. "paragraph": {
  986. "label": "Query",
  987. "variable": "query",
  988. "required": true,
  989. "default": ""
  990. }
  991. }
  992. ],
  993. "file_upload": {
  994. "image": {
  995. "enabled": false,
  996. "number_limits": 3,
  997. "detail": "high",
  998. "transfer_methods": [
  999. "remote_url",
  1000. "local_file"
  1001. ]
  1002. }
  1003. },
  1004. "system_parameters": {
  1005. "file_size_limit": 15,
  1006. "image_file_size_limit": 10,
  1007. "audio_file_size_limit": 50,
  1008. "video_file_size_limit": 100
  1009. }
  1010. }
  1011. ```
  1012. </CodeGroup>
  1013. </Col>
  1014. </Row>
  1015. ---
  1016. <Heading
  1017. url='/meta'
  1018. method='GET'
  1019. title='Get Application Meta Information'
  1020. name='#meta'
  1021. />
  1022. <Row>
  1023. <Col>
  1024. Used to get icons of tools in this application
  1025. ### Query
  1026. <Properties>
  1027. <Property name='user' type='string' key='user'>
  1028. User identifier, defined by the developer's rules, must be unique within the application.
  1029. </Property>
  1030. </Properties>
  1031. ### Response
  1032. - `tool_icons`(object[string]) tool icons
  1033. - `tool_name` (string)
  1034. - `icon` (object|string)
  1035. - (object) icon object
  1036. - `background` (string) background color in hex format
  1037. - `content`(string) emoji
  1038. - (string) url of icon
  1039. </Col>
  1040. <Col>
  1041. <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}'`}>
  1042. ```bash {{ title: 'cURL' }}
  1043. curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \
  1044. -H 'Authorization: Bearer {api_key}'
  1045. ```
  1046. </CodeGroup>
  1047. <CodeGroup title="Response">
  1048. ```json {{ title: 'Response' }}
  1049. {
  1050. "tool_icons": {
  1051. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1052. "api_tool": {
  1053. "background": "#252525",
  1054. "content": "\ud83d\ude01"
  1055. }
  1056. }
  1057. }
  1058. ```
  1059. </CodeGroup>
  1060. </Col>
  1061. </Row>