Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

template_advanced_chat.en.mdx 67KB

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