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

# 启用自动自我修复

> 使用 Bright Data Scraper Studio AI Flow API 为爬虫启用自动自我修复，并设置成功率阈值、触发频率、冷却时间和每日作业上限。

每个爬虫只需调用该端点一次。它返回已保存设置的 ID，例如 `ash_lz3k9qw1`，而不是设置内容本身。

<Warning>
  自动自我修复的设置只能创建一次，无法通过 AI Flow API 修改。对同一个爬虫再次调用会返回 HTTP 409，并且没有用于读取、更新、删除或关闭这些设置的端点。请在 Bright Data Scraper Studio 的 **Auto Self-Healing** 标签页中修改或关闭自动自我修复。参见 [Scraper Studio 自动自我修复](/cn/products/scraper-studio/auto-self-healing)。
</Warning>

请求能否被接受，取决于以下四条规则：

* 每个请求都必须发送 `collector`、`enabled`、`sr_threshold` 和 `trigger_frequency`。当 `trigger_frequency` 为 `per_job` 时，还需发送 `min_inputs_threshold`。
* 只能发送整数，小数会被拒绝。
* 爬虫必须处于活跃状态。非活跃的爬虫会返回 HTTP 400 和 `Collector must be active`。
* `notification_emails` 中的每个地址都必须属于该爬虫所在账户下的用户。

当 `auto_save` 为 `false` 时，请设置 `notification_emails`。此时修复作业会运行但不会保存代码，通知邮件是相关人员看到建议修复方案的唯一途径。


## OpenAPI

````yaml api-reference/web-scraper-ide-rest-api POST /dca/auto_self_healing/create
openapi: 3.1.0
info:
  title: Brightdata API
  description: API for interaction with datasets marketplace
  version: 1.0.0
servers:
  - url: https://api.brightdata.com
security:
  - bearerAuth: []
paths:
  /dca/auto_self_healing/create:
    post:
      summary: Enable Auto Self-Healing
      description: >-
        Turn on [Auto Self-Healing](/products/scraper-studio/auto-self-healing)
        for a Scraper Studio scraper and set the trigger rules that decide when
        a healing job starts. Auto Self-Healing starts only for the
        `crawl_error`, `parse_error`, `bad_cmd_arg`, `dead_page`, `bad_input`
        and `bad_navigate` error codes. Auto Self-Healing jobs do not cost
        credits.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AutoSelfHealingCreateRequest'
            examples:
              required_only:
                summary: Required fields only
                value:
                  collector: c_abc123
                  enabled: true
                  sr_threshold: 50
                  trigger_frequency: per_day
              per_day:
                summary: Check once per day
                value:
                  collector: c_abc123
                  enabled: true
                  sr_threshold: 50
                  trigger_frequency: per_day
                  auto_save: false
                  cooldown_period: 5
                  max_jobs_per_day: 3
                  notification_emails:
                    - data-team@example.com
              per_job:
                summary: Check on every job
                value:
                  collector: c_abc123
                  enabled: true
                  sr_threshold: 50
                  trigger_frequency: per_job
                  min_inputs_threshold: 100
                  auto_save: true
                  cooldown_period: 5
                  max_jobs_per_day: 3
      responses:
        '200':
          description: Auto Self-Healing settings saved
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: ID of the saved Auto Self-Healing settings.
                    example: ash_lz3k9qw1
        '400':
          description: >-
            A required field is missing, a value is invalid, or the collector is
            not active
          content:
            application/json:
              schema:
                type: object
                properties:
                  validation_errors:
                    type: array
                    items:
                      type: string
                example:
                  validation_errors:
                    - Collector must be active
        '403':
          description: >-
            The collector is a managed collector that does not support Auto
            Self-Healing
        '404':
          description: No collector with that ID exists on this account
          content:
            application/json:
              schema:
                type: string
                example: collector_not_found
        '409':
          description: Auto Self-Healing settings already exist for this collector
components:
  schemas:
    AutoSelfHealingCreateRequest:
      type: object
      required:
        - collector
        - enabled
        - sr_threshold
        - trigger_frequency
      properties:
        collector:
          type: string
          description: >-
            ID of the Scraper Studio scraper to configure, in the `c_` format.
            Required.
          example: c_abc123
        enabled:
          type: boolean
          description: >-
            `true` turns Auto Self-Healing on for the scraper, `false` saves the
            settings with Auto Self-Healing off. Required. Send `false` here to
            keep it off, because this endpoint cannot be called a second time to
            disable it later.
          example: true
        sr_threshold:
          type: integer
          minimum: 1
          maximum: 70
          description: >-
            Success rate percentage below which Auto Self-Healing triggers, from
            `1` to `70`. At `50`, a healing job can start once the scraper's
            success rate falls below 50 percent. Required, with no default.
            Decimals are rejected.
          example: 50
        trigger_frequency:
          type: string
          enum:
            - per_day
            - per_job
          description: >-
            How often Scraper Studio checks the trigger rules. `per_day` checks
            once per day. `per_job` checks on every job run. Required. Any other
            value returns HTTP 400.
          example: per_day
        min_inputs_threshold:
          type:
            - integer
            - 'null'
          minimum: 10
          default: 10
          description: >-
            Minimum number of job inputs required before Auto Self-Healing
            triggers, `10` or higher. A job with fewer inputs does not start a
            healing job. Required with `trigger_frequency: per_job`. Optional
            with `per_day`, which does not use it: the server stores `10` when
            the field is omitted, and `null` is accepted.
          example: 100
        auto_save:
          type: boolean
          default: false
          description: >-
            When `true`, any successful healing job saves the newly extracted
            code to production and updates the scraper's template version, with
            no human review. When `false`, the healing job runs but the
            generated code is not saved. Defaults to `false`.
          example: true
        cooldown_period:
          type:
            - integer
            - 'null'
          minimum: 1
          default: 3
          description: >-
            Minimum hours to wait between consecutive Auto Self-Healing triggers
            for the scraper, `1` or higher. Send `null` for no cooldown.
            Defaults to `3`.
          example: 5
        max_jobs_per_day:
          type:
            - integer
            - 'null'
          minimum: 1
          maximum: 24
          default: 8
          description: >-
            Maximum number of Auto Self-Healing jobs allowed for the scraper in
            one day, from `1` to `24`. Send `null` for no daily limit. Defaults
            to `8`. A failed healing job still counts toward this limit and
            still starts the cooldown period.
          example: 3
        notification_emails:
          type: array
          items:
            type: string
          default: []
          description: >-
            Email addresses that receive the Auto Self-Healing notifications for
            this scraper. Each address must belong to a user on the collector's
            account. Defaults to an empty array, which leaves nobody to review a
            fix when `auto_save` is `false`.
          example:
            - data-team@example.com
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Use your Bright Data API Key as a Bearer token in the Authorization
        header.


        **How to authenticate:**

        1. Obtain your API Key from the Bright Data account settings at
        https://brightdata.com/cp/setting/users

        2. Include the API Key in the Authorization header of your requests

        3. Format: `Authorization: Bearer YOUR_API_KEY`


        **Example:**

        ```

        Authorization: Bearer
        b5648e1096c6442f60a6c4bbbe73f8d2234d3d8324554bd6a7ec8f3f251f07df

        ```


        Learn how to get your Bright Data API key:
        https://docs.brightdata.com/api-reference/authentication
      bearerFormat: API Key

````