You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template_advanced_chat.en.mdx 59KB

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