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_workflow.en.mdx 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # Workflow App API
  4. Workflow applications offers non-session support and is ideal for translation, article writing, summarization AI, and more.
  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='/workflows/run'
  24. method='POST'
  25. title='Execute Workflow'
  26. name='#Execute-Workflow'
  27. />
  28. <Row>
  29. <Col>
  30. Execute workflow, cannot be executed without a published workflow.
  31. ### Request Body
  32. - `inputs` (object) Required
  33. Allows the entry of various variable values defined by the App.
  34. 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.
  35. The workflow application requires at least one key/value pair to be inputted. The variable can be of File Array type.
  36. File Array type variable is suitable for inputting files combined with text understanding and answering questions, available only when the model supports file parsing and understanding capability.
  37. If the variable is of File Array type, the corresponding value should be a list whose elements contain following attributions:
  38. - `type` (string) Supported type:
  39. - `document` ('TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB')
  40. - `image` ('JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG')
  41. - `audio` ('MP3', 'M4A', 'WAV', 'WEBM', 'AMR')
  42. - `video` ('MP4', 'MOV', 'MPEG', 'MPGA')
  43. - `custom` (Other file types)
  44. - `transfer_method` (string) Transfer method, `remote_url` for image URL / `local_file` for file upload
  45. - `url` (string) Image URL (when the transfer method is `remote_url`)
  46. - `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`)
  47. - `response_mode` (string) Required
  48. The mode of response return, supporting:
  49. - `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)).
  50. - `blocking` Blocking mode, returns result after execution is complete. (Requests may be interrupted if the process is long)
  51. <i>Due to Cloudflare restrictions, the request will be interrupted without a return after 100 seconds.</i>
  52. - `user` (string) Required
  53. User identifier, used to define the identity of the end-user for retrieval and statistics.
  54. Should be uniquely defined by the developer within the application.
  55. <br/>
  56. <i>The user identifier should be consistent with the user passed in the message sending interface. The Service API does not share conversations created by the WebApp.</i>
  57. ### Response
  58. When `response_mode` is `blocking`, return a CompletionResponse object.
  59. When `response_mode` is `streaming`, return a ChunkCompletionResponse stream.
  60. ### CompletionResponse
  61. Returns the App result, `Content-Type` is `application/json`.
  62. - `workflow_run_id` (string) Unique ID of workflow execution
  63. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  64. - `data` (object) detail of result
  65. - `id` (string) ID of workflow execution
  66. - `workflow_id` (string) ID of related workflow
  67. - `status` (string) status of execution, `running` / `succeeded` / `failed` / `stopped`
  68. - `outputs` (json) Optional content of output
  69. - `error` (string) Optional reason of error
  70. - `elapsed_time` (float) Optional total seconds to be used
  71. - `total_tokens` (int) Optional tokens to be used
  72. - `total_steps` (int) default 0
  73. - `created_at` (timestamp) start time
  74. - `finished_at` (timestamp) end time
  75. ### ChunkCompletionResponse
  76. Returns the stream chunks outputted by the App, `Content-Type` is `text/event-stream`.
  77. Each streaming chunk starts with `data:`, separated by two newline characters `\n\n`, as shown below:
  78. <CodeGroup>
  79. ```streaming {{ title: 'Response' }}
  80. data: {"event": "text_chunk", "workflow_run_id": "b85e5fc5-751b-454d-b14e-dc5f240b0a31", "task_id": "bd029338-b068-4d34-a331-fc85478922c2", "data": {"text": "\u4e3a\u4e86", "from_variable_selector": ["1745912968134", "text"]}}\n\n
  81. ```
  82. </CodeGroup>
  83. The structure of the streaming chunks varies depending on the `event`:
  84. - `event: workflow_started` workflow starts execution
  85. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  86. - `workflow_run_id` (string) Unique ID of workflow execution
  87. - `event` (string) fixed to `workflow_started`
  88. - `data` (object) detail
  89. - `id` (string) Unique ID of workflow execution
  90. - `workflow_id` (string) ID of related workflow
  91. - `sequence_number` (int) Self-increasing serial number, self-increasing in the App, starting from 1
  92. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  93. - `event: node_started` node execution started
  94. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  95. - `workflow_run_id` (string) Unique ID of workflow execution
  96. - `event` (string) fixed to `node_started`
  97. - `data` (object) detail
  98. - `id` (string) Unique ID of workflow execution
  99. - `node_id` (string) ID of node
  100. - `node_type` (string) type of node
  101. - `title` (string) name of node
  102. - `index` (int) Execution sequence number, used to display Tracing Node sequence
  103. - `predecessor_node_id` (string) optional Prefix node ID, used for canvas display execution path
  104. - `inputs` (object) Contents of all preceding node variables used in the node
  105. - `created_at` (timestamp) timestamp of start, e.g., 1705395332
  106. - `event: text_chunk` Text fragment
  107. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  108. - `workflow_run_id` (string) Unique ID of workflow execution
  109. - `event` (string) fixed to `text_chunk`
  110. - `data` (object) detail
  111. - `text` (string) Text content
  112. - `from_variable_selector` (array) Text source path, helping developers understand which node and variable generated the text
  113. - `event: node_finished` node execution ends, success or failure in different states in the same event
  114. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  115. - `workflow_run_id` (string) Unique ID of workflow execution
  116. - `event` (string) fixed to `node_finished`
  117. - `data` (object) detail
  118. - `id` (string) Unique ID of workflow execution
  119. - `node_id` (string) ID of node
  120. - `node_type` (string) type of node
  121. - `title` (string) name of node
  122. - `index` (int) Execution sequence number, used to display Tracing Node sequence
  123. - `predecessor_node_id` (string) optional Prefix node ID, used for canvas display execution path
  124. - `inputs` (object) Contents of all preceding node variables used in the node
  125. - `process_data` (json) Optional node process data
  126. - `outputs` (json) Optional content of output
  127. - `status` (string) status of execution, `running` / `succeeded` / `failed` / `stopped`
  128. - `error` (string) Optional reason of error
  129. - `elapsed_time` (float) Optional total seconds to be used
  130. - `execution_metadata` (json) meta data
  131. - `total_tokens` (int) optional tokens to be used
  132. - `total_price` (decimal) optional Total cost
  133. - `currency` (string) optional e.g. `USD` / `RMB`
  134. - `created_at` (timestamp) timestamp of start, e.g., 1705395332
  135. - `event: workflow_finished` workflow execution ends, success or failure in different states in the same event
  136. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  137. - `workflow_run_id` (string) Unique ID of workflow execution
  138. - `event` (string) fixed to `workflow_finished`
  139. - `data` (object) detail
  140. - `id` (string) ID of workflow execution
  141. - `workflow_id` (string) ID of related workflow
  142. - `status` (string) status of execution, `running` / `succeeded` / `failed` / `stopped`
  143. - `outputs` (json) Optional content of output
  144. - `error` (string) Optional reason of error
  145. - `elapsed_time` (float) Optional total seconds to be used
  146. - `total_tokens` (int) Optional tokens to be used
  147. - `total_steps` (int) default 0
  148. - `created_at` (timestamp) start time
  149. - `finished_at` (timestamp) end time
  150. - `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)
  151. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  152. - `message_id` (string) Unique message ID
  153. - `audio` (string) The audio after speech synthesis, encoded in base64 text content, when playing, simply decode the base64 and feed it into the player
  154. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  155. - `event: tts_message_end` TTS audio stream end event, receiving this event indicates the end of the audio stream.
  156. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  157. - `message_id` (string) Unique message ID
  158. - `audio` (string) The end event has no audio, so this is an empty string
  159. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  160. - `event: ping` Ping event every 10 seconds to keep the connection alive.
  161. ### Errors
  162. - 400, `invalid_param`, abnormal parameter input
  163. - 400, `app_unavailable`, App configuration unavailable
  164. - 400, `provider_not_initialize`, no available model credential configuration
  165. - 400, `provider_quota_exceeded`, model invocation quota insufficient
  166. - 400, `model_currently_not_support`, current model unavailable
  167. - 400, `workflow_request_error`, workflow execution failed
  168. - 500, internal server error
  169. </Col>
  170. <Col sticky>
  171. <CodeGroup title="Request" tag="POST" label="/workflows/run" targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/run' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "response_mode": "streaming",\n "user": "abc-123"\n}'\n`}>
  172. ```bash {{ title: 'cURL' }}
  173. curl -X POST '${props.appDetail.api_base_url}/workflows/run' \
  174. --header 'Authorization: Bearer {api_key}' \
  175. --header 'Content-Type: application/json' \
  176. --data-raw '{
  177. "inputs": {},
  178. "response_mode": "streaming",
  179. "user": "abc-123"
  180. }'
  181. ```
  182. </CodeGroup>
  183. <CodeGroup title="Example: file array as an input variable">
  184. ```json {{ title: 'File variable example' }}
  185. {
  186. "inputs": {
  187. "{variable_name}":
  188. [
  189. {
  190. "transfer_method": "local_file",
  191. "upload_file_id": "{upload_file_id}",
  192. "type": "{document_type}"
  193. }
  194. ]
  195. }
  196. }
  197. ```
  198. </CodeGroup>
  199. ### Blocking Mode
  200. <CodeGroup title="Response">
  201. ```json {{ title: 'Response' }}
  202. {
  203. "workflow_run_id": "djflajgkldjgd",
  204. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  205. "data": {
  206. "id": "fdlsjfjejkghjda",
  207. "workflow_id": "fldjaslkfjlsda",
  208. "status": "succeeded",
  209. "outputs": {
  210. "text": "Nice to meet you."
  211. },
  212. "error": null,
  213. "elapsed_time": 0.875,
  214. "total_tokens": 3562,
  215. "total_steps": 8,
  216. "created_at": 1705407629,
  217. "finished_at": 1727807631
  218. }
  219. }
  220. ```
  221. </CodeGroup>
  222. ### Streaming Mode
  223. <CodeGroup title="Response">
  224. ```streaming {{ title: 'Response' }}
  225. 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}}
  226. 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}}
  227. 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}}
  228. 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}}
  229. 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"}
  230. 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": ""}
  231. ```
  232. </CodeGroup>
  233. <CodeGroup title="File upload sample code">
  234. ```json {{ title: 'File upload sample code' }}
  235. import requests
  236. import json
  237. def upload_file(file_path, user):
  238. upload_url = "https://api.dify.ai/v1/files/upload"
  239. headers = {
  240. "Authorization": "Bearer app-xxxxxxxx",
  241. }
  242. try:
  243. print("Upload file...")
  244. with open(file_path, 'rb') as file:
  245. files = {
  246. 'file': (file_path, file, 'text/plain') # Make sure the file is uploaded with the appropriate MIME type
  247. }
  248. data = {
  249. "user": user,
  250. "type": "TXT" # Set the file type to TXT
  251. }
  252. response = requests.post(upload_url, headers=headers, files=files, data=data)
  253. if response.status_code == 201: # 201 means creation is successful
  254. print("File uploaded successfully")
  255. return response.json().get("id") # Get the uploaded file ID
  256. else:
  257. print(f"File upload failed, status code: {response.status_code}")
  258. return None
  259. except Exception as e:
  260. print(f"Error occurred: {str(e)}")
  261. return None
  262. def run_workflow(file_id, user, response_mode="blocking"):
  263. workflow_url = "https://api.dify.ai/v1/workflows/run"
  264. headers = {
  265. "Authorization": "Bearer app-xxxxxxxxx",
  266. "Content-Type": "application/json"
  267. }
  268. data = {
  269. "inputs": {
  270. "orig_mail": [{
  271. "transfer_method": "local_file",
  272. "upload_file_id": file_id,
  273. "type": "document"
  274. }]
  275. },
  276. "response_mode": response_mode,
  277. "user": user
  278. }
  279. try:
  280. print("Run Workflow...")
  281. response = requests.post(workflow_url, headers=headers, json=data)
  282. if response.status_code == 200:
  283. print("Workflow execution successful")
  284. return response.json()
  285. else:
  286. print(f"Workflow execution failed, status code: {response.status_code}")
  287. return {"status": "error", "message": f"Failed to execute workflow, status code: {response.status_code}"}
  288. except Exception as e:
  289. print(f"Error occurred: {str(e)}")
  290. return {"status": "error", "message": str(e)}
  291. # Usage Examples
  292. file_path = "{your_file_path}"
  293. user = "difyuser"
  294. # Upload files
  295. file_id = upload_file(file_path, user)
  296. if file_id:
  297. # The file was uploaded successfully, and the workflow continues to run
  298. result = run_workflow(file_id, user)
  299. print(result)
  300. else:
  301. print("File upload failed and workflow cannot be executed")
  302. ```
  303. </CodeGroup>
  304. </Col>
  305. </Row>
  306. ---
  307. <Heading
  308. url='/workflows/run/:workflow_id'
  309. method='GET'
  310. title='Get Workflow Run Detail'
  311. name='#get-workflow-run-detail'
  312. />
  313. <Row>
  314. <Col>
  315. Retrieve the current execution results of a workflow task based on the workflow execution ID.
  316. ### Path
  317. - `workflow_id` (string) Workflow ID, can be obtained from the streaming chunk return
  318. ### Response
  319. - `id` (string) ID of workflow execution
  320. - `workflow_id` (string) ID of related workflow
  321. - `status` (string) status of execution, `running` / `succeeded` / `failed` / `stopped`
  322. - `inputs` (json) content of input
  323. - `outputs` (json) content of output
  324. - `error` (string) reason of error
  325. - `total_steps` (int) total steps of task
  326. - `total_tokens` (int) total tokens to be used
  327. - `created_at` (timestamp) start time
  328. - `finished_at` (timestamp) end time
  329. - `elapsed_time` (float) total seconds to be used
  330. </Col>
  331. <Col sticky>
  332. ### Request Example
  333. <CodeGroup title="Request" tag="GET" label="/workflows/run/:workflow_id" targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_id' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json'`}>
  334. ```bash {{ title: 'cURL' }}
  335. curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_id' \
  336. -H 'Authorization: Bearer {api_key}' \
  337. -H 'Content-Type: application/json'
  338. ```
  339. </CodeGroup>
  340. ### Response Example
  341. <CodeGroup title="Response">
  342. ```json {{ title: 'Response' }}
  343. {
  344. "id": "b1ad3277-089e-42c6-9dff-6820d94fbc76",
  345. "workflow_id": "19eff89f-ec03-4f75-b0fc-897e7effea02",
  346. "status": "succeeded",
  347. "inputs": "{\"sys.files\": [], \"sys.user_id\": \"abc-123\"}",
  348. "outputs": null,
  349. "error": null,
  350. "total_steps": 3,
  351. "total_tokens": 0,
  352. "created_at": 1705407629,
  353. "finished_at": 1727807631,
  354. "elapsed_time": 30.098514399956912
  355. }
  356. ```
  357. </CodeGroup>
  358. </Col>
  359. </Row>
  360. ---
  361. <Heading
  362. url='/workflows/tasks/:task_id/stop'
  363. method='POST'
  364. title='Stop Generate'
  365. name='#stop-generatebacks'
  366. />
  367. <Row>
  368. <Col>
  369. Only supported in streaming mode.
  370. ### Path
  371. - `task_id` (string) Task ID, can be obtained from the streaming chunk return
  372. ### Request Body
  373. - `user` (string) Required
  374. 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.
  375. ### Response
  376. - `result` (string) Always returns "success"
  377. </Col>
  378. <Col sticky>
  379. ### Request Example
  380. <CodeGroup title="Request" tag="POST" label="/workflows/tasks/:task_id/stop" targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json' \\\n--data-raw '{"user": "abc-123"}'`}>
  381. ```bash {{ title: 'cURL' }}
  382. curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \
  383. -H 'Authorization: Bearer {api_key}' \
  384. -H 'Content-Type: application/json' \
  385. --data-raw '{
  386. "user": "abc-123"
  387. }'
  388. ```
  389. </CodeGroup>
  390. ### Response Example
  391. <CodeGroup title="Response">
  392. ```json {{ title: 'Response' }}
  393. {
  394. "result": "success"
  395. }
  396. ```
  397. </CodeGroup>
  398. </Col>
  399. </Row>
  400. ---
  401. <Heading
  402. url='/files/upload'
  403. method='POST'
  404. title='File Upload'
  405. name='#file-upload'
  406. />
  407. <Row>
  408. <Col>
  409. Upload a file for use when sending messages, enabling multimodal understanding of images and text.
  410. Supports any formats that are supported by your workflow.
  411. Uploaded files are for use by the current end-user only.
  412. ### Request Body
  413. This interface requires a `multipart/form-data` request.
  414. - `file` (File) Required
  415. The file to be uploaded.
  416. - `user` (string) Required
  417. 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.
  418. ### Response
  419. After a successful upload, the server will return the file's ID and related information.
  420. - `id` (uuid) ID
  421. - `name` (string) File name
  422. - `size` (int) File size (bytes)
  423. - `extension` (string) File extension
  424. - `mime_type` (string) File mime-type
  425. - `created_by` (uuid) End-user ID
  426. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  427. ### Errors
  428. - 400, `no_file_uploaded`, a file must be provided
  429. - 400, `too_many_files`, currently only one file is accepted
  430. - 400, `unsupported_preview`, the file does not support preview
  431. - 400, `unsupported_estimate`, the file does not support estimation
  432. - 413, `file_too_large`, the file is too large
  433. - 415, `unsupported_file_type`, unsupported extension, currently only document files are accepted
  434. - 503, `s3_connection_failed`, unable to connect to S3 service
  435. - 503, `s3_permission_denied`, no permission to upload files to S3
  436. - 503, `s3_file_too_large`, file exceeds S3 size limit
  437. - 500, internal server error
  438. </Col>
  439. <Col sticky>
  440. ### Request Example
  441. <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'`}>
  442. ```bash {{ title: 'cURL' }}
  443. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  444. --header 'Authorization: Bearer {api_key}' \
  445. --form 'file=@"/path/to/file"'
  446. ```
  447. </CodeGroup>
  448. ### Response Example
  449. <CodeGroup title="Response">
  450. ```json {{ title: 'Response' }}
  451. {
  452. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  453. "name": "example.png",
  454. "size": 1024,
  455. "extension": "png",
  456. "mime_type": "image/png",
  457. "created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
  458. "created_at": 1577836800,
  459. }
  460. ```
  461. </CodeGroup>
  462. </Col>
  463. </Row>
  464. ---
  465. <Heading
  466. url='/workflows/logs'
  467. method='GET'
  468. title='Get Workflow Logs'
  469. name='#Get-Workflow-Logs'
  470. />
  471. <Row>
  472. <Col>
  473. Returns workflow logs, with the first page returning the latest `{limit}` messages, i.e., in reverse order.
  474. ### Query
  475. <Properties>
  476. <Property name='keyword' type='string' key='keyword'>
  477. Keyword to search
  478. </Property>
  479. <Property name='status' type='string' key='status'>
  480. succeeded/failed/stopped
  481. </Property>
  482. <Property name='page' type='int' key='page'>
  483. current page, default is 1.
  484. </Property>
  485. <Property name='limit' type='int' key='limit'>
  486. How many chat history messages to return in one request, default is 20.
  487. </Property>
  488. <Property name='created_by_end_user_session_id' type='str' key='created_by_end_user_session_id'>
  489. Created by which endUser, for example, `abc-123`.
  490. </Property>
  491. <Property name='created_by_account' type='str' key='created_by_account'>
  492. Created by which email account, for example, lizb@test.com.
  493. </Property>
  494. </Properties>
  495. ### Response
  496. - `page` (int) Current page
  497. - `limit` (int) Number of returned items, if input exceeds system limit, returns system limit amount
  498. - `total` (int) Number of total items
  499. - `has_more` (bool) Whether there is a next page
  500. - `data` (array[object]) Log list
  501. - `id` (string) ID
  502. - `workflow_run` (object) Workflow run
  503. - `id` (string) ID
  504. - `version` (string) Version
  505. - `status` (string) status of execution, `running` / `succeeded` / `failed` / `stopped`
  506. - `error` (string) Optional reason of error
  507. - `elapsed_time` (float) total seconds to be used
  508. - `total_tokens` (int) tokens to be used
  509. - `total_steps` (int) default 0
  510. - `created_at` (timestamp) start time
  511. - `finished_at` (timestamp) end time
  512. - `created_from` (string) Created from
  513. - `created_by_role` (string) Created by role
  514. - `created_by_account` (string) Optional Created by account
  515. - `created_by_end_user` (object) Created by end user
  516. - `id` (string) ID
  517. - `type` (string) Type
  518. - `is_anonymous` (bool) Is anonymous
  519. - `session_id` (string) Session ID
  520. - `created_at` (timestamp) create time
  521. </Col>
  522. <Col sticky>
  523. <CodeGroup title="Request" tag="GET" label="/workflows/logs" targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/logs'\\\n --header 'Authorization: Bearer {api_key}'`}>
  524. ```bash {{ title: 'cURL' }}
  525. curl -X GET '${props.appDetail.api_base_url}/workflows/logs?limit=1'
  526. --header 'Authorization: Bearer {api_key}'
  527. ```
  528. </CodeGroup>
  529. ### Response Example
  530. <CodeGroup title="Response">
  531. ```json {{ title: 'Response' }}
  532. {
  533. "page": 1,
  534. "limit": 1,
  535. "total": 7,
  536. "has_more": true,
  537. "data": [
  538. {
  539. "id": "e41b93f1-7ca2-40fd-b3a8-999aeb499cc0",
  540. "workflow_run": {
  541. "id": "c0640fc8-03ef-4481-a96c-8a13b732a36e",
  542. "version": "2024-08-01 12:17:09.771832",
  543. "status": "succeeded",
  544. "error": null,
  545. "elapsed_time": 1.3588523610014818,
  546. "total_tokens": 0,
  547. "total_steps": 3,
  548. "created_at": 1726139643,
  549. "finished_at": 1726139644
  550. },
  551. "created_from": "service-api",
  552. "created_by_role": "end_user",
  553. "created_by_account": null,
  554. "created_by_end_user": {
  555. "id": "7f7d9117-dd9d-441d-8970-87e5e7e687a3",
  556. "type": "service_api",
  557. "is_anonymous": false,
  558. "session_id": "abc-123"
  559. },
  560. "created_at": 1726139644
  561. }
  562. ]
  563. }
  564. ```
  565. </CodeGroup>
  566. </Col>
  567. </Row>
  568. ---
  569. <Heading
  570. url='/info'
  571. method='GET'
  572. title='Get Application Basic Information'
  573. name='#info'
  574. />
  575. <Row>
  576. <Col>
  577. Used to get basic information about this application
  578. ### Response
  579. - `name` (string) application name
  580. - `description` (string) application description
  581. - `tags` (array[string]) application tags
  582. - `mode` (string) application mode
  583. - `author_name` (string) application author name
  584. </Col>
  585. <Col>
  586. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  587. ```bash {{ title: 'cURL' }}
  588. curl -X GET '${props.appDetail.api_base_url}/info' \
  589. -H 'Authorization: Bearer {api_key}'
  590. ```
  591. </CodeGroup>
  592. <CodeGroup title="Response">
  593. ```json {{ title: 'Response' }}
  594. {
  595. "name": "My App",
  596. "description": "This is my app.",
  597. "tags": [
  598. "tag1",
  599. "tag2"
  600. ],
  601. "mode": "workflow",
  602. "author_name": "Dify"
  603. }
  604. ```
  605. </CodeGroup>
  606. </Col>
  607. </Row>
  608. ---
  609. <Heading
  610. url='/parameters'
  611. method='GET'
  612. title='Get Application Parameters Information'
  613. name='#parameters'
  614. />
  615. <Row>
  616. <Col>
  617. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  618. ### Response
  619. - `user_input_form` (array[object]) User input form configuration
  620. - `text-input` (object) Text input control
  621. - `label` (string) Variable display label name
  622. - `variable` (string) Variable ID
  623. - `required` (bool) Whether it is required
  624. - `default` (string) Default value
  625. - `paragraph` (object) Paragraph text input control
  626. - `label` (string) Variable display label name
  627. - `variable` (string) Variable ID
  628. - `required` (bool) Whether it is required
  629. - `default` (string) Default value
  630. - `select` (object) Dropdown control
  631. - `label` (string) Variable display label name
  632. - `variable` (string) Variable ID
  633. - `required` (bool) Whether it is required
  634. - `default` (string) Default value
  635. - `options` (array[string]) Option values
  636. - `file_upload` (object) File upload configuration
  637. - `image` (object) Image settings
  638. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`
  639. - `enabled` (bool) Whether it is enabled
  640. - `number_limits` (int) Image number limit, default is 3
  641. - `transfer_methods` (array[string]) List of transfer methods, remote_url, local_file, must choose one
  642. - `system_parameters` (object) System parameters
  643. - `file_size_limit` (int) Document upload size limit (MB)
  644. - `image_file_size_limit` (int) Image file upload size limit (MB)
  645. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  646. - `video_file_size_limit` (int) Video file upload size limit (MB)
  647. </Col>
  648. <Col sticky>
  649. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  650. ```bash {{ title: 'cURL' }}
  651. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  652. --header 'Authorization: Bearer {api_key}'
  653. ```
  654. </CodeGroup>
  655. <CodeGroup title="Response">
  656. ```json {{ title: 'Response' }}
  657. {
  658. "user_input_form": [
  659. {
  660. "paragraph": {
  661. "label": "Query",
  662. "variable": "query",
  663. "required": true,
  664. "default": ""
  665. }
  666. }
  667. ],
  668. "file_upload": {
  669. "image": {
  670. "enabled": false,
  671. "number_limits": 3,
  672. "detail": "high",
  673. "transfer_methods": [
  674. "remote_url",
  675. "local_file"
  676. ]
  677. }
  678. },
  679. "system_parameters": {
  680. "file_size_limit": 15,
  681. "image_file_size_limit": 10,
  682. "audio_file_size_limit": 50,
  683. "video_file_size_limit": 100
  684. }
  685. }
  686. ```
  687. </CodeGroup>
  688. </Col>
  689. </Row>
  690. ---
  691. <Heading
  692. url='/site'
  693. method='GET'
  694. title='Get Application WebApp Settings'
  695. name='#site'
  696. />
  697. <Row>
  698. <Col>
  699. Used to get the WebApp settings of the application.
  700. ### Response
  701. - `title` (string) WebApp name
  702. - `icon_type` (string) Icon type, `emoji` - emoji, `image` - picture
  703. - `icon` (string) Icon. If it's `emoji` type, it's an emoji symbol; if it's `image` type, it's an image URL.
  704. - `icon_background` (string) Background color in hex format
  705. - `icon_url` (string) Icon URL
  706. - `description` (string) Description
  707. - `copyright` (string) Copyright information
  708. - `privacy_policy` (string) Privacy policy link
  709. - `custom_disclaimer` (string) Custom disclaimer
  710. - `default_language` (string) Default language
  711. - `show_workflow_steps` (bool) Whether to show workflow details
  712. </Col>
  713. <Col>
  714. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  715. ```bash {{ title: 'cURL' }}
  716. curl -X GET '${props.appDetail.api_base_url}/site' \
  717. -H 'Authorization: Bearer {api_key}'
  718. ```
  719. </CodeGroup>
  720. <CodeGroup title="Response">
  721. ```json {{ title: 'Response' }}
  722. {
  723. "title": "My App",
  724. "icon_type": "emoji",
  725. "icon": "😄",
  726. "icon_background": "#FFEAD5",
  727. "icon_url": null,
  728. "description": "This is my app.",
  729. "copyright": "all rights reserved",
  730. "privacy_policy": "",
  731. "custom_disclaimer": "All generated by AI",
  732. "default_language": "en-US",
  733. "show_workflow_steps": false,
  734. }
  735. ```
  736. </CodeGroup>
  737. </Col>
  738. </Row>
  739. ___