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

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