---
title: 管理使用者設定檔
url: https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/manage-profiles
description: 檢查 Anthropic 是否已限制或封禁您的某位終端客戶、在終端客戶的詳細資訊變更時更新使用者設定檔，以及刪除使用者設定檔。
---

在您[為每位終端客戶建立使用者設定檔](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#create-a-profile-for-each-end-customer)之後，您可以檢查 Anthropic 是否已限制或封禁其中任何一位。您也可以在終端客戶的詳細資訊變更時更新使用者設定檔。當終端客戶離開或要求您清除其資料時，您可以刪除使用者設定檔。

## 開始之前

您需要兩樣東西：

* **使用者設定檔的 ID：** 您在建立使用者設定檔時儲存的 `uprof_` ID。本頁的範例會從變數中讀取它。
* **建立該使用者設定檔之組織的憑證：** 請使用您建立使用者設定檔時所用的憑證（請參閱[建立使用者設定檔並歸屬請求](https://platform.claude.com/docs/zh-TW/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-TW/api/user_profiles/retrieve) 擷取它。
* **每個有開啟中措施的使用者設定檔：** 使用 `enforcement_status[]=restricted` 和 `enforcement_status[]=banned` [列出您的使用者設定檔](https://platform.claude.com/docs/zh-TW/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-TW/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-TW/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-TW/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-TW/api/user_profiles/update) 只會變更您傳送的欄位：

* `name` 和 [`access_type`](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#decide-who-gets-a-profile) 會取代已儲存的值。
* 您在 [`external_user_details`](https://platform.claude.com/docs/zh-TW/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-TW/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-TW/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-TW/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-TW/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-TW/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-TW/build-with-claude/claude-platform-on-aws) 上，強制措施欄位不會回報措施：`enforcement_status` 一律為 `unrestricted`，而 `enforcement_actions` 一律為空。Anthropic 在該處也不會因為開啟中的措施而拒絕請求。
