You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template_advanced_chat.en.mdx 67KB

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