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_chat.en.mdx 68KB

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