您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

template_chat.en.mdx 65KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  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. - `event` (string) 事件类型,固定为 `message`
  72. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  73. - `id` (string) 唯一ID
  74. - `message_id` (string) Unique message ID
  75. - `conversation_id` (string) Conversation ID
  76. - `mode` (string) App mode, fixed as `chat`
  77. - `answer` (string) Complete response content
  78. - `metadata` (object) Metadata
  79. - `usage` (Usage) Model usage information
  80. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  81. - `created_at` (int) Message creation timestamp, e.g., 1705395332
  82. ### ChunkChatCompletionResponse
  83. Returns the stream chunks outputted by the App, `Content-Type` is `text/event-stream`.
  84. Each streaming chunk starts with `data:`, separated by two newline characters `\n\n`, as shown below:
  85. <CodeGroup>
  86. ```streaming {{ title: 'Response' }}
  87. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  88. ```
  89. </CodeGroup>
  90. The structure of the streaming chunks varies depending on the `event`:
  91. - `event: message` LLM returns text chunk event, i.e., the complete text is output in a chunked fashion.
  92. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  93. - `message_id` (string) Unique message ID
  94. - `conversation_id` (string) Conversation ID
  95. - `answer` (string) LLM returned text chunk content
  96. - `created_at` (int) Creation timestamp, e.g., 1705395332
  97. - `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)
  98. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  99. - `message_id` (string) Unique message ID
  100. - `conversation_id` (string) Conversation ID
  101. - `answer` (string) LLM returned text chunk content
  102. - `created_at` (int) Creation timestamp, e.g., 1705395332
  103. - `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)
  104. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  105. - `message_id` (string) Unique message ID
  106. - `audio` (string) The audio after speech synthesis, encoded in base64 text content, when playing, simply decode the base64 and feed it into the player
  107. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  108. - `event: tts_message_end` TTS audio stream end event, receiving this event indicates the end of the audio stream.
  109. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  110. - `message_id` (string) Unique message ID
  111. - `audio` (string) The end event has no audio, so this is an empty string
  112. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  113. - `event: agent_thought` thought of Agent, contains the thought of LLM, input and output of tool calls (Only supported in Agent mode)
  114. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  115. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  116. - `message_id` (string) Unique message ID
  117. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  118. - `thought` (string) What LLM is thinking about
  119. - `observation` (string) Response from tool calls
  120. - `tool` (string) A list of tools represents which tools are called,split by ;
  121. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  122. - `created_at` (int) Creation timestamp, e.g., 1705395332
  123. - `message_files` (array[string]) Refer to message_file event
  124. - `file_id` (string) File ID
  125. - `conversation_id` (string) Conversation ID
  126. - `event: message_file` Message file event, a new file has created by tool
  127. - `id` (string) File unique ID
  128. - `type` (string) File type,only allow "image" currently
  129. - `belongs_to` (string) Belongs to, it will only be an 'assistant' here
  130. - `url` (string) Remote url of file
  131. - `conversation_id` (string) Conversation ID
  132. - `event: message_end` Message end event, receiving this event means streaming has ended.
  133. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  134. - `message_id` (string) Unique message ID
  135. - `conversation_id` (string) Conversation ID
  136. - `metadata` (object) Metadata
  137. - `usage` (Usage) Model usage information
  138. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  139. - `event: message_replace` Message content replacement event.
  140. 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.
  141. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  142. - `message_id` (string) Unique message ID
  143. - `conversation_id` (string) Conversation ID
  144. - `answer` (string) Replacement content (directly replaces all LLM reply text)
  145. - `created_at` (int) Creation timestamp, e.g., 1705395332
  146. - `event: error`
  147. 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.
  148. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  149. - `message_id` (string) Unique message ID
  150. - `status` (int) HTTP status code
  151. - `code` (string) Error code
  152. - `message` (string) Error message
  153. - `event: ping` Ping event every 10 seconds to keep the connection alive.
  154. ### Errors
  155. - 404, Conversation does not exists
  156. - 400, `invalid_param`, abnormal parameter input
  157. - 400, `app_unavailable`, App configuration unavailable
  158. - 400, `provider_not_initialize`, no available model credential configuration
  159. - 400, `provider_quota_exceeded`, model invocation quota insufficient
  160. - 400, `model_currently_not_support`, current model unavailable
  161. - 400, `completion_request_error`, text generation failed
  162. - 500, internal server error
  163. </Col>
  164. <Col sticky>
  165. <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}'`}>
  166. ```bash {{ title: 'cURL' }}
  167. curl -X POST '${props.appDetail.api_base_url}/chat-messages' \
  168. --header 'Authorization: Bearer {api_key}' \
  169. --header 'Content-Type: application/json' \
  170. --data-raw '{
  171. "inputs": {},
  172. "query": "eh",
  173. "response_mode": "streaming",
  174. "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
  175. "user": "abc-123"
  176. }'
  177. ```
  178. </CodeGroup>
  179. ### Blocking Mode
  180. <CodeGroup title="Response">
  181. ```json {{ title: 'Response' }}
  182. {
  183. "event": "message",
  184. "task_id": "c3800678-a077-43df-a102-53f23ed20b88",
  185. "id": "9da23599-e713-473b-982c-4328d4f5c78a",
  186. "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  187. "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
  188. "mode": "chat",
  189. "answer": "iPhone 13 Pro Max specs are listed here:...",
  190. "metadata": {
  191. "usage": {
  192. "prompt_tokens": 1033,
  193. "prompt_unit_price": "0.001",
  194. "prompt_price_unit": "0.001",
  195. "prompt_price": "0.0010330",
  196. "completion_tokens": 128,
  197. "completion_unit_price": "0.002",
  198. "completion_price_unit": "0.001",
  199. "completion_price": "0.0002560",
  200. "total_tokens": 1161,
  201. "total_price": "0.0012890",
  202. "currency": "USD",
  203. "latency": 0.7682376249867957
  204. },
  205. "retriever_resources": [
  206. {
  207. "position": 1,
  208. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  209. "dataset_name": "iPhone",
  210. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  211. "document_name": "iPhone List",
  212. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  213. "score": 0.98457545,
  214. "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\""
  215. }
  216. ]
  217. },
  218. "created_at": 1705407629
  219. }
  220. ```
  221. </CodeGroup>
  222. ### Streaming Mode ( Basic Assistant )
  223. <CodeGroup title="Response">
  224. ```streaming {{ title: 'Response' }}
  225. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  226. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  227. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  228. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  229. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  230. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  231. 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\""}]}}
  232. 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"}
  233. 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": ""}
  234. ```
  235. </CodeGroup>
  236. ### Response Example(Agent Assistant)
  237. <CodeGroup title="Response">
  238. ```streaming {{ title: 'Response' }}
  239. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  240. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  241. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  242. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  243. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  244. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  245. 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\""}]}}
  246. 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"}
  247. 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": ""}
  248. ```
  249. </CodeGroup>
  250. </Col>
  251. </Row>
  252. ---
  253. <Heading
  254. url='/files/upload'
  255. method='POST'
  256. title='File Upload'
  257. name='#file-upload'
  258. />
  259. <Row>
  260. <Col>
  261. Upload a file (currently only images are supported) for use when sending messages, enabling multimodal understanding of images and text.
  262. Supports png, jpg, jpeg, webp, gif formats.
  263. Uploaded files are for use by the current end-user only.
  264. ### Request Body
  265. This interface requires a `multipart/form-data` request.
  266. - `file` (File) Required
  267. The file to be uploaded.
  268. - `user` (string) Required
  269. User identifier, defined by the developer's rules, must be unique within the application.
  270. ### Response
  271. After a successful upload, the server will return the file's ID and related information.
  272. - `id` (uuid) ID
  273. - `name` (string) File name
  274. - `size` (int) File size (bytes)
  275. - `extension` (string) File extension
  276. - `mime_type` (string) File mime-type
  277. - `created_by` (uuid) End-user ID
  278. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  279. ### Errors
  280. - 400, `no_file_uploaded`, a file must be provided
  281. - 400, `too_many_files`, currently only one file is accepted
  282. - 400, `unsupported_preview`, the file does not support preview
  283. - 400, `unsupported_estimate`, the file does not support estimation
  284. - 413, `file_too_large`, the file is too large
  285. - 415, `unsupported_file_type`, unsupported extension, currently only document files are accepted
  286. - 503, `s3_connection_failed`, unable to connect to S3 service
  287. - 503, `s3_permission_denied`, no permission to upload files to S3
  288. - 503, `s3_file_too_large`, file exceeds S3 size limit
  289. - 500, internal server error
  290. </Col>
  291. <Col sticky>
  292. ### Request Example
  293. <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'`}>
  294. ```bash {{ title: 'cURL' }}
  295. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  296. --header 'Authorization: Bearer {api_key}' \
  297. --form 'file=@"/path/to/file"'
  298. ```
  299. </CodeGroup>
  300. ### Response Example
  301. <CodeGroup title="Response">
  302. ```json {{ title: 'Response' }}
  303. {
  304. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  305. "name": "example.png",
  306. "size": 1024,
  307. "extension": "png",
  308. "mime_type": "image/png",
  309. "created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
  310. "created_at": 1577836800,
  311. }
  312. ```
  313. </CodeGroup>
  314. </Col>
  315. </Row>
  316. ---
  317. <Heading
  318. url='/chat-messages/:task_id/stop'
  319. method='POST'
  320. title='Stop Generate'
  321. name='#stop-generatebacks'
  322. />
  323. <Row>
  324. <Col>
  325. Only supported in streaming mode.
  326. ### Path
  327. - `task_id` (string) Task ID, can be obtained from the streaming chunk return
  328. ### Request Body
  329. - `user` (string) Required
  330. User identifier, used to define the identity of the end-user, must be consistent with the user passed in the send message interface.
  331. ### Response
  332. - `result` (string) Always returns "success"
  333. </Col>
  334. <Col sticky>
  335. ### Request Example
  336. <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"}'`}>
  337. ```bash {{ title: 'cURL' }}
  338. curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \
  339. -H 'Authorization: Bearer {api_key}' \
  340. -H 'Content-Type: application/json' \
  341. --data-raw '{
  342. "user": "abc-123"
  343. }'
  344. ```
  345. </CodeGroup>
  346. ### Response Example
  347. <CodeGroup title="Response">
  348. ```json {{ title: 'Response' }}
  349. {
  350. "result": "success"
  351. }
  352. ```
  353. </CodeGroup>
  354. </Col>
  355. </Row>
  356. ---
  357. <Heading
  358. url='/messages/:message_id/feedbacks'
  359. method='POST'
  360. title='Message Feedback'
  361. name='#feedbacks'
  362. />
  363. <Row>
  364. <Col>
  365. End-users can provide feedback messages, facilitating application developers to optimize expected outputs.
  366. ### Path
  367. <Properties>
  368. <Property name='message_id' type='string' key='message_id'>
  369. Message ID
  370. </Property>
  371. </Properties>
  372. ### Request Body
  373. <Properties>
  374. <Property name='rating' type='string' key='rating'>
  375. Upvote as `like`, downvote as `dislike`, revoke upvote as `null`
  376. </Property>
  377. <Property name='user' type='string' key='user'>
  378. User identifier, defined by the developer's rules, must be unique within the application.
  379. </Property>
  380. <Property name='content' type='string' key='content'>
  381. The specific content of message feedback.
  382. </Property>
  383. </Properties>
  384. ### Response
  385. - `result` (string) Always returns "success"
  386. </Col>
  387. <Col sticky>
  388. <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 "content": "message feedback information"\n}'`}>
  389. ```bash {{ title: 'cURL' }}
  390. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  391. --header 'Authorization: Bearer {api_key}' \
  392. --header 'Content-Type: application/json' \
  393. --data-raw '{
  394. "rating": "like",
  395. "user": "abc-123",
  396. "content": "message feedback information"
  397. }'
  398. ```
  399. </CodeGroup>
  400. <CodeGroup title="Response">
  401. ```json {{ title: 'Response' }}
  402. {
  403. "result": "success"
  404. }
  405. ```
  406. </CodeGroup>
  407. </Col>
  408. </Row>
  409. ---
  410. <Heading
  411. url='/app/feedbacks'
  412. method='GET'
  413. title='Get feedbacks of application'
  414. name='#app-feedbacks'
  415. />
  416. <Row>
  417. <Col>
  418. Get application's feedbacks.
  419. ### Query
  420. <Properties>
  421. <Property name='page' type='string' key='page'>
  422. (optional)pagination,default:1
  423. </Property>
  424. </Properties>
  425. <Properties>
  426. <Property name='limit' type='string' key='limit'>
  427. (optional) records per page default:20
  428. </Property>
  429. </Properties>
  430. ### Response
  431. - `data` (List) return apps feedback list.
  432. </Col>
  433. <Col sticky>
  434. <CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
  435. ```bash {{ title: 'cURL' }}
  436. curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
  437. --header 'Authorization: Bearer {api_key}' \
  438. --header 'Content-Type: application/json'
  439. ```
  440. </CodeGroup>
  441. <CodeGroup title="Response">
  442. ```json {{ title: 'Response' }}
  443. {
  444. "data": [
  445. {
  446. "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
  447. "app_id": "f252d396-fe48-450e-94ec-e184218e7346",
  448. "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
  449. "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
  450. "rating": "like",
  451. "content": "message feedback information-3",
  452. "from_source": "user",
  453. "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
  454. "from_account_id": null,
  455. "created_at": "2025-04-24T09:24:38",
  456. "updated_at": "2025-04-24T09:24:38"
  457. }
  458. ]
  459. }
  460. ```
  461. </CodeGroup>
  462. </Col>
  463. </Row>
  464. ---
  465. <Heading
  466. url='/messages/{message_id}/suggested'
  467. method='GET'
  468. title='Next Suggested Questions'
  469. name='#suggested'
  470. />
  471. <Row>
  472. <Col>
  473. Get next questions suggestions for the current message
  474. ### Path Params
  475. <Properties>
  476. <Property name='message_id' type='string' key='message_id'>
  477. Message ID
  478. </Property>
  479. </Properties>
  480. ### Query
  481. <Properties>
  482. <Property name='user' type='string' key='user'>
  483. User identifier, used to define the identity of the end-user for retrieval and statistics.
  484. Should be uniquely defined by the developer within the application.
  485. </Property>
  486. </Properties>
  487. </Col>
  488. <Col sticky>
  489. <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'`}>
  490. ```bash {{ title: 'cURL' }}
  491. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
  492. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  493. --header 'Content-Type: application/json' \
  494. ```
  495. </CodeGroup>
  496. <CodeGroup title="Response">
  497. ```json {{ title: 'Response' }}
  498. {
  499. "result": "success",
  500. "data": [
  501. "a",
  502. "b",
  503. "c"
  504. ]
  505. }
  506. ```
  507. </CodeGroup>
  508. </Col>
  509. </Row>
  510. ---
  511. <Heading
  512. url='/messages'
  513. method='GET'
  514. title='Get Conversation History Messages'
  515. name='#messages'
  516. />
  517. <Row>
  518. <Col>
  519. Returns historical chat records in a scrolling load format, with the first page returning the latest `{limit}` messages, i.e., in reverse order.
  520. ### Query
  521. <Properties>
  522. <Property name='conversation_id' type='string' key='conversation_id'>
  523. Conversation ID
  524. </Property>
  525. <Property name='user' type='string' key='user'>
  526. User identifier, used to define the identity of the end-user for retrieval and statistics.
  527. Should be uniquely defined by the developer within the application.
  528. </Property>
  529. <Property name='first_id' type='string' key='first_id'>
  530. The ID of the first chat record on the current page, default is null.
  531. </Property>
  532. <Property name='limit' type='int' key='limit'>
  533. How many chat history messages to return in one request, default is 20.
  534. </Property>
  535. </Properties>
  536. ### Response
  537. - `data` (array[object]) Message list
  538. - `id` (string) Message ID
  539. - `conversation_id` (string) Conversation ID
  540. - `inputs` (object) User input parameters.
  541. - `query` (string) User input / question content.
  542. - `message_files` (array[object]) Message files
  543. - `id` (string) ID
  544. - `type` (string) File type, image for images
  545. - `url` (string) Preview image URL
  546. - `belongs_to` (string) belongs to,user or assistant
  547. - `agent_thoughts` (array[object]) Agent thought(Empty if it's a Basic Assistant)
  548. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  549. - `message_id` (string) Unique message ID
  550. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  551. - `thought` (string) What LLM is thinking about
  552. - `observation` (string) Response from tool calls
  553. - `tool` (string) A list of tools represents which tools are called,split by ;
  554. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  555. - `created_at` (int) Creation timestamp, e.g., 1705395332
  556. - `message_files` (array[string]) Refer to message_file event
  557. - `file_id` (string) File ID
  558. - `answer` (string) Response message content
  559. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  560. - `feedback` (object) Feedback information
  561. - `rating` (string) Upvote as `like` / Downvote as `dislike`
  562. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  563. - `has_more` (bool) Whether there is a next page
  564. - `limit` (int) Number of returned items, if input exceeds system limit, returns system limit amount
  565. </Col>
  566. <Col sticky>
  567. <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}'`}>
  568. ```bash {{ title: 'cURL' }}
  569. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  570. --header 'Authorization: Bearer {api_key}'
  571. ```
  572. </CodeGroup>
  573. ### Response Example (Basic Assistant)
  574. <CodeGroup title="Response">
  575. ```json {{ title: 'Response' }}
  576. {
  577. "limit": 20,
  578. "has_more": false,
  579. "data": [
  580. {
  581. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  582. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  583. "inputs": {
  584. "name": "dify"
  585. },
  586. "query": "iphone 13 pro",
  587. "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.",
  588. "message_files": [],
  589. "feedback": null,
  590. "retriever_resources": [
  591. {
  592. "position": 1,
  593. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  594. "dataset_name": "iPhone",
  595. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  596. "document_name": "iPhone List",
  597. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  598. "score": 0.98457545,
  599. "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\""
  600. }
  601. ],
  602. "agent_thoughts": [],
  603. "created_at": 1705569239,
  604. }
  605. ]
  606. }
  607. ```
  608. </CodeGroup>
  609. ### Response Example (Agent Assistant)
  610. <CodeGroup title="Response">
  611. ```json {{ title: 'Response' }}
  612. {
  613. "limit": 20,
  614. "has_more": false,
  615. "data": [
  616. {
  617. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  618. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  619. "inputs": {},
  620. "query": "draw a cat",
  621. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  622. "message_files": [
  623. {
  624. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  625. "type": "image",
  626. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  627. "belongs_to": "assistant"
  628. }
  629. ],
  630. "feedback": null,
  631. "retriever_resources": [],
  632. "created_at": 1705988187,
  633. "agent_thoughts": [
  634. {
  635. "id": "592c84cf-07ee-441c-9dcc-ffc66c033469",
  636. "chain_id": null,
  637. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  638. "position": 1,
  639. "thought": "",
  640. "tool": "dalle2",
  641. "tool_input": "{\"dalle2\": {\"prompt\": \"cat\"}}",
  642. "created_at": 1705988186,
  643. "observation": "image has been created and sent to user already, you should tell user to check it now.",
  644. "files": [
  645. "976990d2-5294-47e6-8f14-7356ba9d2d76"
  646. ]
  647. },
  648. {
  649. "id": "73ead60d-2370-4780-b5ed-532d2762b0e5",
  650. "chain_id": null,
  651. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  652. "position": 2,
  653. "thought": "I have generated an image of a cat for you. Please check your messages to view the image.",
  654. "tool": "",
  655. "tool_input": "",
  656. "created_at": 1705988199,
  657. "observation": "",
  658. "files": []
  659. }
  660. ]
  661. }
  662. ]
  663. }
  664. ```
  665. </CodeGroup>
  666. </Col>
  667. </Row>
  668. ---
  669. <Heading
  670. url='/conversations'
  671. method='GET'
  672. title='Get Conversations'
  673. name='#conversations'
  674. />
  675. <Row>
  676. <Col>
  677. Retrieve the conversation list for the current user, defaulting to the most recent 20 entries.
  678. ### Query
  679. <Properties>
  680. <Property name='user' type='string' key='user'>
  681. User identifier, used to define the identity of the end-user for retrieval and statistics.
  682. Should be uniquely defined by the developer within the application.
  683. </Property>
  684. <Property name='last_id' type='string' key='last_id'>
  685. (Optional) The ID of the last record on the current page, default is null.
  686. </Property>
  687. <Property name='limit' type='int' key='limit'>
  688. (Optional) How many records to return in one request, default is the most recent 20 entries. Maximum 100, minimum 1.
  689. </Property>
  690. <Property name='sort_by' type='string' key='sort_by'>
  691. (Optional) Sorting Field, Default: -updated_at (sorted in descending order by update time)
  692. - Available Values: created_at, -created_at, updated_at, -updated_at
  693. - The symbol before the field represents the order or reverse, "-" represents reverse order.
  694. </Property>
  695. </Properties>
  696. ### Response
  697. - `data` (array[object]) List of conversations
  698. - `id` (string) Conversation ID
  699. - `name` (string) Conversation name, by default, is a snippet of the first question asked by the user in the conversation.
  700. - `inputs` (object) User input parameters.
  701. - `status` (string) Conversation status
  702. - `introduction` (string) Introduction
  703. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  704. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  705. - `has_more` (bool)
  706. - `limit` (int) Number of entries returned, if input exceeds system limit, system limit number is returned
  707. </Col>
  708. <Col sticky>
  709. <CodeGroup title="Request" tag="GET" label="/conversations" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \\\n --header 'Authorization: Bearer {api_key}'`}>
  710. ```bash {{ title: 'cURL' }}
  711. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  712. --header 'Authorization: Bearer {api_key}'
  713. ```
  714. </CodeGroup>
  715. <CodeGroup title="Response">
  716. ```json {{ title: 'Response' }}
  717. {
  718. "limit": 20,
  719. "has_more": false,
  720. "data": [
  721. {
  722. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  723. "name": "New chat",
  724. "inputs": {
  725. "book": "book",
  726. "myName": "Lucy"
  727. },
  728. "status": "normal",
  729. "created_at": 1679667915,
  730. "updated_at": 1679667915
  731. },
  732. {
  733. "id": "hSIhXBhNe8X1d8Et"
  734. // ...
  735. }
  736. ]
  737. }
  738. ```
  739. </CodeGroup>
  740. </Col>
  741. </Row>
  742. ---
  743. <Heading
  744. url='/conversations/:conversation_id'
  745. method='DELETE'
  746. title='Delete Conversation'
  747. name='#delete'
  748. />
  749. <Row>
  750. <Col>
  751. Delete a conversation.
  752. ### Path
  753. - `conversation_id` (string) Conversation ID
  754. ### Request Body
  755. <Properties>
  756. <Property name='user' type='string' key='user'>
  757. The user identifier, defined by the developer, must ensure uniqueness within the application.
  758. </Property>
  759. </Properties>
  760. ### Response
  761. - `result` (string) Always returns "success"
  762. </Col>
  763. <Col sticky>
  764. <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}'`}>
  765. ```bash {{ title: 'cURL' }}
  766. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  767. --header 'Content-Type: application/json' \
  768. --header 'Accept: application/json' \
  769. --header 'Authorization: Bearer {api_key}' \
  770. --data '{
  771. "user": "abc-123"
  772. }'
  773. ```
  774. </CodeGroup>
  775. <CodeGroup title="Response">
  776. ```text {{ title: 'Response' }}
  777. 204 No Content
  778. ```
  779. </CodeGroup>
  780. </Col>
  781. </Row>
  782. ---
  783. <Heading
  784. url='/conversations/:conversation_id/name'
  785. method='POST'
  786. title='Conversation Rename'
  787. name='#rename'
  788. />
  789. <Row>
  790. <Col>
  791. ### Request Body
  792. Rename the session, the session name is used for display on clients that support multiple sessions.
  793. ### Path
  794. - `conversation_id` (string) Conversation ID
  795. <Properties>
  796. <Property name='name' type='string' key='name'>
  797. (Optional) The name of the conversation. This parameter can be omitted if `auto_generate` is set to `true`.
  798. </Property>
  799. <Property name='auto_generate' type='bool' key='auto_generate'>
  800. (Optional) Automatically generate the title, default is `false`
  801. </Property>
  802. <Property name='user' type='string' key='user'>
  803. The user identifier, defined by the developer, must ensure uniqueness within the application.
  804. </Property>
  805. </Properties>
  806. ### Response
  807. - `id` (string) Conversation ID
  808. - `name` (string) Conversation name
  809. - `inputs` (object) User input parameters
  810. - `status` (string) Conversation status
  811. - `introduction` (string) Introduction
  812. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  813. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  814. </Col>
  815. <Col sticky>
  816. <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}'`}>
  817. ```bash {{ title: 'cURL' }}
  818. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  819. --header 'Content-Type: application/json' \
  820. --header 'Authorization: Bearer {api_key}' \
  821. --data-raw '{
  822. "name": "",
  823. "auto_generate": true,
  824. "user": "abc-123"
  825. }'
  826. ```
  827. </CodeGroup>
  828. <CodeGroup title="Response">
  829. ```json {{ title: 'Response' }}
  830. {
  831. "id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  832. "name": "Chat vs AI",
  833. "inputs": {},
  834. "status": "normal",
  835. "introduction": "",
  836. "created_at": 1705569238,
  837. "updated_at": 1705569238
  838. }
  839. ```
  840. </CodeGroup>
  841. </Col>
  842. </Row>
  843. ---
  844. <Heading
  845. url='/conversations/:conversation_id/variables'
  846. method='GET'
  847. title='Get Conversation Variables'
  848. name='#conversation-variables'
  849. />
  850. <Row>
  851. <Col>
  852. Retrieve variables from a specific conversation. This endpoint is useful for extracting structured data that was captured during the conversation.
  853. ### Path Parameters
  854. <Properties>
  855. <Property name='conversation_id' type='string' key='conversation_id'>
  856. The ID of the conversation to retrieve variables from.
  857. </Property>
  858. </Properties>
  859. ### Query Parameters
  860. <Properties>
  861. <Property name='user' type='string' key='user'>
  862. The user identifier, defined by the developer, must ensure uniqueness within the application
  863. </Property>
  864. <Property name='last_id' type='string' key='last_id'>
  865. (Optional) The ID of the last record on the current page, default is null.
  866. </Property>
  867. <Property name='limit' type='int' key='limit'>
  868. (Optional) How many records to return in one request, default is the most recent 20 entries. Maximum 100, minimum 1.
  869. </Property>
  870. </Properties>
  871. ### Response
  872. - `limit` (int) Number of items per page
  873. - `has_more` (bool) Whether there is a next page
  874. - `data` (array[object]) List of variables
  875. - `id` (string) Variable ID
  876. - `name` (string) Variable name
  877. - `value_type` (string) Variable type (string, number, object, etc.)
  878. - `value` (string) Variable value
  879. - `description` (string) Variable description
  880. - `created_at` (int) Creation timestamp
  881. - `updated_at` (int) Last update timestamp
  882. ### Errors
  883. - 404, `conversation_not_exists`, Conversation not found
  884. </Col>
  885. <Col sticky>
  886. <CodeGroup title="Request" tag="GET" label="/conversations/:conversation_id/variables" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123' \\\n--header 'Authorization: Bearer {api_key}'`}>
  887. ```bash {{ title: 'cURL' }}
  888. curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123' \
  889. --header 'Authorization: Bearer {api_key}'
  890. ```
  891. </CodeGroup>
  892. <CodeGroup title="Request with variable name filter">
  893. ```bash {{ title: 'cURL' }}
  894. curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123&variable_name=customer_name' \
  895. --header 'Authorization: Bearer {api_key}'
  896. ```
  897. </CodeGroup>
  898. <CodeGroup title="Response">
  899. ```json {{ title: 'Response' }}
  900. {
  901. "limit": 100,
  902. "has_more": false,
  903. "data": [
  904. {
  905. "id": "variable-uuid-1",
  906. "name": "customer_name",
  907. "value_type": "string",
  908. "value": "John Doe",
  909. "description": "Customer name extracted from the conversation",
  910. "created_at": 1650000000000,
  911. "updated_at": 1650000000000
  912. },
  913. {
  914. "id": "variable-uuid-2",
  915. "name": "order_details",
  916. "value_type": "json",
  917. "value": "{\"product\":\"Widget\",\"quantity\":5,\"price\":19.99}",
  918. "description": "Order details from the customer",
  919. "created_at": 1650000000000,
  920. "updated_at": 1650000000000
  921. }
  922. ]
  923. }
  924. ```
  925. </CodeGroup>
  926. </Col>
  927. </Row>
  928. ---
  929. <Heading
  930. url='/audio-to-text'
  931. method='POST'
  932. title='Speech to Text'
  933. name='#audio'
  934. />
  935. <Row>
  936. <Col>
  937. This endpoint requires a multipart/form-data request.
  938. ### Request Body
  939. <Properties>
  940. <Property name='file' type='file' key='file'>
  941. Audio file.
  942. Supported formats: `['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  943. File size limit: 15MB
  944. </Property>
  945. <Property name='user' type='string' key='user'>
  946. User identifier, defined by the developer's rules, must be unique within the application.
  947. </Property>
  948. </Properties>
  949. ### Response
  950. - `text` (string) Output text
  951. </Col>
  952. <Col sticky>
  953. <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]'`}>
  954. ```bash {{ title: 'cURL' }}
  955. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  956. --header 'Authorization: Bearer {api_key}' \
  957. --form 'file=@localfile;type=audio/mp3'
  958. ```
  959. </CodeGroup>
  960. <CodeGroup title="Response">
  961. ```json {{ title: 'Response' }}
  962. {
  963. "text": ""
  964. }
  965. ```
  966. </CodeGroup>
  967. </Col>
  968. </Row>
  969. ---
  970. <Heading
  971. url='/text-to-audio'
  972. method='POST'
  973. title='Text to Audio'
  974. name='#audio'
  975. />
  976. <Row>
  977. <Col>
  978. Text to speech.
  979. ### Request Body
  980. <Properties>
  981. <Property name='message_id' type='str' key='message_id'>
  982. 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.
  983. </Property>
  984. <Property name='text' type='str' key='text'>
  985. Speech generated content。
  986. </Property>
  987. <Property name='user' type='string' key='user'>
  988. The user identifier, defined by the developer, must ensure uniqueness within the app.
  989. </Property>
  990. </Properties>
  991. </Col>
  992. <Col sticky>
  993. <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`}>
  994. ```bash {{ title: 'cURL' }}
  995. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  996. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  997. --form 'file=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290'
  998. ```
  999. </CodeGroup>
  1000. <CodeGroup title="headers">
  1001. ```json {{ title: 'headers' }}
  1002. {
  1003. "Content-Type": "audio/wav"
  1004. }
  1005. ```
  1006. </CodeGroup>
  1007. </Col>
  1008. </Row>
  1009. ---
  1010. <Heading
  1011. url='/info'
  1012. method='GET'
  1013. title='Get Application Basic Information'
  1014. name='#info'
  1015. />
  1016. <Row>
  1017. <Col>
  1018. Used to get basic information about this application
  1019. ### Response
  1020. - `name` (string) application name
  1021. - `description` (string) application description
  1022. - `tags` (array[string]) application tags
  1023. - `mode` (string) application mode
  1024. - `author_name` (string) application author name
  1025. </Col>
  1026. <Col>
  1027. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1028. ```bash {{ title: 'cURL' }}
  1029. curl -X GET '${props.appDetail.api_base_url}/info' \
  1030. -H 'Authorization: Bearer {api_key}'
  1031. ```
  1032. </CodeGroup>
  1033. <CodeGroup title="Response">
  1034. ```json {{ title: 'Response' }}
  1035. {
  1036. "name": "My App",
  1037. "description": "This is my app.",
  1038. "tags": [
  1039. "tag1",
  1040. "tag2"
  1041. ],
  1042. "mode": "advanced-chat",
  1043. "author_name": "Dify"
  1044. }
  1045. ```
  1046. </CodeGroup>
  1047. </Col>
  1048. </Row>
  1049. ---
  1050. <Heading
  1051. url='/parameters'
  1052. method='GET'
  1053. title='Get Application Parameters Information'
  1054. name='#parameters'
  1055. />
  1056. <Row>
  1057. <Col>
  1058. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  1059. ### Query
  1060. <Properties>
  1061. <Property name='user' type='string' key='user'>
  1062. User identifier, defined by the developer's rules, must be unique within the application.
  1063. </Property>
  1064. </Properties>
  1065. ### Response
  1066. - `opening_statement` (string) Opening statement
  1067. - `suggested_questions` (array[string]) List of suggested questions for the opening
  1068. - `suggested_questions_after_answer` (object) Suggest questions after enabling the answer.
  1069. - `enabled` (bool) Whether it is enabled
  1070. - `speech_to_text` (object) Speech to text
  1071. - `enabled` (bool) Whether it is enabled
  1072. - `text_to_speech` (object) Text to speech
  1073. - `enabled` (bool) Whether it is enabled
  1074. - `voice` (string) Voice type
  1075. - `language` (string) Language
  1076. - `autoPlay` (string) Auto play
  1077. - `enabled` Enabled
  1078. - `disabled` Disabled
  1079. - `retriever_resource` (object) Citation and Attribution
  1080. - `enabled` (bool) Whether it is enabled
  1081. - `annotation_reply` (object) Annotation reply
  1082. - `enabled` (bool) Whether it is enabled
  1083. - `user_input_form` (array[object]) User input form configuration
  1084. - `text-input` (object) Text input control
  1085. - `label` (string) Variable display label name
  1086. - `variable` (string) Variable ID
  1087. - `required` (bool) Whether it is required
  1088. - `default` (string) Default value
  1089. - `paragraph` (object) Paragraph text input control
  1090. - `label` (string) Variable display label name
  1091. - `variable` (string) Variable ID
  1092. - `required` (bool) Whether it is required
  1093. - `default` (string) Default value
  1094. - `select` (object) Dropdown control
  1095. - `label` (string) Variable display label name
  1096. - `variable` (string) Variable ID
  1097. - `required` (bool) Whether it is required
  1098. - `default` (string) Default value
  1099. - `options` (array[string]) Option values
  1100. - `file_upload` (object) File upload configuration
  1101. - `image` (object) Image settings
  1102. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`
  1103. - `enabled` (bool) Whether it is enabled
  1104. - `number_limits` (int) Image number limit, default is 3
  1105. - `transfer_methods` (array[string]) List of transfer methods, remote_url, local_file, must choose one
  1106. - `system_parameters` (object) System parameters
  1107. - `file_size_limit` (int) Document upload size limit (MB)
  1108. - `image_file_size_limit` (int) Image file upload size limit (MB)
  1109. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  1110. - `video_file_size_limit` (int) Video file upload size limit (MB)
  1111. </Col>
  1112. <Col sticky>
  1113. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  1114. ```bash {{ title: 'cURL' }}
  1115. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  1116. --header 'Authorization: Bearer {api_key}'
  1117. ```
  1118. </CodeGroup>
  1119. <CodeGroup title="Response">
  1120. ```json {{ title: 'Response' }}
  1121. {
  1122. "opening_statement": "Hello!",
  1123. "suggested_questions_after_answer": {
  1124. "enabled": true
  1125. },
  1126. "speech_to_text": {
  1127. "enabled": true
  1128. },
  1129. "text_to_speech": {
  1130. "enabled": true,
  1131. "voice": "sambert-zhinan-v1",
  1132. "language": "zh-Hans",
  1133. "autoPlay": "disabled"
  1134. },
  1135. "retriever_resource": {
  1136. "enabled": true
  1137. },
  1138. "annotation_reply": {
  1139. "enabled": true
  1140. },
  1141. "user_input_form": [
  1142. {
  1143. "paragraph": {
  1144. "label": "Query",
  1145. "variable": "query",
  1146. "required": true,
  1147. "default": ""
  1148. }
  1149. }
  1150. ],
  1151. "file_upload": {
  1152. "image": {
  1153. "enabled": false,
  1154. "number_limits": 3,
  1155. "detail": "high",
  1156. "transfer_methods": [
  1157. "remote_url",
  1158. "local_file"
  1159. ]
  1160. }
  1161. },
  1162. "system_parameters": {
  1163. "file_size_limit": 15,
  1164. "image_file_size_limit": 10,
  1165. "audio_file_size_limit": 50,
  1166. "video_file_size_limit": 100
  1167. }
  1168. }
  1169. ```
  1170. </CodeGroup>
  1171. </Col>
  1172. </Row>
  1173. ---
  1174. <Heading
  1175. url='/meta'
  1176. method='GET'
  1177. title='Get Application Meta Information'
  1178. name='#meta'
  1179. />
  1180. <Row>
  1181. <Col>
  1182. Used to get icons of tools in this application
  1183. ### Response
  1184. - `tool_icons`(object[string]) tool icons
  1185. - `tool_name` (string)
  1186. - `icon` (object|string)
  1187. - (object) icon object
  1188. - `background` (string) background color in hex format
  1189. - `content`(string) emoji
  1190. - (string) url of icon
  1191. </Col>
  1192. <Col>
  1193. <CodeGroup title="Request" tag="GET" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1194. ```bash {{ title: 'cURL' }}
  1195. curl -X GET '${props.appDetail.api_base_url}/meta' \
  1196. -H 'Authorization: Bearer {api_key}'
  1197. ```
  1198. </CodeGroup>
  1199. <CodeGroup title="Response">
  1200. ```json {{ title: 'Response' }}
  1201. {
  1202. "tool_icons": {
  1203. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1204. "api_tool": {
  1205. "background": "#252525",
  1206. "content": "\ud83d\ude01"
  1207. }
  1208. }
  1209. }
  1210. ```
  1211. </CodeGroup>
  1212. </Col>
  1213. </Row>
  1214. ---
  1215. <Heading
  1216. url='/site'
  1217. method='GET'
  1218. title='Get Application WebApp Settings'
  1219. name='#site'
  1220. />
  1221. <Row>
  1222. <Col>
  1223. Used to get the WebApp settings of the application.
  1224. ### Response
  1225. - `title` (string) WebApp name
  1226. - `chat_color_theme` (string) Chat color theme, in hex format
  1227. - `chat_color_theme_inverted` (bool) Whether the chat color theme is inverted
  1228. - `icon_type` (string) Icon type, `emoji` - emoji, `image` - picture
  1229. - `icon` (string) Icon. If it's `emoji` type, it's an emoji symbol; if it's `image` type, it's an image URL
  1230. - `icon_background` (string) Background color in hex format
  1231. - `icon_url` (string) Icon URL
  1232. - `description` (string) Description
  1233. - `copyright` (string) Copyright information
  1234. - `privacy_policy` (string) Privacy policy link
  1235. - `custom_disclaimer` (string) Custom disclaimer
  1236. - `default_language` (string) Default language
  1237. - `show_workflow_steps` (bool) Whether to show workflow details
  1238. - `use_icon_as_answer_icon` (bool) Whether to replace 🤖 in chat with the WebApp icon
  1239. </Col>
  1240. <Col>
  1241. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1242. ```bash {{ title: 'cURL' }}
  1243. curl -X GET '${props.appDetail.api_base_url}/site' \
  1244. -H 'Authorization: Bearer {api_key}'
  1245. ```
  1246. </CodeGroup>
  1247. <CodeGroup title="Response">
  1248. ```json {{ title: 'Response' }}
  1249. {
  1250. "title": "My App",
  1251. "chat_color_theme": "#ff4a4a",
  1252. "chat_color_theme_inverted": false,
  1253. "icon_type": "emoji",
  1254. "icon": "😄",
  1255. "icon_background": "#FFEAD5",
  1256. "icon_url": null,
  1257. "description": "This is my app.",
  1258. "copyright": "all rights reserved",
  1259. "privacy_policy": "",
  1260. "custom_disclaimer": "All generated by AI",
  1261. "default_language": "en-US",
  1262. "show_workflow_steps": false,
  1263. "use_icon_as_answer_icon": false,
  1264. }
  1265. ```
  1266. </CodeGroup>
  1267. </Col>
  1268. </Row>
  1269. ___
  1270. <Heading
  1271. url='/apps/annotations'
  1272. method='GET'
  1273. title='Get Annotation List'
  1274. name='#annotation_list'
  1275. />
  1276. <Row>
  1277. <Col>
  1278. ### Query
  1279. <Properties>
  1280. <Property name='page' type='string' key='page'>
  1281. Page number
  1282. </Property>
  1283. <Property name='limit' type='string' key='limit'>
  1284. Number of items returned, default 20, range 1-100
  1285. </Property>
  1286. </Properties>
  1287. </Col>
  1288. <Col sticky>
  1289. <CodeGroup
  1290. title="Request"
  1291. tag="GET"
  1292. label="/apps/annotations"
  1293. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  1294. >
  1295. ```bash {{ title: 'cURL' }}
  1296. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  1297. --header 'Authorization: Bearer {api_key}'
  1298. ```
  1299. </CodeGroup>
  1300. <CodeGroup title="Response">
  1301. ```json {{ title: 'Response' }}
  1302. {
  1303. "data": [
  1304. {
  1305. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1306. "question": "What is your name?",
  1307. "answer": "I am Dify.",
  1308. "hit_count": 0,
  1309. "created_at": 1735625869
  1310. }
  1311. ],
  1312. "has_more": false,
  1313. "limit": 20,
  1314. "total": 1,
  1315. "page": 1
  1316. }
  1317. ```
  1318. </CodeGroup>
  1319. </Col>
  1320. </Row>
  1321. ---
  1322. <Heading
  1323. url='/apps/annotations'
  1324. method='POST'
  1325. title='Create Annotation'
  1326. name='#create_annotation'
  1327. />
  1328. <Row>
  1329. <Col>
  1330. ### Query
  1331. <Properties>
  1332. <Property name='question' type='string' key='question'>
  1333. Question
  1334. </Property>
  1335. <Property name='answer' type='string' key='answer'>
  1336. Answer
  1337. </Property>
  1338. </Properties>
  1339. </Col>
  1340. <Col sticky>
  1341. <CodeGroup
  1342. title="Request"
  1343. tag="POST"
  1344. label="/apps/annotations"
  1345. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"question": "What is your name?","answer": "I am Dify."}'`}
  1346. >
  1347. ```bash {{ title: 'cURL' }}
  1348. curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \
  1349. --header 'Authorization: Bearer {api_key}' \
  1350. --header 'Content-Type: application/json' \
  1351. --data-raw '{
  1352. "question": "What is your name?",
  1353. "answer": "I am Dify."
  1354. }'
  1355. ```
  1356. </CodeGroup>
  1357. <CodeGroup title="Response">
  1358. ```json {{ title: 'Response' }}
  1359. {
  1360. {
  1361. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1362. "question": "What is your name?",
  1363. "answer": "I am Dify.",
  1364. "hit_count": 0,
  1365. "created_at": 1735625869
  1366. }
  1367. }
  1368. ```
  1369. </CodeGroup>
  1370. </Col>
  1371. </Row>
  1372. ---
  1373. <Heading
  1374. url='/apps/annotations/{annotation_id}'
  1375. method='PUT'
  1376. title='Update Annotation'
  1377. name='#update_annotation'
  1378. />
  1379. <Row>
  1380. <Col>
  1381. ### Query
  1382. <Properties>
  1383. <Property name='annotation_id' type='string' key='annotation_id'>
  1384. Annotation ID
  1385. </Property>
  1386. <Property name='question' type='string' key='question'>
  1387. Question
  1388. </Property>
  1389. <Property name='answer' type='string' key='answer'>
  1390. Answer
  1391. </Property>
  1392. </Properties>
  1393. </Col>
  1394. <Col sticky>
  1395. <CodeGroup
  1396. title="Request"
  1397. tag="PUT"
  1398. label="/apps/annotations/{annotation_id}"
  1399. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"question": "What is your name?","answer": "I am Dify."}'`}
  1400. >
  1401. ```bash {{ title: 'cURL' }}
  1402. curl --location --request POST '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1403. --header 'Authorization: Bearer {api_key}' \
  1404. --header 'Content-Type: application/json' \
  1405. --data-raw '{
  1406. "question": "What is your name?",
  1407. "answer": "I am Dify."
  1408. }'
  1409. ```
  1410. </CodeGroup>
  1411. <CodeGroup title="Response">
  1412. ```json {{ title: 'Response' }}
  1413. {
  1414. {
  1415. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1416. "question": "What is your name?",
  1417. "answer": "I am Dify.",
  1418. "hit_count": 0,
  1419. "created_at": 1735625869
  1420. }
  1421. }
  1422. ```
  1423. </CodeGroup>
  1424. </Col>
  1425. </Row>
  1426. ---
  1427. <Heading
  1428. url='/apps/annotations/{annotation_id}'
  1429. method='DELETE'
  1430. title='Delete Annotation'
  1431. name='#delete_annotation'
  1432. />
  1433. <Row>
  1434. <Col>
  1435. ### Query
  1436. <Properties>
  1437. <Property name='annotation_id' type='string' key='annotation_id'>
  1438. Annotation ID
  1439. </Property>
  1440. </Properties>
  1441. </Col>
  1442. <Col sticky>
  1443. <CodeGroup
  1444. title="Request"
  1445. tag="PUT"
  1446. label="/apps/annotations/{annotation_id}"
  1447. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  1448. >
  1449. ```bash {{ title: 'cURL' }}
  1450. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1451. --header 'Authorization: Bearer {api_key}'
  1452. ```
  1453. </CodeGroup>
  1454. <CodeGroup title="Response">
  1455. ```text {{ title: 'Response' }}
  1456. 204 No Content
  1457. ```
  1458. </CodeGroup>
  1459. </Col>
  1460. </Row>
  1461. ---
  1462. <Heading
  1463. url='/apps/annotation-reply/{action}'
  1464. method='POST'
  1465. title='Initial Annotation Reply Settings'
  1466. name='#initial_annotation_reply_settings'
  1467. />
  1468. <Row>
  1469. <Col>
  1470. ### Query
  1471. <Properties>
  1472. <Property name='action' type='string' key='action'>
  1473. Action, can only be 'enable' or 'disable'
  1474. </Property>
  1475. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  1476. Specified embedding model provider, must be set up in the system first, corresponding to the provider field(Optional)
  1477. </Property>
  1478. <Property name='embedding_model' type='string' key='embedding_model'>
  1479. Specified embedding model, corresponding to the model field(Optional)
  1480. </Property>
  1481. <Property name='score_threshold' type='number' key='score_threshold'>
  1482. The similarity threshold for matching annotated replies. Only annotations with scores above this threshold will be recalled.
  1483. </Property>
  1484. </Properties>
  1485. </Col>
  1486. <Col sticky>
  1487. The provider and model name of the embedding model can be obtained through the following interface: v1/workspaces/current/models/model-types/text-embedding. For specific instructions, see: Maintain Knowledge Base via API. The Authorization used is the Dataset API Token.
  1488. <CodeGroup
  1489. title="Request"
  1490. tag="POST"
  1491. label="/apps/annotation-reply/{action}"
  1492. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotation-reply/{action}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"score_threshold": 0.9, "embedding_provider_name": "zhipu", "embedding_model_name": "embedding_3"}'`}
  1493. >
  1494. ```bash {{ title: 'cURL' }}
  1495. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  1496. --header 'Authorization: Bearer {api_key}' \
  1497. --header 'Content-Type: application/json' \
  1498. --data-raw '{
  1499. "score_threshold": 0.9,
  1500. "embedding_provider_name": "zhipu",
  1501. "embedding_model_name": "embedding_3"
  1502. }'
  1503. ```
  1504. </CodeGroup>
  1505. <CodeGroup title="Response">
  1506. ```json {{ title: 'Response' }}
  1507. {
  1508. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1509. "job_status": "waiting"
  1510. }
  1511. ```
  1512. </CodeGroup>
  1513. This interface is executed asynchronously, so it will return a job_id. You can get the final execution result by querying the job status interface.
  1514. </Col>
  1515. </Row>
  1516. ---
  1517. <Heading
  1518. url='/apps/annotation-reply/{action}/status/{job_id}'
  1519. method='GET'
  1520. title='Query Initial Annotation Reply Settings Task Status'
  1521. name='#initial_annotation_reply_settings_task_status'
  1522. />
  1523. <Row>
  1524. <Col>
  1525. ### Query
  1526. <Properties>
  1527. <Property name='action' type='string' key='action'>
  1528. Action, can only be 'enable' or 'disable', must be the same as the action in the initial annotation reply settings interface
  1529. </Property>
  1530. <Property name='job_id' type='string' key='job_id'>
  1531. Job ID,
  1532. </Property>
  1533. </Properties>
  1534. </Col>
  1535. <Col sticky>
  1536. <CodeGroup
  1537. title="Request"
  1538. tag="GET"
  1539. label="/apps/annotations"
  1540. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1541. >
  1542. ```bash {{ title: 'cURL' }}
  1543. curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \
  1544. --header 'Authorization: Bearer {api_key}'
  1545. ```
  1546. </CodeGroup>
  1547. <CodeGroup title="Response">
  1548. ```json {{ title: 'Response' }}
  1549. {
  1550. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1551. "job_status": "waiting",
  1552. "error_msg": ""
  1553. }
  1554. ```
  1555. </CodeGroup>
  1556. </Col>
  1557. </Row>