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

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