template_workflow.en.mdx 30 KB

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