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

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