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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  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='/audio-to-text'
  903. method='POST'
  904. title='Speech to Text'
  905. name='#audio'
  906. />
  907. <Row>
  908. <Col>
  909. This endpoint requires a multipart/form-data request.
  910. ### Request Body
  911. <Properties>
  912. <Property name='file' type='file' key='file'>
  913. Audio file.
  914. Supported formats: `['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  915. File size limit: 15MB
  916. </Property>
  917. <Property name='user' type='string' key='user'>
  918. User identifier, defined by the developer's rules, must be unique within the application.
  919. </Property>
  920. </Properties>
  921. ### Response
  922. - `text` (string) Output text
  923. </Col>
  924. <Col sticky>
  925. <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]'`}>
  926. ```bash {{ title: 'cURL' }}
  927. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  928. --header 'Authorization: Bearer {api_key}' \
  929. --form 'file=@localfile;type=audio/mp3'
  930. ```
  931. </CodeGroup>
  932. <CodeGroup title="Response">
  933. ```json {{ title: 'Response' }}
  934. {
  935. "text": ""
  936. }
  937. ```
  938. </CodeGroup>
  939. </Col>
  940. </Row>
  941. ---
  942. <Heading
  943. url='/text-to-audio'
  944. method='POST'
  945. title='Text to Audio'
  946. name='#audio'
  947. />
  948. <Row>
  949. <Col>
  950. Text to speech.
  951. ### Request Body
  952. <Properties>
  953. <Property name='message_id' type='str' key='message_id'>
  954. 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.
  955. </Property>
  956. <Property name='text' type='str' key='text'>
  957. Speech generated content。
  958. </Property>
  959. <Property name='user' type='string' key='user'>
  960. The user identifier, defined by the developer, must ensure uniqueness within the app.
  961. </Property>
  962. </Properties>
  963. </Col>
  964. <Col sticky>
  965. <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}'`}>
  966. ```bash {{ title: 'cURL' }}
  967. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  968. --header 'Authorization: Bearer {api_key}' \
  969. --header 'Content-Type: application/json' \
  970. --data-raw '{
  971. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  972. "text": "Hello Dify",
  973. "user": "abc-123",
  974. "streaming": false
  975. }'
  976. ```
  977. </CodeGroup>
  978. <CodeGroup title="headers">
  979. ```json {{ title: 'headers' }}
  980. {
  981. "Content-Type": "audio/wav"
  982. }
  983. ```
  984. </CodeGroup>
  985. </Col>
  986. </Row>
  987. ---
  988. <Heading
  989. url='/info'
  990. method='GET'
  991. title='Get Application Basic Information'
  992. name='#info'
  993. />
  994. <Row>
  995. <Col>
  996. Used to get basic information about this application
  997. ### Response
  998. - `name` (string) application name
  999. - `description` (string) application description
  1000. - `tags` (array[string]) application tags
  1001. - `mode` (string) application mode
  1002. - `author_name` (string) application author name
  1003. </Col>
  1004. <Col>
  1005. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1006. ```bash {{ title: 'cURL' }}
  1007. curl -X GET '${props.appDetail.api_base_url}/info' \
  1008. -H 'Authorization: Bearer {api_key}'
  1009. ```
  1010. </CodeGroup>
  1011. <CodeGroup title="Response">
  1012. ```json {{ title: 'Response' }}
  1013. {
  1014. "name": "My App",
  1015. "description": "This is my app.",
  1016. "tags": [
  1017. "tag1",
  1018. "tag2"
  1019. ],
  1020. "mode": "advanced-chat",
  1021. "author_name": "Dify"
  1022. }
  1023. ```
  1024. </CodeGroup>
  1025. </Col>
  1026. </Row>
  1027. ---
  1028. <Heading
  1029. url='/parameters'
  1030. method='GET'
  1031. title='Get Application Parameters Information'
  1032. name='#parameters'
  1033. />
  1034. <Row>
  1035. <Col>
  1036. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  1037. ### Response
  1038. - `opening_statement` (string) Opening statement
  1039. - `suggested_questions` (array[string]) List of suggested questions for the opening
  1040. - `suggested_questions_after_answer` (object) Suggest questions after enabling the answer.
  1041. - `enabled` (bool) Whether it is enabled
  1042. - `speech_to_text` (object) Speech to text
  1043. - `enabled` (bool) Whether it is enabled
  1044. - `text_to_speech` (object) Text to speech
  1045. - `enabled` (bool) Whether it is enabled
  1046. - `voice` (string) Voice type
  1047. - `language` (string) Language
  1048. - `autoPlay` (string) Auto play
  1049. - `enabled` Enabled
  1050. - `disabled` Disabled
  1051. - `retriever_resource` (object) Citation and Attribution
  1052. - `enabled` (bool) Whether it is enabled
  1053. - `annotation_reply` (object) Annotation reply
  1054. - `enabled` (bool) Whether it is enabled
  1055. - `user_input_form` (array[object]) User input form configuration
  1056. - `text-input` (object) Text input control
  1057. - `label` (string) Variable display label name
  1058. - `variable` (string) Variable ID
  1059. - `required` (bool) Whether it is required
  1060. - `default` (string) Default value
  1061. - `paragraph` (object) Paragraph text input control
  1062. - `label` (string) Variable display label name
  1063. - `variable` (string) Variable ID
  1064. - `required` (bool) Whether it is required
  1065. - `default` (string) Default value
  1066. - `select` (object) Dropdown control
  1067. - `label` (string) Variable display label name
  1068. - `variable` (string) Variable ID
  1069. - `required` (bool) Whether it is required
  1070. - `default` (string) Default value
  1071. - `options` (array[string]) Option values
  1072. - `file_upload` (object) File upload configuration
  1073. - `document` (object) Document settings
  1074. Currently only supports document types: `txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`.
  1075. - `enabled` (bool) Whether it is enabled
  1076. - `number_limits` (int) Document number limit, default is 3
  1077. - `transfer_methods` (array[string]) List of transfer methods: `remote_url`, `local_file`. Must choose one.
  1078. - `image` (object) Image settings
  1079. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`.
  1080. - `enabled` (bool) Whether it is enabled
  1081. - `number_limits` (int) Image number limit, default is 3
  1082. - `transfer_methods` (array[string]) List of transfer methods: `remote_url`, `local_file`. Must choose one.
  1083. - `audio` (object) Audio settings
  1084. Currently only supports audio types: `mp3`, `m4a`, `wav`, `webm`, `amr`.
  1085. - `enabled` (bool) Whether it is enabled
  1086. - `number_limits` (int) Audio number limit, default is 3
  1087. - `transfer_methods` (array[string]) List of transfer methods: `remote_url`, `local_file`. Must choose one.
  1088. - `video` (object) Video settings
  1089. Currently only supports video types: `mp4`, `mov`, `mpeg`, `mpga`.
  1090. - `enabled` (bool) Whether it is enabled
  1091. - `number_limits` (int) Video number limit, default is 3
  1092. - `transfer_methods` (array[string]) List of transfer methods: `remote_url`, `local_file`. Must choose one.
  1093. - `custom` (object) Custom settings
  1094. - `enabled` (bool) Whether it is enabled
  1095. - `number_limits` (int) Custom number limit, default is 3
  1096. - `transfer_methods` (array[string]) List of transfer methods: `remote_url`, `local_file`. Must choose one.
  1097. - `system_parameters` (object) System parameters
  1098. - `file_size_limit` (int) Document upload size limit (MB)
  1099. - `image_file_size_limit` (int) Image file upload size limit (MB)
  1100. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  1101. - `video_file_size_limit` (int) Video file upload size limit (MB)
  1102. </Col>
  1103. <Col sticky>
  1104. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  1105. ```bash {{ title: 'cURL' }}
  1106. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  1107. --header 'Authorization: Bearer {api_key}'
  1108. ```
  1109. </CodeGroup>
  1110. <CodeGroup title="Response">
  1111. ```json {{ title: 'Response' }}
  1112. {
  1113. "opening_statement": "Hello!",
  1114. "suggested_questions_after_answer": {
  1115. "enabled": true
  1116. },
  1117. "speech_to_text": {
  1118. "enabled": true
  1119. },
  1120. "text_to_speech": {
  1121. "enabled": true,
  1122. "voice": "sambert-zhinan-v1",
  1123. "language": "zh-Hans",
  1124. "autoPlay": "disabled"
  1125. },
  1126. "retriever_resource": {
  1127. "enabled": true
  1128. },
  1129. "annotation_reply": {
  1130. "enabled": true
  1131. },
  1132. "user_input_form": [
  1133. {
  1134. "paragraph": {
  1135. "label": "Query",
  1136. "variable": "query",
  1137. "required": true,
  1138. "default": ""
  1139. }
  1140. }
  1141. ],
  1142. "file_upload": {
  1143. "image": {
  1144. "enabled": false,
  1145. "number_limits": 3,
  1146. "detail": "high",
  1147. "transfer_methods": [
  1148. "remote_url",
  1149. "local_file"
  1150. ]
  1151. }
  1152. },
  1153. "system_parameters": {
  1154. "file_size_limit": 15,
  1155. "image_file_size_limit": 10,
  1156. "audio_file_size_limit": 50,
  1157. "video_file_size_limit": 100
  1158. }
  1159. }
  1160. ```
  1161. </CodeGroup>
  1162. </Col>
  1163. </Row>
  1164. ---
  1165. <Heading
  1166. url='/meta'
  1167. method='GET'
  1168. title='Get Application Meta Information'
  1169. name='#meta'
  1170. />
  1171. <Row>
  1172. <Col>
  1173. Used to get icons of tools in this application
  1174. ### Response
  1175. - `tool_icons`(object[string]) tool icons
  1176. - `tool_name` (string)
  1177. - `icon` (object|string)
  1178. - (object) icon object
  1179. - `background` (string) background color in hex format
  1180. - `content`(string) emoji
  1181. - (string) url of icon
  1182. </Col>
  1183. <Col>
  1184. <CodeGroup title="Request" tag="GET" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1185. ```bash {{ title: 'cURL' }}
  1186. curl -X GET '${props.appDetail.api_base_url}/meta' \
  1187. -H 'Authorization: Bearer {api_key}'
  1188. ```
  1189. </CodeGroup>
  1190. <CodeGroup title="Response">
  1191. ```json {{ title: 'Response' }}
  1192. {
  1193. "tool_icons": {
  1194. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1195. "api_tool": {
  1196. "background": "#252525",
  1197. "content": "\ud83d\ude01"
  1198. }
  1199. }
  1200. }
  1201. ```
  1202. </CodeGroup>
  1203. </Col>
  1204. </Row>
  1205. ---
  1206. <Heading
  1207. url='/site'
  1208. method='GET'
  1209. title='Get Application WebApp Settings'
  1210. name='#site'
  1211. />
  1212. <Row>
  1213. <Col>
  1214. Used to get the WebApp settings of the application.
  1215. ### Response
  1216. - `title` (string) WebApp name
  1217. - `chat_color_theme` (string) Chat color theme, in hex format
  1218. - `chat_color_theme_inverted` (bool) Whether the chat color theme is inverted
  1219. - `icon_type` (string) Icon type, `emoji` - emoji, `image` - picture
  1220. - `icon` (string) Icon. If it's `emoji` type, it's an emoji symbol; if it's `image` type, it's an image URL
  1221. - `icon_background` (string) Background color in hex format
  1222. - `icon_url` (string) Icon URL
  1223. - `description` (string) Description
  1224. - `copyright` (string) Copyright information
  1225. - `privacy_policy` (string) Privacy policy link
  1226. - `custom_disclaimer` (string) Custom disclaimer
  1227. - `default_language` (string) Default language
  1228. - `show_workflow_steps` (bool) Whether to show workflow details
  1229. - `use_icon_as_answer_icon` (bool) Whether to replace 🤖 in chat with the WebApp icon
  1230. </Col>
  1231. <Col>
  1232. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1233. ```bash {{ title: 'cURL' }}
  1234. curl -X GET '${props.appDetail.api_base_url}/site' \
  1235. -H 'Authorization: Bearer {api_key}'
  1236. ```
  1237. </CodeGroup>
  1238. <CodeGroup title="Response">
  1239. ```json {{ title: 'Response' }}
  1240. {
  1241. "title": "My App",
  1242. "chat_color_theme": "#ff4a4a",
  1243. "chat_color_theme_inverted": false,
  1244. "icon_type": "emoji",
  1245. "icon": "😄",
  1246. "icon_background": "#FFEAD5",
  1247. "icon_url": null,
  1248. "description": "This is my app.",
  1249. "copyright": "all rights reserved",
  1250. "privacy_policy": "",
  1251. "custom_disclaimer": "All generated by AI",
  1252. "default_language": "en-US",
  1253. "show_workflow_steps": false,
  1254. "use_icon_as_answer_icon": false,
  1255. }
  1256. ```
  1257. </CodeGroup>
  1258. </Col>
  1259. </Row>
  1260. ___
  1261. <Heading
  1262. url='/apps/annotations'
  1263. method='GET'
  1264. title='Get Annotation List'
  1265. name='#annotation_list'
  1266. />
  1267. <Row>
  1268. <Col>
  1269. ### Query
  1270. <Properties>
  1271. <Property name='page' type='string' key='page'>
  1272. Page number
  1273. </Property>
  1274. <Property name='limit' type='string' key='limit'>
  1275. Number of items returned, default 20, range 1-100
  1276. </Property>
  1277. </Properties>
  1278. </Col>
  1279. <Col sticky>
  1280. <CodeGroup
  1281. title="Request"
  1282. tag="GET"
  1283. label="/apps/annotations"
  1284. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  1285. >
  1286. ```bash {{ title: 'cURL' }}
  1287. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  1288. --header 'Authorization: Bearer {api_key}'
  1289. ```
  1290. </CodeGroup>
  1291. <CodeGroup title="Response">
  1292. ```json {{ title: 'Response' }}
  1293. {
  1294. "data": [
  1295. {
  1296. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1297. "question": "What is your name?",
  1298. "answer": "I am Dify.",
  1299. "hit_count": 0,
  1300. "created_at": 1735625869
  1301. }
  1302. ],
  1303. "has_more": false,
  1304. "limit": 20,
  1305. "total": 1,
  1306. "page": 1
  1307. }
  1308. ```
  1309. </CodeGroup>
  1310. </Col>
  1311. </Row>
  1312. ---
  1313. <Heading
  1314. url='/apps/annotations'
  1315. method='POST'
  1316. title='Create Annotation'
  1317. name='#create_annotation'
  1318. />
  1319. <Row>
  1320. <Col>
  1321. ### Query
  1322. <Properties>
  1323. <Property name='question' type='string' key='question'>
  1324. Question
  1325. </Property>
  1326. <Property name='answer' type='string' key='answer'>
  1327. Answer
  1328. </Property>
  1329. </Properties>
  1330. </Col>
  1331. <Col sticky>
  1332. <CodeGroup
  1333. title="Request"
  1334. tag="POST"
  1335. label="/apps/annotations"
  1336. 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."}'`}
  1337. >
  1338. ```bash {{ title: 'cURL' }}
  1339. curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \
  1340. --header 'Authorization: Bearer {api_key}' \
  1341. --header 'Content-Type: application/json' \
  1342. --data-raw '{
  1343. "question": "What is your name?",
  1344. "answer": "I am Dify."
  1345. }'
  1346. ```
  1347. </CodeGroup>
  1348. <CodeGroup title="Response">
  1349. ```json {{ title: 'Response' }}
  1350. {
  1351. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1352. "question": "What is your name?",
  1353. "answer": "I am Dify.",
  1354. "hit_count": 0,
  1355. "created_at": 1735625869
  1356. }
  1357. ```
  1358. </CodeGroup>
  1359. </Col>
  1360. </Row>
  1361. ---
  1362. <Heading
  1363. url='/apps/annotations/{annotation_id}'
  1364. method='PUT'
  1365. title='Update Annotation'
  1366. name='#update_annotation'
  1367. />
  1368. <Row>
  1369. <Col>
  1370. ### Query
  1371. <Properties>
  1372. <Property name='annotation_id' type='string' key='annotation_id'>
  1373. Annotation ID
  1374. </Property>
  1375. <Property name='question' type='string' key='question'>
  1376. Question
  1377. </Property>
  1378. <Property name='answer' type='string' key='answer'>
  1379. Answer
  1380. </Property>
  1381. </Properties>
  1382. </Col>
  1383. <Col sticky>
  1384. <CodeGroup
  1385. title="Request"
  1386. tag="PUT"
  1387. label="/apps/annotations/{annotation_id}"
  1388. 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."}'`}
  1389. >
  1390. ```bash {{ title: 'cURL' }}
  1391. curl --location --request PUT '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1392. --header 'Authorization: Bearer {api_key}' \
  1393. --header 'Content-Type: application/json' \
  1394. --data-raw '{
  1395. "question": "What is your name?",
  1396. "answer": "I am Dify."
  1397. }'
  1398. ```
  1399. </CodeGroup>
  1400. <CodeGroup title="Response">
  1401. ```json {{ title: 'Response' }}
  1402. {
  1403. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1404. "question": "What is your name?",
  1405. "answer": "I am Dify.",
  1406. "hit_count": 0,
  1407. "created_at": 1735625869
  1408. }
  1409. ```
  1410. </CodeGroup>
  1411. </Col>
  1412. </Row>
  1413. ---
  1414. <Heading
  1415. url='/apps/annotations/{annotation_id}'
  1416. method='DELETE'
  1417. title='Delete Annotation'
  1418. name='#delete_annotation'
  1419. />
  1420. <Row>
  1421. <Col>
  1422. ### Query
  1423. <Properties>
  1424. <Property name='annotation_id' type='string' key='annotation_id'>
  1425. Annotation ID
  1426. </Property>
  1427. </Properties>
  1428. </Col>
  1429. <Col sticky>
  1430. <CodeGroup
  1431. title="Request"
  1432. tag="PUT"
  1433. label="/apps/annotations/{annotation_id}"
  1434. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  1435. >
  1436. ```bash {{ title: 'cURL' }}
  1437. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1438. --header 'Authorization: Bearer {api_key}'
  1439. ```
  1440. </CodeGroup>
  1441. <CodeGroup title="Response">
  1442. ```text {{ title: 'Response' }}
  1443. 204 No Content
  1444. ```
  1445. </CodeGroup>
  1446. </Col>
  1447. </Row>
  1448. ---
  1449. <Heading
  1450. url='/apps/annotation-reply/{action}'
  1451. method='POST'
  1452. title='Initial Annotation Reply Settings'
  1453. name='#initial_annotation_reply_settings'
  1454. />
  1455. <Row>
  1456. <Col>
  1457. ### Query
  1458. <Properties>
  1459. <Property name='action' type='string' key='action'>
  1460. Action, can only be 'enable' or 'disable'
  1461. </Property>
  1462. <Property name='embedding_provider_name' type='string' key='embedding_provider_name'>
  1463. Specified embedding model provider, must be set up in the system first, corresponding to the provider field(Optional)
  1464. </Property>
  1465. <Property name='embedding_model_name' type='string' key='embedding_model_name'>
  1466. Specified embedding model, corresponding to the model field(Optional)
  1467. </Property>
  1468. <Property name='score_threshold' type='number' key='score_threshold'>
  1469. The similarity threshold for matching annotated replies. Only annotations with scores above this threshold will be recalled.
  1470. </Property>
  1471. </Properties>
  1472. </Col>
  1473. <Col sticky>
  1474. 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.
  1475. <CodeGroup
  1476. title="Request"
  1477. tag="POST"
  1478. label="/apps/annotation-reply/{action}"
  1479. 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"}'`}
  1480. >
  1481. ```bash {{ title: 'cURL' }}
  1482. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  1483. --header 'Authorization: Bearer {api_key}' \
  1484. --header 'Content-Type: application/json' \
  1485. --data-raw '{
  1486. "score_threshold": 0.9,
  1487. "embedding_provider_name": "zhipu",
  1488. "embedding_model_name": "embedding_3"
  1489. }'
  1490. ```
  1491. </CodeGroup>
  1492. <CodeGroup title="Response">
  1493. ```json {{ title: 'Response' }}
  1494. {
  1495. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1496. "job_status": "waiting"
  1497. }
  1498. ```
  1499. </CodeGroup>
  1500. 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.
  1501. </Col>
  1502. </Row>
  1503. ---
  1504. <Heading
  1505. url='/apps/annotation-reply/{action}/status/{job_id}'
  1506. method='GET'
  1507. title='Query Initial Annotation Reply Settings Task Status'
  1508. name='#initial_annotation_reply_settings_task_status'
  1509. />
  1510. <Row>
  1511. <Col>
  1512. ### Query
  1513. <Properties>
  1514. <Property name='action' type='string' key='action'>
  1515. Action, can only be 'enable' or 'disable', must be the same as the action in the initial annotation reply settings interface
  1516. </Property>
  1517. <Property name='job_id' type='string' key='job_id'>
  1518. Job ID, obtained from the initial annotation reply settings interface
  1519. </Property>
  1520. </Properties>
  1521. </Col>
  1522. <Col sticky>
  1523. <CodeGroup
  1524. title="Request"
  1525. tag="GET"
  1526. label="/apps/annotations"
  1527. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1528. >
  1529. ```bash {{ title: 'cURL' }}
  1530. curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \
  1531. --header 'Authorization: Bearer {api_key}'
  1532. ```
  1533. </CodeGroup>
  1534. <CodeGroup title="Response">
  1535. ```json {{ title: 'Response' }}
  1536. {
  1537. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1538. "job_status": "waiting",
  1539. "error_msg": ""
  1540. }
  1541. ```
  1542. </CodeGroup>
  1543. </Col>
  1544. </Row>