> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 运行流水线

> 为知识库执行完整的知识流水线。支持流式和阻塞两种响应模式。



## OpenAPI

````yaml /zh/api-reference/openapi_knowledge.json post /datasets/{dataset_id}/pipeline/run
openapi: 3.0.1
info:
  title: 知识库 API
  description: >-
    用于管理知识库、文档、分段、元数据和标签的 API，包括创建、检索和配置操作。**注意：**单个知识库 API
    密钥有权操作同一账户下所有可见的知识库。请注意数据安全。
  version: 1.0.0
servers:
  - url: https://{api_base_url}
    description: Knowledge API 的基础 URL。自部署时，替换为你的 API 基础 URL。
    variables:
      api_base_url:
        default: api.dify.ai/v1
        description: API 基础 URL 的主机与路径，不含 `https://` 前缀。
security:
  - ApiKeyAuth: []
tags:
  - name: 知识库
    description: 用于管理知识库的操作，包括创建、配置和检索。
  - name: 文档
    description: 用于在知识库中创建、更新和管理文档的操作。
  - name: 分段
    description: 用于管理分段和子分段的操作。
  - name: 元数据
    description: 用于管理知识库元数据字段和文档元数据值的操作。
  - name: 标签
    description: 用于管理知识库标签和标签绑定的操作。
  - name: 模型
    description: 用于获取可用模型的操作。
  - name: 知识流水线
    description: 用于管理和运行知识流水线的操作，包括数据源插件和流水线执行。
paths:
  /datasets/{dataset_id}/pipeline/run:
    post:
      tags:
        - 知识流水线
      summary: 运行流水线
      description: 为知识库执行完整的知识流水线。支持流式和阻塞两种响应模式。
      operationId: runPipelineZh
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: 知识库 ID。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - inputs
                - datasource_type
                - datasource_info_list
                - start_node_id
                - is_published
                - response_mode
              properties:
                inputs:
                  type: object
                  additionalProperties: true
                  description: 流水线输入变量的键值对，对应工作流中定义的流水线变量。如果流水线没有输入变量，传 `{}`。
                datasource_type:
                  type: string
                  enum:
                    - local_file
                    - online_document
                    - website_crawl
                    - online_drive
                  description: 数据源类型。决定 `datasource_info_list` 中条目所需的字段。
                datasource_info_list:
                  type: array
                  description: 待处理的数据源对象列表。条目结构取决于 `datasource_type`。
                  items:
                    oneOf:
                      - title: Local File
                        type: object
                        required:
                          - reference
                        properties:
                          reference:
                            type: string
                            description: >-
                              使用 [上传流水线文件](/api-reference/知识流水线/上传流水线文件) 端点返回的
                              `id`。`related_id` 可作为别名使用。
                          name:
                            type: string
                            description: 文档标题。默认为 `"untitled"`。
                      - title: Online Document
                        type: object
                        required:
                          - workspace_id
                          - page
                        properties:
                          workspace_id:
                            type: string
                            description: 外部平台中的工作空间或数据库 ID（例如 Notion 工作空间 ID）。
                          page:
                            type: object
                            description: 页面详情。
                            required:
                              - page_id
                              - type
                            properties:
                              page_id:
                                type: string
                                description: 页面标识符。
                              type:
                                type: string
                                description: 由数据源插件定义的页面类型（例如 `"page"`、`"database"`）。
                              page_name:
                                type: string
                                description: 显示名称。默认为 `"untitled"`。
                          credential_id:
                            type: string
                            description: 用于与外部平台认证的凭证。通过 Dify 控制台管理。如省略，则使用该供应商的默认凭证。
                      - title: Website Crawl
                        type: object
                        required:
                          - url
                        properties:
                          url:
                            type: string
                            description: 待爬取的 URL。
                          title:
                            type: string
                            description: 用作文档名称。默认为 `"untitled"`。
                      - title: Online Drive
                        type: object
                        required:
                          - id
                          - type
                        properties:
                          id:
                            type: string
                            description: 文件或文件夹 ID。
                          type:
                            type: string
                            enum:
                              - file
                              - folder
                            description: 该条目是单个文件还是待展开的文件夹。
                          bucket:
                            type: string
                            description: 存储桶名称。部分存储供应商需要此字段（例如 S3 兼容存储）；如果供应商不使用存储桶，可省略。
                          name:
                            type: string
                            description: 文件名称。默认为 `"untitled"`。
                start_node_id:
                  type: string
                  description: 流水线开始执行的数据源节点 ID。
                is_published:
                  type: boolean
                  description: >-
                    运行流水线的已发布版本还是草稿版本。`true` 运行最新已发布版本；`false`
                    运行当前草稿（适用于测试未发布的更改）。
                response_mode:
                  type: string
                  enum:
                    - streaming
                    - blocking
                  description: 流水线执行的响应模式。`streaming` 返回服务器发送事件流，`blocking` 等待并返回完整结果。
            examples:
              local_file:
                summary: 请求示例—本地文件
                value:
                  inputs: {}
                  datasource_type: local_file
                  datasource_info_list:
                    - reference: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                      name: quarterly-report.pdf
                  start_node_id: '1719288585006'
                  is_published: true
                  response_mode: blocking
              online_document:
                summary: 请求示例—在线文档
                value:
                  inputs: {}
                  datasource_type: online_document
                  datasource_info_list:
                    - workspace_id: ws-abc123
                      page:
                        page_id: pg-def456
                        type: page
                        page_name: Product Roadmap
                      credential_id: cred-789xyz
                  start_node_id: '1719288585006'
                  is_published: true
                  response_mode: streaming
              website_crawl:
                summary: 请求示例—网站爬取
                value:
                  inputs: {}
                  datasource_type: website_crawl
                  datasource_info_list:
                    - url: https://example.com/docs/getting-started
                      title: Getting Started Guide
                  start_node_id: '1719288585006'
                  is_published: true
                  response_mode: blocking
              online_drive:
                summary: 请求示例—在线存储
                value:
                  inputs: {}
                  datasource_type: online_drive
                  datasource_info_list:
                    - id: file-abc123
                      type: file
                      bucket: my-bucket
                      name: meeting-notes.docx
                  start_node_id: '1719288585006'
                  is_published: true
                  response_mode: blocking
      responses:
        '200':
          description: >-
            流水线执行结果。格式取决于 `response_mode`：流式返回 `text/event-stream`，阻塞返回完整的 JSON
            结果。
          content:
            text/event-stream:
              schema:
                type: string
                description: >-
                  服务器发送事件流。每行格式为 `data:
                  {JSON}\n\n`。主要事件：`workflow_started`（执行开始）、`node_started` /
                  `node_finished`（逐节点进度，包含
                  `node_id`、`node_type`、`status`、`inputs`、`outputs`）、`workflow_finished`（最终结果，包含
                  `status`、`outputs`、`total_tokens`、`elapsed_time`）、`ping`（心跳保活）。
            application/json:
              schema:
                type: object
                description: 完整的流水线执行结果。当 `response_mode` 为 `blocking` 时返回。
                additionalProperties: true
              examples:
                success:
                  summary: Blocking Response Example
                  value:
                    task_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                    workflow_run_id: f1e2d3c4-b5a6-7890-abcd-ef0987654321
                    data:
                      id: f1e2d3c4-b5a6-7890-abcd-ef0987654321
                      status: succeeded
                      outputs: {}
                      created_at: 1741267200
                      finished_at: 1741267210
        '403':
          description: '`forbidden` : 禁止访问。'
          content:
            application/json:
              examples:
                forbidden:
                  summary: forbidden
                  value:
                    status: 403
                    code: forbidden
                    message: Forbidden.
        '404':
          description: '`not_found` : 未找到知识库。'
          content:
            application/json:
              examples:
                not_found:
                  summary: not_found
                  value:
                    status: 404
                    code: not_found
                    message: Dataset not found.
        '500':
          description: '`pipeline_run_error` : 流水线执行失败。'
          content:
            application/json:
              examples:
                pipeline_run_error:
                  summary: pipeline_run_error
                  value:
                    status: 500
                    code: pipeline_run_error
                    message: 'Pipeline execution failed: connection timeout'
components:
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        API Key 认证。对于所有 API 请求，请在 `Authorization` HTTP 头中包含您的 API Key，并加上
        `Bearer ` 前缀。示例：`Authorization: Bearer {API_KEY}`。**强烈建议将 API Key
        存储在服务端，不要在客户端共享或存储，以避免 API Key 泄漏导致严重后果。**

````