您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

template_workflow.zh.mdx 50KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  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. 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. 文件列表类型变量适用于传入文件结合文本理解并回答问题,仅当模型支持该类型文件解析能力时可用。如果该变量是文件列表类型,该变量对应的值应是列表格式,其中每个元素应包含以下内容:
  36. - `type` (string) 支持类型:
  37. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  38. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  39. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
  40. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'MPGA'
  41. - `custom` 具体类型包含:其他文件类型
  42. - `transfer_method` (string) 传递方式,`remote_url` 图片地址 / `local_file` 上传文件
  43. - `url` (string) 图片地址(仅当传递方式为 `remote_url` 时)
  44. - `upload_file_id` (string) 上传文件 ID(仅当传递方式为 `local_file` 时)
  45. - `response_mode` (string) Required
  46. 返回响应模式,支持:
  47. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  48. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  49. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  50. - `user` (string) Required
  51. 用户标识,用于定义终端用户的身份,方便检索、统计。
  52. 由开发者定义规则,需保证用户标识在应用内唯一。API 无法访问 WebApp 创建的会话。
  53. - `files` (array[object]) 可选
  54. - `trace_id` (string) Optional
  55. 链路追踪ID。适用于与业务系统已有的trace组件打通,实现端到端分布式追踪等场景。如果未指定,系统将自动生成 `trace_id`。支持以下三种方式传递,具体优先级依次为:
  56. 1. Header:推荐通过 HTTP Header `X-Trace-Id` 传递,优先级最高。
  57. 2. Query 参数:通过 URL 查询参数 `trace_id` 传递。
  58. 3. Request Body:通过请求体字段 `trace_id` 传递(即本字段)。
  59. ### Response
  60. 当 `response_mode` 为 `blocking` 时,返回 CompletionResponse object。
  61. 当 `response_mode` 为 `streaming`时,返回 ChunkCompletionResponse object 流式序列。
  62. ### CompletionResponse
  63. 返回完整的 App 结果,`Content-Type` 为 `application/json` 。
  64. - `workflow_run_id` (string) workflow 执行 ID
  65. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  66. - `data` (object) 详细内容
  67. - `id` (string) workflow 执行 ID
  68. - `workflow_id` (string) 关联 Workflow ID
  69. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  70. - `outputs` (json) Optional 输出内容
  71. - `error` (string) Optional 错误原因
  72. - `elapsed_time` (float) Optional 耗时(s)
  73. - `total_tokens` (int) Optional 总使用 tokens
  74. - `total_steps` (int) 总步数(冗余),默认 0
  75. - `created_at` (timestamp) 开始时间
  76. - `finished_at` (timestamp) 结束时间
  77. ### ChunkCompletionResponse
  78. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  79. 每个流式块均为 data: 开头,块之间以 `\n\n` 即两个换行符分隔,如下所示:
  80. <CodeGroup>
  81. ```streaming {{ title: 'Response' }}
  82. 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
  83. ```
  84. </CodeGroup>
  85. 流式块中根据 `event` 不同,结构也不同,包含以下类型:
  86. - `event: workflow_started` workflow 开始执行
  87. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  88. - `workflow_run_id` (string) workflow 执行 ID
  89. - `event` (string) 固定为 `workflow_started`
  90. - `data` (object) 详细内容
  91. - `id` (string) workflow 执行 ID
  92. - `workflow_id` (string) 关联 Workflow ID
  93. - `created_at` (timestamp) 开始时间
  94. - `event: node_started` node 开始执行
  95. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  96. - `workflow_run_id` (string) workflow 执行 ID
  97. - `event` (string) 固定为 `node_started`
  98. - `data` (object) 详细内容
  99. - `id` (string) workflow 执行 ID
  100. - `node_id` (string) 节点 ID
  101. - `node_type` (string) 节点类型
  102. - `title` (string) 节点名称
  103. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  104. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  105. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  106. - `created_at` (timestamp) 开始时间
  107. - `event: text_chunk` 文本片段
  108. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  109. - `workflow_run_id` (string) workflow 执行 ID
  110. - `event` (string) 固定为 `text_chunk`
  111. - `data` (object) 详细内容
  112. - `text` (string) 文本内容
  113. - `from_variable_selector` (array) 文本来源路径,帮助开发者了解文本是由哪个节点的哪个变量生成的
  114. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  115. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  116. - `workflow_run_id` (string) workflow 执行 ID
  117. - `event` (string) 固定为 `node_finished`
  118. - `data` (object) 详细内容
  119. - `id` (string) node 执行 ID
  120. - `node_id` (string) 节点 ID
  121. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  122. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  123. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  124. - `process_data` (json) Optional 节点过程数据
  125. - `outputs` (json) Optional 输出内容
  126. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  127. - `error` (string) Optional 错误原因
  128. - `elapsed_time` (float) Optional 耗时(s)
  129. - `execution_metadata` (json) 元数据
  130. - `total_tokens` (int) optional 总使用 tokens
  131. - `total_price` (decimal) optional 总费用
  132. - `currency` (string) optional 货币,如 `USD` / `RMB`
  133. - `created_at` (timestamp) 开始时间
  134. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  135. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  136. - `workflow_run_id` (string) workflow 执行 ID
  137. - `event` (string) 固定为 `workflow_finished`
  138. - `data` (object) 详细内容
  139. - `id` (string) workflow 执行 ID
  140. - `workflow_id` (string) 关联 Workflow ID
  141. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  142. - `outputs` (json) Optional 输出内容
  143. - `error` (string) Optional 错误原因
  144. - `elapsed_time` (float) Optional 耗时(s)
  145. - `total_tokens` (int) Optional 总使用 tokens
  146. - `total_steps` (int) 总步数(冗余),默认 0
  147. - `created_at` (timestamp) 开始时间
  148. - `finished_at` (timestamp) 结束时间
  149. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  150. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  151. - `message_id` (string) 消息唯一 ID
  152. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  153. - `created_at` (int) 创建时间戳,如:1705395332
  154. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  155. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  156. - `message_id` (string) 消息唯一 ID
  157. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  158. - `created_at` (int) 创建时间戳,如:1705395332
  159. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  160. ### Errors
  161. - 400,`invalid_param`,传入参数异常
  162. - 400,`app_unavailable`,App 配置不可用
  163. - 400,`provider_not_initialize`,无可用模型凭据配置
  164. - 400,`provider_quota_exceeded`,模型调用额度不足
  165. - 400,`model_currently_not_support`,当前模型不可用
  166. - 400,`workflow_request_error`,workflow 执行失败
  167. - 500,服务内部异常
  168. </Col>
  169. <Col sticky>
  170. <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`}>
  171. ```bash {{ title: 'cURL' }}
  172. curl -X POST '${props.appDetail.api_base_url}/workflows/run' \
  173. --header 'Authorization: Bearer {api_key}' \
  174. --header 'Content-Type: application/json' \
  175. --data-raw '{
  176. "inputs": {},
  177. "response_mode": "streaming",
  178. "user": "abc-123"
  179. }'
  180. ```
  181. </CodeGroup>
  182. <CodeGroup title="Example: file array as an input variable">
  183. ```json {{ title: 'File variable example' }}
  184. {
  185. "inputs": {
  186. "{variable_name}":
  187. [
  188. {
  189. "transfer_method": "local_file",
  190. "upload_file_id": "{upload_file_id}",
  191. "type": "{document_type}"
  192. }
  193. ]
  194. }
  195. }
  196. ```
  197. </CodeGroup>
  198. ### Blocking Mode
  199. <CodeGroup title="Response">
  200. ```json {{ title: 'Response' }}
  201. {
  202. "workflow_run_id": "djflajgkldjgd",
  203. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  204. "data": {
  205. "id": "fdlsjfjejkghjda",
  206. "workflow_id": "fldjaslkfjlsda",
  207. "status": "succeeded",
  208. "outputs": {
  209. "text": "Nice to meet you."
  210. },
  211. "error": null,
  212. "elapsed_time": 0.875,
  213. "total_tokens": 3562,
  214. "total_steps": 8,
  215. "created_at": 1705407629,
  216. "finished_at": 1727807631
  217. }
  218. }
  219. ```
  220. </CodeGroup>
  221. ### Streaming Mode
  222. <CodeGroup title="Response">
  223. ```streaming {{ title: 'Response' }}
  224. data: {"event": "workflow_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "created_at": 1679586595}}
  225. 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}}
  226. 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}}
  227. 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}}
  228. 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"}
  229. 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": ""}
  230. ```
  231. </CodeGroup>
  232. <CodeGroup title="File upload sample code">
  233. ```json {{ title: 'File upload sample code' }}
  234. import requests
  235. import json
  236. def upload_file(file_path, user):
  237. upload_url = "https://api.dify.ai/v1/files/upload"
  238. headers = {
  239. "Authorization": "Bearer app-xxxxxxxx",
  240. }
  241. try:
  242. print("上传文件中...")
  243. with open(file_path, 'rb') as file:
  244. files = {
  245. 'file': (file_path, file, 'text/plain') # 确保文件以适当的MIME类型上传
  246. }
  247. data = {
  248. "user": user,
  249. "type": "TXT" # 设置文件类型为TXT
  250. }
  251. response = requests.post(upload_url, headers=headers, files=files, data=data)
  252. if response.status_code == 201: # 201 表示创建成功
  253. print("文件上传成功")
  254. return response.json().get("id") # 获取上传的文件 ID
  255. else:
  256. print(f"文件上传失败,状态码: {response.status_code}")
  257. return None
  258. except Exception as e:
  259. print(f"发生错误: {str(e)}")
  260. return None
  261. def run_workflow(file_id, user, response_mode="blocking"):
  262. workflow_url = "https://api.dify.ai/v1/workflows/run"
  263. headers = {
  264. "Authorization": "Bearer app-xxxxxxxxx",
  265. "Content-Type": "application/json"
  266. }
  267. data = {
  268. "inputs": {
  269. "orig_mail": [{
  270. "transfer_method": "local_file",
  271. "upload_file_id": file_id,
  272. "type": "document"
  273. }]
  274. },
  275. "response_mode": response_mode,
  276. "user": user
  277. }
  278. try:
  279. print("运行工作流...")
  280. response = requests.post(workflow_url, headers=headers, json=data)
  281. if response.status_code == 200:
  282. print("工作流执行成功")
  283. return response.json()
  284. else:
  285. print(f"工作流执行失败,状态码: {response.status_code}")
  286. return {"status": "error", "message": f"Failed to execute workflow, status code: {response.status_code}"}
  287. except Exception as e:
  288. print(f"发生错误: {str(e)}")
  289. return {"status": "error", "message": str(e)}
  290. # 使用示例
  291. file_path = "{your_file_path}"
  292. user = "difyuser"
  293. # 上传文件
  294. file_id = upload_file(file_path, user)
  295. if file_id:
  296. # 文件上传成功,继续运行工作流
  297. result = run_workflow(file_id, user)
  298. print(result)
  299. else:
  300. print("文件上传失败,无法执行工作流")
  301. ```
  302. </CodeGroup>
  303. </Col>
  304. </Row>
  305. ---
  306. <Heading
  307. url='/workflows/:workflow_id/run'
  308. method='POST'
  309. title='执行指定版本 workflow'
  310. name='#Execute-Specific-Workflow'
  311. />
  312. <Row>
  313. <Col>
  314. 执行指定版本的工作流,通过路径参数指定工作流ID。
  315. ### Path
  316. - `workflow_id` (string) Required 工作流ID,用于指定特定版本的工作流
  317. 获取方式:可以在版本历史中查询特定版本的工作流ID。
  318. ### Request Body
  319. - `inputs` (object) Required
  320. 允许传入 App 定义的各变量值。
  321. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。变量可以是文件列表类型。
  322. 文件列表类型变量适用于传入文件结合文本理解并回答问题,仅当模型支持该类型文件解析能力时可用。如果该变量是文件列表类型,该变量对应的值应是列表格式,其中每个元素应包含以下内容:
  323. - `type` (string) 支持类型:
  324. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  325. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  326. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
  327. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'MPGA'
  328. - `custom` 具体类型包含:其他文件类型
  329. - `transfer_method` (string) 传递方式,`remote_url` 图片地址 / `local_file` 上传文件
  330. - `url` (string) 图片地址(仅当传递方式为 `remote_url` 时)
  331. - `upload_file_id` (string) 上传文件 ID(仅当传递方式为 `local_file` 时)
  332. - `response_mode` (string) Required
  333. 返回响应模式,支持:
  334. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  335. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  336. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  337. - `user` (string) Required
  338. 用户标识,用于定义终端用户的身份,方便检索、统计。
  339. 由开发者定义规则,需保证用户标识在应用内唯一。API 无法访问 WebApp 创建的会话。
  340. - `files` (array[object]) 可选
  341. - `trace_id` (string) Optional
  342. 链路追踪ID。适用于与业务系统已有的trace组件打通,实现端到端分布式追踪等场景。如果未指定,系统将自动生成 `trace_id`。支持以下三种方式传递,具体优先级依次为:
  343. 1. Header:推荐通过 HTTP Header `X-Trace-Id` 传递,优先级最高。
  344. 2. Query 参数:通过 URL 查询参数 `trace_id` 传递。
  345. 3. Request Body:通过请求体字段 `trace_id` 传递(即本字段)。
  346. ### Response
  347. 当 `response_mode` 为 `blocking` 时,返回 CompletionResponse object。
  348. 当 `response_mode` 为 `streaming`时,返回 ChunkCompletionResponse object 流式序列。
  349. ### CompletionResponse
  350. 返回完整的 App 结果,`Content-Type` 为 `application/json` 。
  351. - `workflow_run_id` (string) workflow 执行 ID
  352. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  353. - `data` (object) 详细内容
  354. - `id` (string) workflow 执行 ID
  355. - `workflow_id` (string) 关联 Workflow ID
  356. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  357. - `outputs` (json) Optional 输出内容
  358. - `error` (string) Optional 错误原因
  359. - `elapsed_time` (float) Optional 耗时(s)
  360. - `total_tokens` (int) Optional 总使用 tokens
  361. - `total_steps` (int) 总步数(冗余),默认 0
  362. - `created_at` (timestamp) 开始时间
  363. - `finished_at` (timestamp) 结束时间
  364. ### ChunkCompletionResponse
  365. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  366. 每个流式块均为 data: 开头,块之间以 `\n\n` 即两个换行符分隔,如下所示:
  367. <CodeGroup>
  368. ```streaming {{ title: 'Response' }}
  369. 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
  370. ```
  371. </CodeGroup>
  372. 流式块中根据 `event` 不同,结构也不同,包含以下类型:
  373. - `event: workflow_started` workflow 开始执行
  374. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  375. - `workflow_run_id` (string) workflow 执行 ID
  376. - `event` (string) 固定为 `workflow_started`
  377. - `data` (object) 详细内容
  378. - `id` (string) workflow 执行 ID
  379. - `workflow_id` (string) 关联 Workflow ID
  380. - `created_at` (timestamp) 开始时间
  381. - `event: node_started` node 开始执行
  382. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  383. - `workflow_run_id` (string) workflow 执行 ID
  384. - `event` (string) 固定为 `node_started`
  385. - `data` (object) 详细内容
  386. - `id` (string) workflow 执行 ID
  387. - `node_id` (string) 节点 ID
  388. - `node_type` (string) 节点类型
  389. - `title` (string) 节点名称
  390. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  391. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  392. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  393. - `created_at` (timestamp) 开始时间
  394. - `event: text_chunk` 文本片段
  395. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  396. - `workflow_run_id` (string) workflow 执行 ID
  397. - `event` (string) 固定为 `text_chunk`
  398. - `data` (object) 详细内容
  399. - `text` (string) 文本内容
  400. - `from_variable_selector` (array) 文本来源路径,帮助开发者了解文本是由哪个节点的哪个变量生成的
  401. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  402. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  403. - `workflow_run_id` (string) workflow 执行 ID
  404. - `event` (string) 固定为 `node_finished`
  405. - `data` (object) 详细内容
  406. - `id` (string) node 执行 ID
  407. - `node_id` (string) 节点 ID
  408. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  409. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  410. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  411. - `process_data` (json) Optional 节点过程数据
  412. - `outputs` (json) Optional 输出内容
  413. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  414. - `error` (string) Optional 错误原因
  415. - `elapsed_time` (float) Optional 耗时(s)
  416. - `execution_metadata` (json) 元数据
  417. - `total_tokens` (int) optional 总使用 tokens
  418. - `total_price` (decimal) optional 总费用
  419. - `currency` (string) optional 货币,如 `USD` / `RMB`
  420. - `created_at` (timestamp) 开始时间
  421. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  422. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  423. - `workflow_run_id` (string) workflow 执行 ID
  424. - `event` (string) 固定为 `workflow_finished`
  425. - `data` (object) 详细内容
  426. - `id` (string) workflow 执行 ID
  427. - `workflow_id` (string) 关联 Workflow ID
  428. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  429. - `outputs` (json) Optional 输出内容
  430. - `error` (string) Optional 错误原因
  431. - `elapsed_time` (float) Optional 耗时(s)
  432. - `total_tokens` (int) Optional 总使用 tokens
  433. - `total_steps` (int) 总步数(冗余),默认 0
  434. - `created_at` (timestamp) 开始时间
  435. - `finished_at` (timestamp) 结束时间
  436. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  437. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  438. - `message_id` (string) 消息唯一 ID
  439. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  440. - `created_at` (int) 创建时间戳,如:1705395332
  441. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  442. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  443. - `message_id` (string) 消息唯一 ID
  444. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  445. - `created_at` (int) 创建时间戳,如:1705395332
  446. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  447. ### Errors
  448. - 400,`invalid_param`,传入参数异常
  449. - 400,`app_unavailable`,App 配置不可用
  450. - 400,`provider_not_initialize`,无可用模型凭据配置
  451. - 400,`provider_quota_exceeded`,模型调用额度不足
  452. - 400,`model_currently_not_support`,当前模型不可用
  453. - 400,`workflow_not_found`,指定的工作流版本未找到
  454. - 400,`draft_workflow_error`,无法使用草稿工作流版本
  455. - 400,`workflow_id_format_error`,工作流ID格式错误,需要UUID格式
  456. - 400,`workflow_request_error`,workflow 执行失败
  457. - 500,服务内部异常
  458. </Col>
  459. <Col sticky>
  460. <CodeGroup title="Request" tag="POST" label="/workflows/:workflow_id/run" targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/{workflow_id}/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`}>
  461. ```bash {{ title: 'cURL' }}
  462. curl -X POST '${props.appDetail.api_base_url}/workflows/{workflow_id}/run' \
  463. --header 'Authorization: Bearer {api_key}' \
  464. --header 'Content-Type: application/json' \
  465. --data-raw '{
  466. "inputs": {},
  467. "response_mode": "streaming",
  468. "user": "abc-123"
  469. }'
  470. ```
  471. </CodeGroup>
  472. <CodeGroup title="Example: file array as an input variable">
  473. ```json {{ title: 'File variable example' }}
  474. {
  475. "inputs": {
  476. "{variable_name}":
  477. [
  478. {
  479. "transfer_method": "local_file",
  480. "upload_file_id": "{upload_file_id}",
  481. "type": "{document_type}"
  482. }
  483. ]
  484. }
  485. }
  486. ```
  487. </CodeGroup>
  488. ### Blocking Mode
  489. <CodeGroup title="Response">
  490. ```json {{ title: 'Response' }}
  491. {
  492. "workflow_run_id": "djflajgkldjgd",
  493. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  494. "data": {
  495. "id": "fdlsjfjejkghjda",
  496. "workflow_id": "fldjaslkfjlsda",
  497. "status": "succeeded",
  498. "outputs": {
  499. "text": "Nice to meet you."
  500. },
  501. "error": null,
  502. "elapsed_time": 0.875,
  503. "total_tokens": 3562,
  504. "total_steps": 8,
  505. "created_at": 1705407629,
  506. "finished_at": 1727807631
  507. }
  508. }
  509. ```
  510. </CodeGroup>
  511. ### Streaming Mode
  512. <CodeGroup title="Response">
  513. ```streaming {{ title: 'Response' }}
  514. data: {"event": "workflow_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "created_at": 1679586595}}
  515. 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}}
  516. 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}}
  517. 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}}
  518. 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"}
  519. 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": ""}
  520. ```
  521. </CodeGroup>
  522. </Col>
  523. </Row>
  524. ---
  525. <Heading
  526. url='/workflows/run/:workflow_run_id'
  527. method='GET'
  528. title='获取workflow执行情况'
  529. name='#get-workflow-run-detail'
  530. />
  531. <Row>
  532. <Col>
  533. 根据 workflow 执行 ID 获取 workflow 任务当前执行结果
  534. ### Path
  535. - `workflow_run_id` (string) workflow 执行 ID,可在流式返回 Chunk 中获取
  536. ### Response
  537. - `id` (string) workflow 执行 ID
  538. - `workflow_id` (string) 关联的 Workflow ID
  539. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  540. - `inputs` (json) 任务输入内容
  541. - `outputs` (json) 任务输出内容
  542. - `error` (string) 错误原因
  543. - `total_steps` (int) 任务执行总步数
  544. - `total_tokens` (int) 任务执行总 tokens
  545. - `created_at` (timestamp) 任务开始时间
  546. - `finished_at` (timestamp) 任务结束时间
  547. - `elapsed_time` (float) 耗时 (s)
  548. </Col>
  549. <Col sticky>
  550. ### Request Example
  551. <CodeGroup title="Request" tag="GET" label="/workflows/run/:workflow_run_id" targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json'`}>
  552. ```bash {{ title: 'cURL' }}
  553. curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id' \
  554. -H 'Authorization: Bearer {api_key}' \
  555. -H 'Content-Type: application/json'
  556. ```
  557. </CodeGroup>
  558. ### Response Example
  559. <CodeGroup title="Response">
  560. ```json {{ title: 'Response' }}
  561. {
  562. "id": "b1ad3277-089e-42c6-9dff-6820d94fbc76",
  563. "workflow_id": "19eff89f-ec03-4f75-b0fc-897e7effea02",
  564. "status": "succeeded",
  565. "inputs": "{\"sys.files\": [], \"sys.user_id\": \"abc-123\"}",
  566. "outputs": null,
  567. "error": null,
  568. "total_steps": 3,
  569. "total_tokens": 0,
  570. "created_at": 1705407629,
  571. "finished_at": 1727807631,
  572. "elapsed_time": 30.098514399956912
  573. }
  574. ```
  575. </CodeGroup>
  576. </Col>
  577. </Row>
  578. ---
  579. <Heading
  580. url='/workflows/tasks/:task_id/stop'
  581. method='POST'
  582. title='停止响应'
  583. name='#stop-generatebacks'
  584. />
  585. <Row>
  586. <Col>
  587. 仅支持流式模式。
  588. ### Path
  589. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  590. ### Request Body
  591. - `user` (string) Required
  592. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。API 无法访问 WebApp 创建的会话。
  593. ### Response
  594. - `result` (string) 固定返回 "success"
  595. </Col>
  596. <Col sticky>
  597. ### Request Example
  598. <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"}'`}>
  599. ```bash {{ title: 'cURL' }}
  600. curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \
  601. -H 'Authorization: Bearer {api_key}' \
  602. -H 'Content-Type: application/json' \
  603. --data-raw '{
  604. "user": "abc-123"
  605. }'
  606. ```
  607. </CodeGroup>
  608. ### Response Example
  609. <CodeGroup title="Response">
  610. ```json {{ title: 'Response' }}
  611. {
  612. "result": "success"
  613. }
  614. ```
  615. </CodeGroup>
  616. </Col>
  617. </Row>
  618. ---
  619. <Heading
  620. url='/files/upload'
  621. method='POST'
  622. title='上传文件'
  623. name='#files-upload'
  624. />
  625. <Row>
  626. <Col>
  627. 上传文件并在发送消息时使用,可实现图文多模态理解。
  628. 支持您的工作流程所支持的任何格式。
  629. <i>上传的文件仅供当前终端用户使用。</i>
  630. ### Request Body
  631. 该接口需使用 `multipart/form-data` 进行请求。
  632. <Properties>
  633. <Property name='file' type='file' key='file'>
  634. 要上传的文件。
  635. </Property>
  636. <Property name='user' type='string' key='user'>
  637. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。服务 API 不会共享 WebApp 创建的对话。
  638. </Property>
  639. </Properties>
  640. ### Response
  641. 成功上传后,服务器会返回文件的 ID 和相关信息。
  642. - `id` (uuid) ID
  643. - `name` (string) 文件名
  644. - `size` (int) 文件大小(byte)
  645. - `extension` (string) 文件后缀
  646. - `mime_type` (string) 文件 mime-type
  647. - `created_by` (uuid) 上传人 ID
  648. - `created_at` (timestamp) 上传时间
  649. ### Errors
  650. - 400,`no_file_uploaded`,必须提供文件
  651. - 400,`too_many_files`,目前只接受一个文件
  652. - 400,`unsupported_preview`,该文件不支持预览
  653. - 400,`unsupported_estimate`,该文件不支持估算
  654. - 413,`file_too_large`,文件太大
  655. - 415,`unsupported_file_type`,不支持的扩展名,当前只接受文档类文件
  656. - 503,`s3_connection_failed`,无法连接到 S3 服务
  657. - 503,`s3_permission_denied`,无权限上传文件到 S3
  658. - 503,`s3_file_too_large`,文件超出 S3 大小限制
  659. </Col>
  660. <Col sticky>
  661. <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'`}>
  662. ```bash {{ title: 'cURL' }}
  663. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  664. --header 'Authorization: Bearer {api_key}' \
  665. --form 'file=@"/path/to/file"'
  666. ```
  667. </CodeGroup>
  668. <CodeGroup title="Response">
  669. ```json {{ title: 'Response' }}
  670. {
  671. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  672. "name": "example.png",
  673. "size": 1024,
  674. "extension": "png",
  675. "mime_type": "image/png",
  676. "created_by": 123,
  677. "created_at": 1577836800,
  678. }
  679. ```
  680. </CodeGroup>
  681. </Col>
  682. </Row>
  683. ---
  684. <Heading
  685. url='/files/:file_id/preview'
  686. method='GET'
  687. title='文件预览'
  688. name='#file-preview'
  689. />
  690. <Row>
  691. <Col>
  692. 预览或下载已上传的文件。此端点允许您访问先前通过文件上传 API 上传的文件。
  693. <i>文件只能在属于请求应用程序的消息范围内访问。</i>
  694. ### 路径参数
  695. - `file_id` (string) 必需
  696. 要预览的文件的唯一标识符,从文件上传 API 响应中获得。
  697. ### 查询参数
  698. - `as_attachment` (boolean) 可选
  699. 是否强制将文件作为附件下载。默认为 `false`(在浏览器中预览)。
  700. ### 响应
  701. 返回带有适当浏览器显示或下载标头的文件内容。
  702. - `Content-Type` 根据文件 MIME 类型设置
  703. - `Content-Length` 文件大小(以字节为单位,如果可用)
  704. - `Content-Disposition` 如果 `as_attachment=true` 则设置为 "attachment"
  705. - `Cache-Control` 用于性能的缓存标头
  706. - `Accept-Ranges` 对于音频/视频文件设置为 "bytes"
  707. ### 错误
  708. - 400, `invalid_param`, 参数输入异常
  709. - 403, `file_access_denied`, 文件访问被拒绝或文件不属于当前应用程序
  710. - 404, `file_not_found`, 文件未找到或已被删除
  711. - 500, 服务内部错误
  712. </Col>
  713. <Col sticky>
  714. ### 请求示例
  715. <CodeGroup title="Request" tag="GET" label="/files/:file_id/preview" targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview' \\\n--header 'Authorization: Bearer {api_key}'`}>
  716. ```bash {{ title: 'cURL' }}
  717. curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview' \
  718. --header 'Authorization: Bearer {api_key}'
  719. ```
  720. </CodeGroup>
  721. ### 作为附件下载
  722. <CodeGroup title="Request" tag="GET" label="/files/:file_id/preview?as_attachment=true" targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview?as_attachment=true' \\\\\\n--header 'Authorization: Bearer {api_key}' \\\\\\n--output downloaded_file.png`}>
  723. ```bash {{ title: 'cURL' }}
  724. curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview?as_attachment=true' \
  725. --header 'Authorization: Bearer {api_key}' \
  726. --output downloaded_file.png
  727. ```
  728. </CodeGroup>
  729. ### 响应标头示例
  730. <CodeGroup title="Response Headers">
  731. ```http {{ title: 'Headers - 图片预览' }}
  732. Content-Type: image/png
  733. Content-Length: 1024
  734. Cache-Control: public, max-age=3600
  735. ```
  736. </CodeGroup>
  737. ### 文件下载响应标头
  738. <CodeGroup title="Download Response Headers">
  739. ```http {{ title: 'Headers - 文件下载' }}
  740. Content-Type: image/png
  741. Content-Length: 1024
  742. Content-Disposition: attachment; filename*=UTF-8''example.png
  743. Cache-Control: public, max-age=3600
  744. ```
  745. </CodeGroup>
  746. </Col>
  747. </Row>
  748. ---
  749. <Heading
  750. url='/workflows/logs'
  751. method='GET'
  752. title='获取 workflow 日志'
  753. name='#Get-Workflow-Logs'
  754. />
  755. <Row>
  756. <Col>
  757. 倒序返回 workflow 日志
  758. ### Query
  759. <Properties>
  760. <Property name='keyword' type='string' key='keyword'>
  761. 关键字
  762. </Property>
  763. <Property name='status' type='string' key='status'>
  764. 执行状态 succeeded/failed/stopped
  765. </Property>
  766. <Property name='page' type='int' key='page'>
  767. 当前页码, 默认1.
  768. </Property>
  769. <Property name='limit' type='int' key='limit'>
  770. 每页条数, 默认20.
  771. </Property>
  772. <Property name='created_by_end_user_session_id' type='str' key='created_by_end_user_session_id'>
  773. 由哪个endUser创建,例如,`abc-123`.
  774. </Property>
  775. <Property name='created_by_account' type='str' key='created_by_account'>
  776. 由哪个邮箱账户创建,例如,lizb@test.com.
  777. </Property>
  778. </Properties>
  779. ### Response
  780. - `page` (int) 当前页码
  781. - `limit` (int) 每页条数
  782. - `total` (int) 总条数
  783. - `has_more` (bool) 是否还有更多数据
  784. - `data` (array[object]) 当前页码的数据
  785. - `id` (string) 标识
  786. - `workflow_run` (object) Workflow 执行日志
  787. - `id` (string) 标识
  788. - `version` (string) 版本
  789. - `status` (string) 执行状态,`running` / `succeeded` / `failed` / `stopped`
  790. - `error` (string) (可选) 错误
  791. - `elapsed_time` (float) 耗时,单位秒
  792. - `total_tokens` (int) 消耗的 token 数量
  793. - `total_steps` (int) 执行步骤长度
  794. - `created_at` (timestamp) 开始时间
  795. - `finished_at` (timestamp) 结束时间
  796. - `created_from` (string) 来源
  797. - `created_by_role` (string) 角色
  798. - `created_by_account` (string) (可选) 帐号
  799. - `created_by_end_user` (object) 用户
  800. - `id` (string) 标识
  801. - `type` (string) 类型
  802. - `is_anonymous` (bool) 是否匿名
  803. - `session_id` (string) 会话标识
  804. - `created_at` (timestamp) 创建时间
  805. </Col>
  806. <Col sticky>
  807. <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}'`}>
  808. ```bash {{ title: 'cURL' }}
  809. curl -X GET '${props.appDetail.api_base_url}/workflows/logs?limit=1'
  810. --header 'Authorization: Bearer {api_key}'
  811. ```
  812. </CodeGroup>
  813. ### Response Example
  814. <CodeGroup title="Response">
  815. ```json {{ title: 'Response' }}
  816. {
  817. "page": 1,
  818. "limit": 1,
  819. "total": 7,
  820. "has_more": true,
  821. "data": [
  822. {
  823. "id": "e41b93f1-7ca2-40fd-b3a8-999aeb499cc0",
  824. "workflow_run": {
  825. "id": "c0640fc8-03ef-4481-a96c-8a13b732a36e",
  826. "version": "2024-08-01 12:17:09.771832",
  827. "status": "succeeded",
  828. "error": null,
  829. "elapsed_time": 1.3588523610014818,
  830. "total_tokens": 0,
  831. "total_steps": 3,
  832. "created_at": 1726139643,
  833. "finished_at": 1726139644
  834. },
  835. "created_from": "service-api",
  836. "created_by_role": "end_user",
  837. "created_by_account": null,
  838. "created_by_end_user": {
  839. "id": "7f7d9117-dd9d-441d-8970-87e5e7e687a3",
  840. "type": "service_api",
  841. "is_anonymous": false,
  842. "session_id": "abc-123"
  843. },
  844. "created_at": 1726139644
  845. }
  846. ]
  847. }
  848. ```
  849. </CodeGroup>
  850. </Col>
  851. </Row>
  852. ---
  853. <Heading
  854. url='/info'
  855. method='GET'
  856. title='获取应用基本信息'
  857. name='#info'
  858. />
  859. <Row>
  860. <Col>
  861. 用于获取应用的基本信息
  862. ### Response
  863. - `name` (string) 应用名称
  864. - `description` (string) 应用描述
  865. - `tags` (array[string]) 应用标签
  866. - `mode` (string) 应用模式
  867. - 'author_name' (string) 作者名称
  868. </Col>
  869. <Col>
  870. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  871. ```bash {{ title: 'cURL' }}
  872. curl -X GET '${props.appDetail.api_base_url}/info' \
  873. -H 'Authorization: Bearer {api_key}'
  874. ```
  875. </CodeGroup>
  876. <CodeGroup title="Response">
  877. ```json {{ title: 'Response' }}
  878. {
  879. "name": "My App",
  880. "description": "This is my app.",
  881. "tags": [
  882. "tag1",
  883. "tag2"
  884. ],
  885. "mode": "workflow",
  886. "author_name": "Dify"
  887. }
  888. ```
  889. </CodeGroup>
  890. </Col>
  891. </Row>
  892. ---
  893. <Heading
  894. url='/parameters'
  895. method='GET'
  896. title='获取应用参数'
  897. name='#parameters'
  898. />
  899. <Row>
  900. <Col>
  901. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  902. ### Response
  903. - `user_input_form` (array[object]) 用户输入表单配置
  904. - `text-input` (object) 文本输入控件
  905. - `label` (string) 控件展示标签名
  906. - `variable` (string) 控件 ID
  907. - `required` (bool) 是否必填
  908. - `default` (string) 默认值
  909. - `paragraph` (object) 段落文本输入控件
  910. - `label` (string) 控件展示标签名
  911. - `variable` (string) 控件 ID
  912. - `required` (bool) 是否必填
  913. - `default` (string) 默认值
  914. - `select` (object) 下拉控件
  915. - `label` (string) 控件展示标签名
  916. - `variable` (string) 控件 ID
  917. - `required` (bool) 是否必填
  918. - `default` (string) 默认值
  919. - `options` (array[string]) 选项值
  920. - `file_upload` (object) 文件上传配置
  921. - `document` (object) 文档设置
  922. 当前仅支持文档类型:`txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`。
  923. - `enabled` (bool) 是否启用
  924. - `number_limits` (int) 文档数量限制,默认为 3
  925. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  926. - `image` (object) 图片设置
  927. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`。
  928. - `enabled` (bool) 是否启用
  929. - `number_limits` (int) 图片数量限制,默认为 3
  930. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  931. - `audio` (object) 音频设置
  932. 当前仅支持音频类型:`mp3`, `m4a`, `wav`, `webm`, `amr`。
  933. - `enabled` (bool) 是否启用
  934. - `number_limits` (int) 音频数量限制,默认为 3
  935. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  936. - `video` (object) 视频设置
  937. 当前仅支持视频类型:`mp4`, `mov`, `mpeg`, `mpga`。
  938. - `enabled` (bool) 是否启用
  939. - `number_limits` (int) 视频数量限制,默认为 3
  940. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  941. - `custom` (object) 自定义设置
  942. - `enabled` (bool) 是否启用
  943. - `number_limits` (int) 自定义数量限制,默认为 3
  944. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  945. - `system_parameters` (object) 系统参数
  946. - `file_size_limit` (int) 文档上传大小限制 (MB)
  947. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  948. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  949. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  950. </Col>
  951. <Col sticky>
  952. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  953. ```bash {{ title: 'cURL' }}
  954. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  955. --header 'Authorization: Bearer {api_key}'
  956. ```
  957. </CodeGroup>
  958. <CodeGroup title="Response">
  959. ```json {{ title: 'Response' }}
  960. {
  961. "user_input_form": [
  962. {
  963. "paragraph": {
  964. "label": "Query",
  965. "variable": "query",
  966. "required": true,
  967. "default": ""
  968. }
  969. }
  970. ],
  971. "file_upload": {
  972. "image": {
  973. "enabled": false,
  974. "number_limits": 3,
  975. "detail": "high",
  976. "transfer_methods": [
  977. "remote_url",
  978. "local_file"
  979. ]
  980. }
  981. },
  982. "system_parameters": {
  983. "file_size_limit": 15,
  984. "image_file_size_limit": 10,
  985. "audio_file_size_limit": 50,
  986. "video_file_size_limit": 100
  987. }
  988. }
  989. ```
  990. </CodeGroup>
  991. </Col>
  992. </Row>
  993. ---
  994. <Heading
  995. url='/site'
  996. method='GET'
  997. title='获取应用 WebApp 设置'
  998. name='#site'
  999. />
  1000. <Row>
  1001. <Col>
  1002. 用于获取应用的 WebApp 设置
  1003. ### Response
  1004. - `title` (string) WebApp 名称
  1005. - `icon_type` (string) 图标类型,`emoji`-表情,`image`-图片
  1006. - `icon` (string) 图标,如果是 `emoji` 类型,则是 emoji 表情符号,如果是 `image` 类型,则是图片 URL
  1007. - `icon_background` (string) hex 格式的背景色
  1008. - `icon_url` (string) 图标 URL
  1009. - `description` (string) 描述
  1010. - `copyright` (string) 版权信息
  1011. - `privacy_policy` (string) 隐私政策链接
  1012. - `custom_disclaimer` (string) 自定义免责声明
  1013. - `default_language` (string) 默认语言
  1014. - `show_workflow_steps` (bool) 是否显示工作流详情
  1015. </Col>
  1016. <Col>
  1017. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1018. ```bash {{ title: 'cURL' }}
  1019. curl -X GET '${props.appDetail.api_base_url}/site' \
  1020. -H 'Authorization: Bearer {api_key}'
  1021. ```
  1022. </CodeGroup>
  1023. <CodeGroup title="Response">
  1024. ```json {{ title: 'Response' }}
  1025. {
  1026. "title": "My App",
  1027. "icon_type": "emoji",
  1028. "icon": "😄",
  1029. "icon_background": "#FFEAD5",
  1030. "icon_url": null,
  1031. "description": "This is my app.",
  1032. "copyright": "all rights reserved",
  1033. "privacy_policy": "",
  1034. "custom_disclaimer": "All generated by AI",
  1035. "default_language": "en-US",
  1036. "show_workflow_steps": false,
  1037. }
  1038. ```
  1039. </CodeGroup>
  1040. </Col>
  1041. </Row>
  1042. ___