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

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