template_workflow.zh.mdx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # Workflow 应用 API
  4. Workflow 应用无会话支持,适合用于翻译/文章写作/总结 AI 等等。
  5. <div>
  6. ### Base URL
  7. <CodeGroup title="Code" targetCode={props.appDetail.api_base_url}>
  8. ```javascript
  9. ```
  10. </CodeGroup>
  11. ### Authentication
  12. Dify Service API 使用 `API-Key` 进行鉴权。
  13. <i>**强烈建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。**</i>
  14. 所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  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='执行 workflow'
  26. name='#Execute-Workflow'
  27. />
  28. <Row>
  29. <Col>
  30. 执行 workflow,没有已发布的 workflow,不可执行。
  31. ### Request Body
  32. - `inputs` (object) Required
  33. 允许传入 App 定义的各变量值。
  34. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。
  35. - `response_mode` (string) Required
  36. 返回响应模式,支持:
  37. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  38. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  39. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  40. - `user` (string) Required
  41. 用户标识,用于定义终端用户的身份,方便检索、统计。
  42. 由开发者定义规则,需保证用户标识在应用内唯一。
  43. - `files` (array[object]) Optional
  44. 文件列表,适用于传入文件结合文本理解并回答问题,仅当模型支持 Vision 能力时可用。
  45. - `type` (string) 支持类型:
  46. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  47. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  48. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
  49. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'MPGA'
  50. - `transfer_method` (string) 传递方式,`remote_url` 图片地址 / `local_file` 上传文件
  51. - `url` (string) 图片地址(仅当传递方式为 `remote_url` 时)
  52. - `upload_file_id` (string) (string) 上传文件 ID(仅当传递方式为 `local_file` 时)
  53. ### Response
  54. 当 `response_mode` 为 `blocking` 时,返回 CompletionResponse object。
  55. 当 `response_mode` 为 `streaming`时,返回 ChunkCompletionResponse object 流式序列。
  56. ### CompletionResponse
  57. 返回完整的 App 结果,`Content-Type` 为 `application/json` 。
  58. - `workflow_run_id` (string) workflow 执行 ID
  59. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  60. - `data` (object) 详细内容
  61. - `id` (string) workflow 执行 ID
  62. - `workflow_id` (string) 关联 Workflow ID
  63. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  64. - `outputs` (json) Optional 输出内容
  65. - `error` (string) Optional 错误原因
  66. - `elapsed_time` (float) Optional 耗时(s)
  67. - `total_tokens` (int) Optional 总使用 tokens
  68. - `total_steps` (int) 总步数(冗余),默认 0
  69. - `created_at` (timestamp) 开始时间
  70. - `finished_at` (timestamp) 结束时间
  71. ### ChunkCompletionResponse
  72. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  73. 每个流式块均为 data: 开头,块之间以 `\n\n` 即两个换行符分隔,如下所示:
  74. <CodeGroup>
  75. ```streaming {{ title: 'Response' }}
  76. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  77. ```
  78. </CodeGroup>
  79. 流式块中根据 `event` 不同,结构也不同,包含以下类型:
  80. - `event: workflow_started` workflow 开始执行
  81. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  82. - `workflow_run_id` (string) workflow 执行 ID
  83. - `event` (string) 固定为 `workflow_started`
  84. - `data` (object) 详细内容
  85. - `id` (string) workflow 执行 ID
  86. - `workflow_id` (string) 关联 Workflow ID
  87. - `sequence_number` (int) 自增序号,App 内自增,从 1 开始
  88. - `created_at` (timestamp) 开始时间
  89. - `event: node_started` node 开始执行
  90. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  91. - `workflow_run_id` (string) workflow 执行 ID
  92. - `event` (string) 固定为 `node_started`
  93. - `data` (object) 详细内容
  94. - `id` (string) workflow 执行 ID
  95. - `node_id` (string) 节点 ID
  96. - `node_type` (string) 节点类型
  97. - `title` (string) 节点名称
  98. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  99. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  100. - `inputs` (array[object]) 节点中所有使用到的前置节点变量内容
  101. - `created_at` (timestamp) 开始时间
  102. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  103. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  104. - `workflow_run_id` (string) workflow 执行 ID
  105. - `event` (string) 固定为 `node_finished`
  106. - `data` (object) 详细内容
  107. - `id` (string) node 执行 ID
  108. - `node_id` (string) 节点 ID
  109. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  110. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  111. - `inputs` (array[object]) 节点中所有使用到的前置节点变量内容
  112. - `process_data` (json) Optional 节点过程数据
  113. - `outputs` (json) Optional 输出内容
  114. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  115. - `error` (string) Optional 错误原因
  116. - `elapsed_time` (float) Optional 耗时(s)
  117. - `execution_metadata` (json) 元数据
  118. - `total_tokens` (int) optional 总使用 tokens
  119. - `total_price` (decimal) optional 总费用
  120. - `currency` (string) optional 货币,如 `USD` / `RMB`
  121. - `created_at` (timestamp) 开始时间
  122. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  123. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  124. - `workflow_run_id` (string) workflow 执行 ID
  125. - `event` (string) 固定为 `workflow_finished`
  126. - `data` (object) 详细内容
  127. - `id` (string) workflow 执行 ID
  128. - `workflow_id` (string) 关联 Workflow ID
  129. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  130. - `outputs` (json) Optional 输出内容
  131. - `error` (string) Optional 错误原因
  132. - `elapsed_time` (float) Optional 耗时(s)
  133. - `total_tokens` (int) Optional 总使用 tokens
  134. - `total_steps` (int) 总步数(冗余),默认 0
  135. - `created_at` (timestamp) 开始时间
  136. - `finished_at` (timestamp) 结束时间
  137. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  138. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  139. - `message_id` (string) 消息唯一 ID
  140. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  141. - `created_at` (int) 创建时间戳,如:1705395332
  142. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  143. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  144. - `message_id` (string) 消息唯一 ID
  145. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  146. - `created_at` (int) 创建时间戳,如:1705395332
  147. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  148. ### Errors
  149. - 400,`invalid_param`,传入参数异常
  150. - 400,`app_unavailable`,App 配置不可用
  151. - 400,`provider_not_initialize`,无可用模型凭据配置
  152. - 400,`provider_quota_exceeded`,模型调用额度不足
  153. - 400,`model_currently_not_support`,当前模型不可用
  154. - 400,`workflow_request_error`,workflow 执行失败
  155. - 500,服务内部异常
  156. </Col>
  157. <Col sticky>
  158. <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`}>
  159. ```bash {{ title: 'cURL' }}
  160. curl -X POST '${props.appDetail.api_base_url}/workflows/run' \
  161. --header 'Authorization: Bearer {api_key}' \
  162. --header 'Content-Type: application/json' \
  163. --data-raw '{
  164. "inputs": {},
  165. "response_mode": "streaming",
  166. "user": "abc-123"
  167. }'
  168. ```
  169. </CodeGroup>
  170. ### Blocking Mode
  171. <CodeGroup title="Response">
  172. ```json {{ title: 'Response' }}
  173. {
  174. "workflow_run_id": "djflajgkldjgd",
  175. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  176. "data": {
  177. "id": "fdlsjfjejkghjda",
  178. "workflow_id": "fldjaslkfjlsda",
  179. "status": "succeeded",
  180. "outputs": {
  181. "text": "Nice to meet you."
  182. },
  183. "error": null,
  184. "elapsed_time": 0.875,
  185. "total_tokens": 3562,
  186. "total_steps": 8,
  187. "created_at": 1705407629,
  188. "finished_at": 1727807631
  189. }
  190. }
  191. ```
  192. </CodeGroup>
  193. ### Streaming Mode
  194. <CodeGroup title="Response">
  195. ```streaming {{ title: 'Response' }}
  196. 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}}
  197. 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}}
  198. 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}}
  199. 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}}
  200. 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"}
  201. 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": ""}
  202. ```
  203. </CodeGroup>
  204. </Col>
  205. </Row>
  206. ---
  207. <Heading
  208. url='/workflows/run/:workflow_id'
  209. method='GET'
  210. title='获取workflow执行情况'
  211. name='#get-workflow-run-detail'
  212. />
  213. <Row>
  214. <Col>
  215. 根据 workflow 执行 ID 获取 workflow 任务当前执行结果
  216. ### Path
  217. - `workflow_id` (string) workflow 执行 ID,可在流式返回 Chunk 中获取
  218. ### Response
  219. - `id` (string) workflow 执行 ID
  220. - `workflow_id` (string) 关联的 Workflow ID
  221. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  222. - `inputs` (json) 任务输入内容
  223. - `outputs` (json) 任务输出内容
  224. - `error` (string) 错误原因
  225. - `total_steps` (int) 任务执行总步数
  226. - `total_tokens` (int) 任务执行总 tokens
  227. - `created_at` (timestamp) 任务开始时间
  228. - `finished_at` (timestamp) 任务结束时间
  229. - `elapsed_time` (float) 耗时(s)
  230. </Col>
  231. <Col sticky>
  232. ### Request Example
  233. <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'`}>
  234. ```bash {{ title: 'cURL' }}
  235. curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_id' \
  236. -H 'Authorization: Bearer {api_key}' \
  237. -H 'Content-Type: application/json'
  238. ```
  239. </CodeGroup>
  240. ### Response Example
  241. <CodeGroup title="Response">
  242. ```json {{ title: 'Response' }}
  243. {
  244. "id": "b1ad3277-089e-42c6-9dff-6820d94fbc76",
  245. "workflow_id": "19eff89f-ec03-4f75-b0fc-897e7effea02",
  246. "status": "succeeded",
  247. "inputs": "{\"sys.files\": [], \"sys.user_id\": \"abc-123\"}",
  248. "outputs": null,
  249. "error": null,
  250. "total_steps": 3,
  251. "total_tokens": 0,
  252. "created_at": "Thu, 18 Jul 2024 03:17:40 -0000",
  253. "finished_at": "Thu, 18 Jul 2024 03:18:10 -0000",
  254. "elapsed_time": 30.098514399956912
  255. }
  256. ```
  257. </CodeGroup>
  258. </Col>
  259. </Row>
  260. ---
  261. <Heading
  262. url='/workflows/tasks/:task_id/stop'
  263. method='POST'
  264. title='停止响应'
  265. name='#stop-generatebacks'
  266. />
  267. <Row>
  268. <Col>
  269. 仅支持流式模式。
  270. ### Path
  271. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  272. ### Request Body
  273. - `user` (string) Required
  274. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。
  275. ### Response
  276. - `result` (string) 固定返回 "success"
  277. </Col>
  278. <Col sticky>
  279. ### Request Example
  280. <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"}'`}>
  281. ```bash {{ title: 'cURL' }}
  282. curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \
  283. -H 'Authorization: Bearer {api_key}' \
  284. -H 'Content-Type: application/json' \
  285. --data-raw '{
  286. "user": "abc-123"
  287. }'
  288. ```
  289. </CodeGroup>
  290. ### Response Example
  291. <CodeGroup title="Response">
  292. ```json {{ title: 'Response' }}
  293. {
  294. "result": "success"
  295. }
  296. ```
  297. </CodeGroup>
  298. </Col>
  299. </Row>
  300. ---
  301. <Heading
  302. url='/parameters'
  303. method='GET'
  304. title='获取应用配置信息'
  305. name='#parameters'
  306. />
  307. <Row>
  308. <Col>
  309. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  310. ### Query
  311. <Properties>
  312. <Property name='user' type='string' key='user'>
  313. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  314. </Property>
  315. </Properties>
  316. ### Response
  317. - `user_input_form` (array[object]) 用户输入表单配置
  318. - `text-input` (object) 文本输入控件
  319. - `label` (string) 控件展示标签名
  320. - `variable` (string) 控件 ID
  321. - `required` (bool) 是否必填
  322. - `default` (string) 默认值
  323. - `paragraph` (object) 段落文本输入控件
  324. - `label` (string) 控件展示标签名
  325. - `variable` (string) 控件 ID
  326. - `required` (bool) 是否必填
  327. - `default` (string) 默认值
  328. - `select` (object) 下拉控件
  329. - `label` (string) 控件展示标签名
  330. - `variable` (string) 控件 ID
  331. - `required` (bool) 是否必填
  332. - `default` (string) 默认值
  333. - `options` (array[string]) 选项值
  334. - `file_upload` (object) 文件上传配置
  335. - `image` (object) 图片设置
  336. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  337. - `enabled` (bool) 是否开启
  338. - `number_limits` (int) 图片数量限制,默认 3
  339. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  340. - `system_parameters` (object) 系统参数
  341. - `file_size_limit` (int) 文档上传大小限制 (MB)
  342. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  343. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  344. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  345. </Col>
  346. <Col sticky>
  347. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123'`}>
  348. ```bash {{ title: 'cURL' }}
  349. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  350. --header 'Authorization: Bearer {api_key}'
  351. ```
  352. </CodeGroup>
  353. <CodeGroup title="Response">
  354. ```json {{ title: 'Response' }}
  355. {
  356. "user_input_form": [
  357. {
  358. "paragraph": {
  359. "label": "Query",
  360. "variable": "query",
  361. "required": true,
  362. "default": ""
  363. }
  364. }
  365. ],
  366. "file_upload": {
  367. "image": {
  368. "enabled": false,
  369. "number_limits": 3,
  370. "detail": "high",
  371. "transfer_methods": [
  372. "remote_url",
  373. "local_file"
  374. ]
  375. }
  376. },
  377. "system_parameters": {
  378. "file_size_limit": 15,
  379. "image_file_size_limit": 10,
  380. "audio_file_size_limit": 50,
  381. "video_file_size_limit": 100
  382. }
  383. }
  384. ```
  385. </CodeGroup>
  386. </Col>
  387. </Row>
  388. ---
  389. <Heading
  390. url='/workflows/logs'
  391. method='GET'
  392. title='获取 workflow 日志'
  393. name='#Get-Workflow-Logs'
  394. />
  395. <Row>
  396. <Col>
  397. 倒序返回workflow日志
  398. ### Query
  399. <Properties>
  400. <Property name='keyword' type='string' key='keyword'>
  401. 关键字
  402. </Property>
  403. <Property name='status' type='string' key='status'>
  404. 执行状态 succeeded/failed/stopped
  405. </Property>
  406. <Property name='page' type='int' key='page'>
  407. 当前页码, 默认1.
  408. </Property>
  409. <Property name='limit' type='int' key='limit'>
  410. 每页条数, 默认20.
  411. </Property>
  412. </Properties>
  413. ### Response
  414. - `page` (int) 当前页码
  415. - `limit` (int) 每页条数
  416. - `total` (int) 总条数
  417. - `has_more` (bool) 是否还有更多数据
  418. - `data` (array[object]) 当前页码的数据
  419. - `id` (string) 标识
  420. - `workflow_run` (object) Workflow 执行日志
  421. - `id` (string) 标识
  422. - `version` (string) 版本
  423. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  424. - `error` (string) (可选) 错误
  425. - `elapsed_time` (float) 耗时,单位秒
  426. - `total_tokens` (int) 消耗的token数量
  427. - `total_steps` (int) 执行步骤长度
  428. - `created_at` (timestamp) 开始时间
  429. - `finished_at` (timestamp) 结束时间
  430. - `created_from` (string) 来源
  431. - `created_by_role` (string) 角色
  432. - `created_by_account` (string) (可选) 帐号
  433. - `created_by_end_user` (object) 用户
  434. - `id` (string) 标识
  435. - `type` (string) 类型
  436. - `is_anonymous` (bool) 是否匿名
  437. - `session_id` (string) 会话标识
  438. - `created_at` (timestamp) 创建时间
  439. </Col>
  440. <Col sticky>
  441. <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}'`}>
  442. ```bash {{ title: 'cURL' }}
  443. curl -X GET '${props.appDetail.api_base_url}/workflows/logs?limit=1'
  444. --header 'Authorization: Bearer {api_key}'
  445. ```
  446. </CodeGroup>
  447. ### Response Example
  448. <CodeGroup title="Response">
  449. ```json {{ title: 'Response' }}
  450. {
  451. "page": 1,
  452. "limit": 1,
  453. "total": 7,
  454. "has_more": true,
  455. "data": [
  456. {
  457. "id": "e41b93f1-7ca2-40fd-b3a8-999aeb499cc0",
  458. "workflow_run": {
  459. "id": "c0640fc8-03ef-4481-a96c-8a13b732a36e",
  460. "version": "2024-08-01 12:17:09.771832",
  461. "status": "succeeded",
  462. "error": null,
  463. "elapsed_time": 1.3588523610014818,
  464. "total_tokens": 0,
  465. "total_steps": 3,
  466. "created_at": 1726139643,
  467. "finished_at": 1726139644
  468. },
  469. "created_from": "service-api",
  470. "created_by_role": "end_user",
  471. "created_by_account": null,
  472. "created_by_end_user": {
  473. "id": "7f7d9117-dd9d-441d-8970-87e5e7e687a3",
  474. "type": "service_api",
  475. "is_anonymous": false,
  476. "session_id": "abc-123"
  477. },
  478. "created_at": 1726139644
  479. }
  480. ]
  481. }
  482. ```
  483. </CodeGroup>
  484. </Col>
  485. </Row>