---
title: 管理用户配置文件
url: https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/manage-profiles
description: 检查 Anthropic 是否已限制或封禁您的某位终端客户，在终端客户的详细信息发生变化时更新用户配置文件，以及删除用户配置文件。
---

在您[为每个终端客户创建用户配置文件](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#create-a-profile-for-each-end-customer)之后，您可以检查 Anthropic 是否已限制或封禁其中任何一位。您还可以在终端客户的详细信息发生变化时更新用户配置文件。当终端客户离开或要求您删除其数据时，您可以删除该用户配置文件。

## 开始之前

您需要准备两样东西：

* **用户配置文件的 ID：** 您在创建用户配置文件时存储的 `uprof_` ID。本页中的示例从变量中读取该 ID。
* **创建该用户配置文件的组织的凭据：** 请使用您创建用户配置文件时所用的凭据（请参阅[创建用户配置文件并归属请求](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#before-you-begin)）。

## 检查 Anthropic 是否已限制或封禁某个用户配置文件

Anthropic 可以限制或封禁您的某位终端客户。"enforcement action"（执行措施，简称"措施"）是指对该终端客户的用户配置文件施加的限制或封禁。当某项措施处于开启状态时，Anthropic 会拒绝部分或全部携带该用户配置文件 ID 的推理请求。您其他终端客户的请求不受影响。

* **限制**会在其结束之前限制 Anthropic 为该终端客户提供服务的方式，其部分请求可能仍会成功。
* **封禁**意味着 Anthropic 已在封禁适用的范围内停止为该终端客户提供服务，并且不打算再在该范围内为其提供服务。封禁没有结束日期，终端客户也无法自行解除。

### 查找存在开启措施的用户配置文件

有两种检查方式：

* **单个用户配置文件：** 使用 [`GET /v1/user_profiles/{id}`](https://platform.claude.com/docs/zh-CN/api/user_profiles/retrieve) 检索它。
* **所有存在开启措施的用户配置文件：** 使用 `enforcement_status[]=restricted` 和 `enforcement_status[]=banned` [列出您的用户配置文件](https://platform.claude.com/docs/zh-CN/api/user_profiles/list)。

在列表结束之前，列表响应中的用户配置文件数量可能少于 `limit`，甚至为零，因此请持续请求后续页面，直到 `next_page` 为 `null`。

要了解措施何时开启或结束，请定期列出您的用户配置文件。将 `enforcement_status` 和 `enforcement_actions` 与您上次看到的值进行比较。如果某个用户配置文件从列表中消失，则说明它没有开启的措施，或者已被删除。请勿依赖 `updated_at` 来发现变化，因为这些字段的变化并不一定会更新它。

Anthropic 不会针对这些变化发送 webhook 事件。

### 读取执行措施字段

创建、检索、更新或列表响应中的每个用户配置文件都带有两个字段：`enforcement_status` 和 `enforcement_actions`。如果响应中这两个字段都没有，请参阅[如果执行措施字段缺失](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/manage-profiles#if-the-enforcement-fields-are-missing)。在 Claude Platform on AWS 上，这两个字段不会报告措施（请参阅[如果您使用 Claude Platform on AWS](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/manage-profiles#if-you-use-claude-platform-on-aws)）。

这两个字段均由 Anthropic 设置，因此如果创建或更新请求中包含其中任一字段，API 将返回 `400`。

以下示例展示了检索到的用户配置文件上的这两个字段，并省略了其大部分其他字段：

```json
{
  "type": "user_profile",
  "id": "uprof_011CZkZCu8hGbp5mYRQgUmz9",
  "enforcement_status": "restricted",
  "enforcement_actions": [
    {
      "type": "restriction",
      "id": "enac_011CZkZEq4TnWb7xLfRgPm2v",
      "reason": "fraud_or_abuse",
      "action": null,
      "opened_at": "2026-10-02T19:30:00Z",
      "expires_at": null
    }
  ]
}
```

`enforcement_status` 用一个值概括所有开启的措施：

* `unrestricted`：没有开启的措施。
* `restricted`：至少有一项措施处于开启状态，且其中没有封禁。
* `banned`：有一项封禁处于开启状态。

`enforcement_status` 与 `external_user_details.account_status` 相互独立，后者记录的是您自己对该账户的决定。

`enforcement_actions` 列出所有开启的措施，没有措施时为空。措施结束后会从列表中移除，因此如果您需要历史记录，请存储您读取到的措施。每项措施包含以下字段：

* `type`：`restriction` 或 `ban`。
* `id`：措施的 ID，以 `enac_` 开头。
* `reason`：Anthropic 开启该措施的原因。取值为 `unsupported_region`、`fraud_or_abuse`、`high_harm`、`usage_policy_violation`、`account_compromise` 或 `unspecified` 之一。
* `action`：终端客户可以采取哪些操作来解除该措施。该值始终为 `null`。
* `opened_at`：Anthropic 开启该措施的时间。
* `expires_at`：该措施自动结束的时间。如果该措施没有结束日期，则为 `null`。

Anthropic 可能会为这些字段添加新的取值，因此请确保您的代码能够处理[无法识别的值](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/manage-profiles#if-a-field-has-a-value-that-you-dont-recognize)。

## 更新用户配置文件

当终端客户的详细信息或账户状态发生变化时，例如公司更名或您暂停某个账户时，请更新用户配置文件。[`POST /v1/user_profiles/{id}`](https://platform.claude.com/docs/zh-CN/api/user_profiles/update) 仅更改您发送的字段：

* `name` 和 [`access_type`](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#decide-who-gets-a-profile) 会替换存储的值。
* 您在 [`external_user_details`](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#what-to-tell-anthropic-about-an-end-customer) 中发送的每个字段都会替换存储的值。您无法清除值，因为 API 会以 `400` 拒绝 `null`。
* `metadata` 按键合并。您发送的键会覆盖存储的值，空字符串会删除该键，您未发送的键保持不变。

本页中的 cURL 示例会从 `ANTHROPIC_AUTH_TOKEN` 发送访问令牌，例如"workload identity federation"（[工作负载身份联合](https://platform.claude.com/docs/zh-CN/manage-claude/workload-identity-federation#authenticate-from-your-workload)）令牌。由于该变量优先于联合环境变量和联合配置文件，请仅在运行示例的 shell 中设置它。

以下示例将账户标记为已暂停，并删除 `trial_cohort` 元数据键：

<CodeGroup>
  ```bash cURL
  curl "https://api.anthropic.com/v1/user_profiles/$PROFILE_ID" \
    -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
    -H "anthropic-version: 2026-10-21" \
    -H "content-type: application/json" \
    -d '{
      "external_user_details": {"account_status": "suspended"},
      "metadata": {"trial_cohort": ""}
    }'
  ```

  ```bash CLI
  ant user-profiles update \
    --user-profile-id "$PROFILE_ID" \
    --external-user-details '{account_status: suspended}' \
    --metadata '{trial_cohort: ""}'
  ```

  ```python Python
  client = anthropic.Anthropic()

  profile = client.user_profiles.update(
      profile_id,
      external_user_details={"account_status": "suspended"},
      metadata={"trial_cohort": ""},
  )

  print(profile)
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const profile = await client.userProfiles.update(profileId, {
    external_user_details: { account_status: "suspended" },
    metadata: { trial_cohort: "" }
  });

  console.log(profile);
  ```

  ```csharp C#
  AnthropicClient client = new();

  var profile = await client.UserProfiles.Update(profileId, new()
  {
      ExternalUserDetails = new()
      {
          AccountStatus = UserProfileExternalUserAccountStatus.Suspended
      },
      Metadata = new Dictionary<string, string> { ["trial_cohort"] = "" }
  });

  Console.WriteLine(profile);
  ```

  ```go Go
  client := anthropic.NewClient()

  profile, err := client.UserProfiles.Update(
  	context.Background(),
  	profileID,
  	anthropic.UserProfileUpdateParams{
  		ExternalUserDetails: anthropic.UserProfileExternalUserDetailsParams{
  			AccountStatus: anthropic.UserProfileExternalUserAccountStatusSuspended,
  		},
  		Metadata: map[string]string{"trial_cohort": ""},
  	},
  )
  if err != nil {
  	log.Fatal(err)
  }

  fmt.Println(profile)
  ```

  ```java Java
  import com.anthropic.core.JsonValue;
  import com.anthropic.models.userprofiles.UserProfileExternalUserAccountStatus;
  import com.anthropic.models.userprofiles.UserProfileExternalUserDetailsParams;
  import com.anthropic.models.userprofiles.UserProfileUpdateParams;

  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      var params = UserProfileUpdateParams.builder()
          .userProfileId(profileId)
          .externalUserDetails(UserProfileExternalUserDetailsParams.builder()
              .accountStatus(UserProfileExternalUserAccountStatus.SUSPENDED)
              .build())
          .metadata(UserProfileUpdateParams.Metadata.builder()
              .putAdditionalProperty("trial_cohort", JsonValue.from(""))
              .build())
          .build();
      var profile = client.userProfiles().update(params);

      IO.println(profile);
  }
  ```

  ```php PHP
  $client = new Client();

  $profile = $client->userProfiles->update(
      $profileId,
      externalUserDetails: ['accountStatus' => 'suspended'],
      metadata: ['trial_cohort' => ''],
  );

  echo json_encode($profile, JSON_PRETTY_PRINT), PHP_EOL;
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  profile = client.user_profiles.update(
    profile_id,
    external_user_details: { account_status: :suspended },
    metadata: { trial_cohort: "" }
  )

  puts profile
  ```
</CodeGroup>

## 删除用户配置文件

[`DELETE /v1/user_profiles/{id}`](https://platform.claude.com/docs/zh-CN/api/user_profiles/delete) 会删除一个用户配置文件以及您为其提供的详细信息，包括 `name`、`external_user_details` 和 `metadata`。它不会删除 Anthropic 针对该用户配置文件 ID 保留的信任与安全记录。您可以在 Claude API 和 Claude Platform on AWS 上删除用户配置文件。

当终端客户关闭账户或要求您删除其数据时，请删除用户配置文件：

* **客户离开：** 停止在其请求中发送该用户配置文件的 ID，然后删除该用户配置文件。
* **客户在提出数据删除请求后仍继续使用您的服务：** 创建一个新的用户配置文件，将其请求切换到新用户配置文件的 ID，然后删除旧的用户配置文件。

如果客户继续使用您的服务，而某个工作区附加了旧用户配置文件，该工作区会拒绝携带新 ID 的请求。在切换之前，请参阅[如果工作区附加了用户配置文件](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#if-a-workspace-has-a-profile-attached)。

<Warning>
  删除操作无法撤销。
</Warning>

以下示例删除一个用户配置文件：

<CodeGroup>
  ```bash cURL
  curl -X DELETE "https://api.anthropic.com/v1/user_profiles/$PROFILE_ID" \
    -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
    -H "anthropic-version: 2026-10-21"
  ```

  ```bash CLI
  ant user-profiles delete --user-profile-id "$PROFILE_ID"
  ```

  ```python Python
  client = anthropic.Anthropic()

  deleted = client.user_profiles.delete(profile_id)

  print(deleted.id)
  ```

  ```typescript TypeScript
  const client = new Anthropic();

  const deleted = await client.userProfiles.delete(profileId);

  console.log(deleted.id);
  ```

  ```csharp C#
  AnthropicClient client = new();

  var deleted = await client.UserProfiles.Delete(profileId);

  Console.WriteLine(deleted.ID);
  ```

  ```go Go
  client := anthropic.NewClient()

  deleted, err := client.UserProfiles.Delete(
  	context.Background(),
  	profileID,
  	anthropic.UserProfileDeleteParams{},
  )
  if err != nil {
  	log.Fatal(err)
  }

  fmt.Println(deleted.ID)
  ```

  ```java Java
  void main() {
      AnthropicClient client = AnthropicOkHttpClient.fromEnv();

      var deleted = client.userProfiles().delete(profileId);

      IO.println(deleted.id());
  }
  ```

  ```php PHP
  $client = new Client();

  $deleted = $client->userProfiles->delete($profileId);

  echo $deleted->id, PHP_EOL;
  ```

  ```ruby Ruby
  client = Anthropic::Client.new

  deleted = client.user_profiles.delete(profile_id)

  puts deleted.id
  ```
</CodeGroup>

响应会重复该 ID，并带有 `"type": "user_profile_deleted"`。如果删除操作返回服务器错误，请重试。如果重试返回 `404`，则表示第一次删除已成功。

删除后，用户配置文件端点会对该 ID 返回 `404`。在最多约 10 分钟内，携带已删除 ID 的推理请求仍可能成功。此后，[在每个请求中检查 ID 的平台](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#if-a-request-returns-a-400)会以 `400` 拒绝这些请求。Claude Models on Google Cloud (Google managed) 不会查找用户配置文件，因此它仍会接受该 ID。对于[接受用户配置文件 ID 的模型](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/platforms#amazon-bedrock-models)，Amazon Bedrock 也是如此。

## 规则和特殊情况

### 如果字段的值无法识别

请按如下方式处理无法识别的值：

| 字段 | 将该值视为 |
| ----- | ----- |
| `enforcement_status` | `restricted` |
| `enforcement_actions[].type` | `restriction` |
| `enforcement_actions[].reason` | `unspecified` |
| `enforcement_actions[].action` | `null` |

### 如果执行措施字段缺失

如果响应中既没有 `enforcement_status` 也没有 `enforcement_actions`，请检查请求的 `anthropic-beta` 标头。`user-profiles-2026-09-04` beta 以及任何更早的用户配置文件 beta 都会省略这两个字段，并使 `enforcement_status[]` 列表筛选器返回 `400`。请移除该 beta，但保留其他任何 beta。

使用 SDK 或 CLI 时，请调用 `client.user_profiles` (typescript: `client.userProfiles`; csharp, go: `client.UserProfiles`; java: `client.userProfiles()`; php: `$client->userProfiles`; cli: `ant user-profiles`)，而不是 `client.beta.user_profiles` (typescript: `client.beta.userProfiles`; csharp, go: `client.Beta.UserProfiles`; java: `client.beta().userProfiles()`; php: `$client->beta->userProfiles`; cli: `ant beta:user-profiles`)，因为 beta 命名空间会发送 `user-profiles-2026-08-18` beta。

### 如果您使用 Claude Platform on AWS

在 [Claude Platform on AWS](https://platform.claude.com/docs/zh-CN/build-with-claude/claude-platform-on-aws) 上，执行措施字段不会报告措施：`enforcement_status` 始终为 `unrestricted`，`enforcement_actions` 始终为空。Anthropic 也不会因为开启的措施而拒绝该平台上的请求。
