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

# 清除生物特征模板 API

> Didit 管理 API：DELETE /v3/biometric-templates/{template_uuid}/，清除单个已保留的人脸生物特征模板，将其移出比对并删除存储的模板。幂等。

清除一个模板：将其从所有类型的比对中移除，并删除已存储的模板。清除不可撤销，并会连同执行操作的主体记录在审计日志中。

```bash theme={null}
curl -X DELETE https://verification.didit.me/v3/biometric-templates/9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b/ \
  -H "x-api-key: YOUR_API_KEY"
```

```json theme={null}
{ "uuid": "9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b", "outcome": "purged" }
```

| `outcome` | 含义 |
| - | - |
| `purged` | 本次调用已清除该模板。 |
| `already_purged` | 该模板此前已被清除。重复执行清除是安全的。 |

## 重试语义

Didit 会先删除已存储的模板，然后才将模板标记为已清除。如果生物特征存储不可用，调用将返回 `503`，模板转为 `status: purge_failed`，并且已从比对中排除。重复同一调用即可完成清除。

## 错误

| 状态 | 触发条件 | 响应体 |
| - | - | - |
| `403` | 使用了控制台用户 token，或 API 密钥无权执行此操作 | `{"detail": "You do not have permission to perform this action."}` |
| `404` | 模板不存在，或属于其他应用 | `{"detail": "Biometric template not found."}` |
| `503` | 生物特征存储不可用。模板处于 `purge_failed` 状态并已从比对中排除；请重复调用。 | `{"detail": "The biometric-template operation could not finish because an external store is unavailable. The operation is retryable."}` |

## 其他清除点

模板还会在以下情况下被清除：通过 [批量删除用户](https://docs.didit.me/zh/management-api/users/delete.md) 删除所属用户时；使用 `deletion_instruction: "privacy_erasure"` 删除该用户的任一会话时；以及在 `expires_at` 到期时自动清除。详见[清除点](https://docs.didit.me/zh/management-api/biometric-templates/overview.md#清除时机)。


## OpenAPI

````yaml zh/openapi-25.json DELETE /v3/biometric-templates/{template_uuid}/
openapi: 3.0.0
info:
  version: 3.0.0
  title: Didit Verification API
  description: 身份证件验证 API。使用 x-api-key 请求头进行身份验证。
servers:
  - url: https://verification.didit.me
security: []
tags: []
paths:
  /v3/biometric-templates/{template_uuid}/:
    delete:
      tags:
        - Biometric Templates
      summary: 清除保留的生物特征模板
      description: >-
        选择启用的应用在会话被删除时（参见 `DELETE
        /v3/session/{sessionId}/delete/`），会保留一个锚定到用户的、独立管理的无图像人脸生物特征模板。模板是具有有限
        `expires_at` 的生物识别数据；它们绝不包含图像、会话数据或身份字段，并在用户删除、隐私清除、过期或明确清除时被清除。这些
        endpoint 仅接受应用 API 密钥（`x-api-key`）；Business Console 用户 token 将被拒绝并返回
        `403`。


        清除一个模板：它将从所有类型的匹配中移除，且存储的模板将被删除。该操作不可逆，并会与执行主体一起记录在审计日志中。


        **重试语义：** Didit 会先删除存储的模板，然后才将模板标记为已清除。如果生物识别存储不可用，调用将返回 `503`，模板状态变更为
        `status: purge_failed` 并且已从匹配中排除；重复相同调用即可完成清除。重复清除已清除的模板将返回
        `already_purged`。


        所属用户的 `POST /v3/users/delete/` 操作、对该用户会话带有 `deletion_instruction:
        privacy_erasure` 的任何删除操作，以及到达 `expires_at` 时，模板也会被自动清除。
      operationId: purge_biometric_template
      parameters:
        - in: path
          name: template_uuid
          required: true
          description: >-
            模板 ID，由会话删除 endpoint 在 `biometric_template_uuid` 中返回、在人脸搜索匹配中通过
            `biometric_template_id` 返回，或由列表 endpoint 返回。
          schema:
            type: string
            format: uuid
            example: 9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b
      responses:
        '200':
          description: 清除结果。
          content:
            application/json:
              schema:
                type: object
                properties:
                  uuid:
                    type: string
                    format: uuid
                  outcome:
                    type: string
                    enum:
                      - purged
                      - already_purged
              examples:
                Purged:
                  value:
                    uuid: 9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b
                    outcome: purged
                Already purged:
                  value:
                    uuid: 9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b
                    outcome: already_purged
        '403':
          description: Console 用户 token，或该 API 密钥不被允许。这些 endpoint 仅接受应用 API 密钥。
          content:
            application/json:
              examples:
                Forbidden:
                  value:
                    detail: You do not have permission to perform this action.
        '404':
          description: 未知模板、其他应用的模板，或（在 `GET` 时）已被清除的模板。
          content:
            application/json:
              examples:
                Not found:
                  value:
                    detail: Biometric template not found.
        '503':
          description: 在保留或清除生物特征模板时，生物特征存储库不可用。未删除任何内容；请重试相同的请求。重试具有幂等性，并最终收敛至单个模板。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
              examples:
                Retryable:
                  value:
                    detail: >-
                      The biometric-template operation could not finish because
                      an external store is unavailable. The operation is
                      retryable.
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: curl
          label: curl
          source: >-
            curl -X DELETE
            https://verification.didit.me/v3/biometric-templates/9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b/
            \
              -H 'x-api-key: YOUR_API_KEY'
        - lang: python
          label: Python
          source: |-
            from didit import Didit

            # Reads DIDIT_API_KEY.
            client = Didit()

            result = client.biometric_templates.delete(
                "9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b",
            )
            print(result)
        - lang: javascript
          label: Node.js
          source: >-
            import Didit from "@didit-protocol/sdk-node";


            // Reads DIDIT_API_KEY.

            const didit = new Didit();


            const result = await
            didit.biometricTemplates.delete("9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b");

            console.log(result);
        - lang: go
          label: Go
          source: "ctx := context.Background()\n// Reads DIDIT_API_KEY.\nclient := didit.NewClient()\n\nresult, err := client.BiometricTemplates.Delete(ctx, \"9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b\")\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", result)"
        - lang: java
          label: Java
          source: >-
            import me.didit.Didit;


            // Reads DIDIT_API_KEY.

            Didit client = new Didit();


            var result =
            client.biometricTemplates().delete("9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b");

            System.out.println(result);
        - lang: php
          label: PHP
          source: >-
            <?php


            require 'vendor/autoload.php';


            use Didit\DiditClient;


            // Reads DIDIT_API_KEY.

            $didit = new DiditClient();


            $result =
            $didit->biometricTemplates->delete('9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b');

            print_r($result->toArray());
        - lang: ruby
          label: Ruby
          source: >-
            require "didit"


            # Reads DIDIT_API_KEY.

            didit = Didit::Client.new


            result =
            didit.biometric_templates.delete("9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b")

            puts result.to_h
        - lang: csharp
          label: .NET
          source: >-
            using System;

            using System.Text.Json;

            using Didit;


            // Reads DIDIT_API_KEY.

            using var client = new DiditClient();


            var result = await
            client.BiometricTemplates.DeleteAsync("9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b");

            Console.WriteLine(JsonSerializer.Serialize(result));
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        您的应用 API 密钥，可在 Business Console 的“开发者 -> API
        密钥”中获取。主密钥拥有完整访问权限。指定名称的密钥可设置作用域：针对每个资源设为无权限、只读或读写，限定于特定工作流或已通过的会话、限定于
        IP 地址列表，以及设置到期日期。401 表示密钥错误、已撤销或已过期；403 表示未发送密钥、密钥无权访问该资源或操作，或请求来自其 IP
        列表之外的地址；在会话路由上返回 404 表示该会话不在该密钥允许的工作流或状态范围内。没有媒体访问权限的密钥获取到的图片、视频和 PDF
        URL 将为 null；没有会话写入权限的密钥获取到的会话链接和 token 将为 null。请参阅
        https://docs.didit.me/console/api-keys。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.