You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template_workflow.en.mdx 33KB

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