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

template_advanced_chat.en.mdx 69KB

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