跳到主要内容

Build endpoints

important

/build 端点由 Langflow 的前端可视化编辑器代码使用。 这些端点是 Langflow 内部代码库的一部分。

不要在应用程序中使用这些端点来运行您的 Langflow 流。 要在您的应用程序中运行流,请参阅 Flow trigger endpoints

/build 端点支持 Langflow 前端代码,用于在 Langflow 可视化编辑器中构建流。 您可以使用这些端点来构建顶点和流,以及执行流并返回流式事件响应。 在为 Langflow 代码库做贡献时,您可能需要使用或理解这些端点。

构建流和流式事件

此端点构建并执行一个流,返回一个可用于流式执行事件的作业 ID。

  1. /build/$FLOW_ID/flow 端点发送 POST 请求:


    _10
    curl -X POST \
    _10
    "$LANGFLOW_URL/api/v1/build/$FLOW_ID/flow" \
    _10
    -H "accept: application/json" \
    _10
    -H "Content-Type: application/json" \
    _10
    -H "x-api-key: $LANGFLOW_API_KEY" \
    _10
    -d '{
    _10
    "inputs": {
    _10
    "input_value": "Tell me a story"
    _10
    }
    _10
    }'

    结果

    _10
    {
    _10
    "job_id": "123e4567-e89b-12d3-a456-426614174000"
    _10
    }

  2. 从构建端点接收到作业 ID 后,使用 /build/$JOB_ID/events 端点来流式传输执行结果:


    _10
    curl -X GET \
    _10
    "$LANGFLOW_URL/api/v1/build/123e4567-e89b-12d3-a456-426614174000/events" \
    _10
    -H "accept: application/json" \
    _10
    -H "x-api-key: $LANGFLOW_API_KEY"

    结果

    _10
    {"event": "vertices_sorted", "data": {"ids": ["ChatInput-XtBLx"], "to_run": ["Prompt-x74Ze", "ChatOutput-ylMzN", "ChatInput-XtBLx", "OpenAIModel-d1wOZ"]}}
    _10
    _10
    {"event": "add_message", "data": {"timestamp": "2025-03-03T17:42:23", "sender": "User", "sender_name": "User", "session_id": "d2bbd92b-187e-4c84-b2d4-5df365704201", "text": "Tell me a story", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "28879bd8-6a68-4dd5-b658-74d643a4dd92", "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201"}}
    _10
    _10
    // ... 流执行过程中的其他事件 ...
    _10
    _10
    {"event": "end", "data": {}}

/build/$FLOW_ID/events 端点有一个 stream 查询参数,默认为 true。 要禁用流式传输并一次性获取所有事件,请设置 ?stream=false


_10
curl -X GET \
_10
"$LANGFLOW_URL/api/v1/build/123e4567-e89b-12d3-a456-426614174000/events?stream=false" \
_10
-H "accept: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY"

构建请求头

HeaderInfoExample
Content-TypeRequired. Specifies the JSON format."application/json"
acceptOptional. Specifies the response format."application/json"
x-api-keyOptional. Required only if authentication is enabled."sk-..."

构建参数

ParameterTypeDescription
inputsobjectOptional. Input values for flow components.
dataobjectOptional. Flow data to override stored configuration.
filesarray[string]Optional. List of file paths to use.
start_component_idstringOptional. ID of the component where the execution should start. Component id values can be found in Langflow JSON files
stop_component_idstringOptional. ID of the component where the execution should stop. Component id values can be found in Langflow JSON files.
log_buildsBooleanWhether to record build logs. Default: Enabled (true).

设置开始和停止点

/build 端点接受 start_component_idstop_component_id 的可选值,以控制流运行的开始和停止位置。 为组件设置 stop_component_id 会触发与在可视化编辑器中对该组件点击 Run component 相同的行为:指定的组件以及所有依赖于此组件的组件都将运行。

以下示例在 OpenAI 组件处停止流执行:


_10
curl -X POST \
_10
"$LANGFLOW_URL/api/v1/build/$FLOW_ID/flow" \
_10
-H "accept: application/json" \
_10
-H "Content-Type: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY" \
_10
-d '{"stop_component_id": "OpenAIModel-Uksag"}'

覆盖流参数

/build 端点也直接接受 data 的输入,而不是使用存储在 Langflow 数据库中的值。 这对于运行流而不必通过可视化编辑器传递自定义值很有用。


_15
curl -X POST \
_15
"$LANGFLOW_URL/api/v1/build/$FLOW_ID/flow" \
_15
-H "accept: application/json" \
_15
-H "Content-Type: application/json" \
_15
-H "x-api-key: $LANGFLOW_API_KEY" \
_15
-d '{
_15
"data": {
_15
"nodes": [],
_15
"edges": []
_15
},
_15
"inputs": {
_15
"input_value": "Your custom input here",
_15
"session": "session_id"
_15
}
_15
}'

结果

_10
{ "job_id": "0bcc7f23-40b4-4bfa-9b8a-a44181fd1175" }

另请参阅

Search