template_workflow.en.mdx 30 KB

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