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

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