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

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