Appearance
工作流执行
执行已发布的工作流,并返回执行结果。支持两种响应模式:
blocking:同步等待执行完成后返回 JSONstreaming:通过 SSE 持续返回执行事件接口路径:
POST /v1/openapi/workflow/invoke
请求头
| 参数名 | 必填 | 说明 |
|---|---|---|
| Content-Type | 是 | application/json |
| Authorization | 是 | 鉴权凭证,格式 Bearer sk_xxx |
请求参数
json
{
"workflow_id": "1368b2d9-60ff-48fc-9f14-0c39711896ef",
"input": {"input": "华西"},
"parameters": {"input": "华西"},
"response_mode": "blocking"
}| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| workflow_id | string(uuid) | 是 | 工作流 ID,必须是合法 UUID |
| input | any | 否 | 工作流输入参数,优先级高于 parameters |
| parameters | any | 否 | 兼容字段;当 input 未传时作为工作流输入 |
| response_mode | string | 否 | blocking 或 streaming;不传时默认为 streaming |
输入归一化规则
服务端会将 input 或 parameters 归一化为 map[string]any 后执行工作流。
| 传入值 | 实际输入 |
|---|---|
input 未传且 parameters 未传 | {"input": ""} |
input 为 null 且 parameters 有值 | 使用 parameters |
{} | {"input": ""} |
"hello" | {"input": "hello"} |
"{\"city\":\"上海\"}" | {"city": "上海"} |
{"city":"上海"} | 原样透传 |
| 数字、布尔、数组等其他 JSON 值 | {"input": value} |
blocking 响应
当 response_mode=blocking 时,接口同步返回执行结果。
成功响应
json
{
"code": 200,
"message": "success",
"data": {
"workflow_id": "1368b2d9-60ff-48fc-9f14-0c39711896ef",
"execute_id": "fe421aca-d4d8-4084-b1b8-4e107bf4d4c2",
"status": "success",
"output": {
"output": "华西通常指四川大学华西医院。"
},
"final_output": "华西通常指四川大学华西医院。",
"token": 202,
"cost": "0.00000"
},
"trace_id": "e3302bb5788035dec7160e58d2261824"
}| 字段 | 类型 | 说明 |
|---|---|---|
| workflow_id | string(uuid) | 工作流 ID |
| execute_id | string(uuid) | 本次执行 ID |
| status | string | 执行状态,成功为 success |
| output | object | 工作流完整输出 |
| final_output | any | 对外最终结果;优先取 output.output,其次取 output.result,单字段输出时取唯一字段值 |
| token | int64 | 本次执行总 token |
| cost | string | 成本信息 |
失败响应
json
{
"code": 0,
"message": "工作流运行失败",
"data": null,
"trace_id": "e3302bb5788035dec7160e58d2261824"
}常见业务失败包括:
无效的workflow_id无效的response_mode参数, 只支持blocking或streaming- 工作流执行失败时返回具体失败信息
streaming 响应
当 response_mode=streaming 或 response_mode 未传时,返回 SSE 事件流。
SSE 响应头
text
Content-Type: text/event-stream; charset=utf-8
Cache-Control: no-cache
Connection: keep-alive
X-Accel-Buffering: no事件格式
text
id: <message_id>
event: <event_name>
data: <json_payload>事件类型
| 事件名 | 说明 |
|---|---|
Message | 工作流输出内容 |
NodeStart | 节点开始执行 |
NodeEnd | 节点执行结束 |
Done | 工作流成功结束 |
Error | 工作流失败或取消 |
Interrupt | 工作流中断等待处理 |
error | SSE 读取异常 |
事件字段
不同事件会返回不同字段,客户端应按需读取。
| 字段 | 类型 | 说明 |
|---|---|---|
| execute_id | string(uuid) | 执行 ID |
| workflow_id | string(uuid) | 工作流 ID |
| status | string | 工作流或节点状态 |
| content | string | Message 事件的输出内容 |
| content_type | string | 内容类型,当前常见为 text |
| node_seq_id | string | 同一节点内的消息序号 |
| node_id | string | 节点 ID |
| node_is_finish | bool | 当前节点输出是否结束 |
| node_type | string | 节点类型 |
| node_title | string | 节点标题 |
| node_status | string | 节点状态,常见为 running、success、fail |
| input | any | 节点输入 |
| output | any | 节点输出 |
| raw_output | any | 节点原始输出 |
| duration | int64 | 节点耗时,单位毫秒 |
| error_info | string | 节点错误信息 |
| error_level | string | 错误级别 |
| token | int64 | token 总数 |
| token_info | object | token 明细,见下方 token_info 字段说明 |
| debug_url | string | 调试链接 |
| error_code | int64 | 错误码 |
| error_message | string | 错误信息 |
| interrupt_data | object | 中断事件数据,见下方 interrupt_data 字段说明 |
token_info 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| input_tokens | int64 | 输入 token 数 |
| output_tokens | int64 | 输出 token 数 |
| total_tokens | int64 | 总 token 数 |
interrupt_data 字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| event_id | string | 中断事件 ID,格式为 {execute_id}/{interrupt_event_id} |
| type | int64 | 中断事件类型,1-问题中断,2-输入节点中断,100-LLM 中断 |
| data | string | 中断数据 |
SSE 示例
text
id: 0
event: NodeStart
data: {"execute_id":"fe421aca-d4d8-4084-b1b8-4e107bf4d4c2","workflow_id":"1368b2d9-60ff-48fc-9f14-0c39711896ef","content_type":"text","node_seq_id":"0","node_id":"start","node_is_finish":false,"node_type":"Start","node_title":"开始","node_status":"running","input":{"input":"华西"}}
id: 1
event: Message
data: {"execute_id":"fe421aca-d4d8-4084-b1b8-4e107bf4d4c2","workflow_id":"1368b2d9-60ff-48fc-9f14-0c39711896ef","content":"华西通常指四川大学华西医院。","content_type":"text","node_seq_id":"0","node_id":"answer","node_is_finish":false,"node_type":"Answer","node_title":"回复","token":202,"token_info":{"input_tokens":31,"output_tokens":171,"total_tokens":202}}
id: 2
event: Done
data: {"execute_id":"fe421aca-d4d8-4084-b1b8-4e107bf4d4c2","workflow_id":"1368b2d9-60ff-48fc-9f14-0c39711896ef","status":"success","debug_url":"/workflow/debug?execute_id=fe421aca-d4d8-4084-b1b8-4e107bf4d4c2&workflow_id=1368b2d9-60ff-48fc-9f14-0c39711896ef"}中断示例
text
id: 3
event: Interrupt
data: {"execute_id":"fe421aca-d4d8-4084-b1b8-4e107bf4d4c2","workflow_id":"1368b2d9-60ff-48fc-9f14-0c39711896ef","status":"interrupted","debug_url":"/workflow/debug?execute_id=fe421aca-d4d8-4084-b1b8-4e107bf4d4c2&workflow_id=1368b2d9-60ff-48fc-9f14-0c39711896ef","interrupt_data":{"event_id":"fe421aca-d4d8-4084-b1b8-4e107bf4d4c2/01965de1-1920-7fe4-aa38-2e6836c46f22","type":1,"data":"..."}}调用示例
blocking
bash
curl -X POST 'https://runtime-api.invalid/v1/openapi/workflow/invoke' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk_your_api_key' \
-d '{
"workflow_id": "1368b2d9-60ff-48fc-9f14-0c39711896ef",
"input": {"input": "华西"},
"response_mode": "blocking"
}'streaming
bash
curl -N -X POST 'https://runtime-api.invalid/v1/openapi/workflow/invoke' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk_your_api_key' \
-d '{
"workflow_id": "1368b2d9-60ff-48fc-9f14-0c39711896ef",
"parameters": {"input": "华西"},
"response_mode": "streaming"
}'