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

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