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

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