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 70KB

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