> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-add-new-agent.mintlify.site/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: '{apiBaseUrl}'
    description: Knowledge API 的基础 URL。
    variables:
      apiBaseUrl:
        default: https://api.dify.ai/v1
        description: API 的实际基础 URL
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:
                    - online_document
                    - local_file
                    - website_crawl
                    - online_drive
                  description: 数据源类型。
                datasource_info_list:
                  type: array
                  items:
                    type: object
                    additionalProperties: true
                  description: 供流水线处理的数据源信息对象列表。
                start_node_id:
                  type: string
                  description: 流水线开始执行的节点 ID。
                is_published:
                  type: boolean
                  description: 运行流水线的已发布版本还是草稿版本。`true` 运行已发布版本，`false` 运行草稿版本。
                response_mode:
                  type: string
                  enum:
                    - streaming
                    - blocking
                  description: 流水线执行的响应模式。`streaming` 返回服务器发送事件流，`blocking` 等待并返回完整结果。
      responses:
        '200':
          description: >-
            流水线执行结果。格式取决于 `response_mode`：流式返回 `text/event-stream`，阻塞返回完整的 JSON
            结果。
          content:
            text/event-stream:
              schema:
                type: string
                description: 包含流水线执行进度和结果的服务器发送事件流。当 `response_mode` 为 `streaming` 时返回。
            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 泄漏导致严重后果。**

````