---
title: 建立使用者設定檔並歸屬請求
url: https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests
description: 為每位終端客戶建立使用者設定檔，並在為其發出的每個請求中傳送該使用者設定檔的 ID。如此一來，安全限制或封禁便可以只套用於該單一終端客戶。
---

使用者設定檔會告訴 Anthropic 每個 API 請求是代表您的哪一位終端客戶發出的。如此一來，安全強制措施（例如限制或封禁）便可以只套用於單一終端客戶，而非您的整個組織。如果您不確定是否需要使用者設定檔，請參閱[使用者設定檔的運作方式](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/how-user-profiles-work)。

如果您撰寫為終端客戶提供服務的程式碼，您會使用 `POST /v1/user_profiles` 為每位終端客戶建立使用者設定檔。您會保留其傳回的不透明 `uprof_` ID，並在您為該終端客戶發出的每個請求中傳送它。

如果您透過雲端平台使用 Claude，該平台會決定由哪個組織保存您的使用者設定檔，以及您如何傳送使用者設定檔 ID。在建立第一個使用者設定檔之前，請先閱讀[在雲端平台上使用使用者設定檔](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/platforms)。

## 開始之前

您需要下列項目：

* **一個用於終端客戶流量的組織：** 請將其與用於您自己用量的組織分開。在同一組織中使用不同的工作區是不夠的。只有用於終端客戶流量的組織需要使用者設定檔。若要在 Claude API 上建立另一個組織，請參閱[在 Claude Console 中建立和管理工作區](https://support.claude.com/en/articles/9796807)中的「How to create a new organization」。
* **該組織的憑證：** 若要建立和管理使用者設定檔，請使用具有 `workspace:developer` 範圍的「workload identity federation」（[工作負載身分聯合](https://platform.claude.com/docs/zh-TW/manage-claude/workload-identity-federation)）或 OAuth 權杖，或使用 API 金鑰。工作負載身分聯合權杖是一種短期的 Anthropic 權杖，您可以用來自您自己身分提供者的權杖交換取得。如果憑證屬於某個人，該人員需要在組織中具備開發者、管理員或擁有者角色，因為工作區角色是不夠的。如果憑證屬於服務帳戶，則在組織或工作區中具備開發者或管理員角色即可。若要傳送使用者設定檔 ID，任何來自該組織且可呼叫 Messages API 的憑證皆可使用。您不需要 Admin API 金鑰。
* **若使用託管在 Anthropic 上的 Microsoft Foundry 部署，則需要一個已連結的組織：** Anthropic 必須將保存您 Foundry 資源的組織連結至保存您使用者設定檔的組織。在此之前，您的 Foundry 請求無法帶有使用者設定檔 ID。請參閱[如果您使用 Microsoft Foundry](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/platforms#microsoft-foundry)。

## 決定誰需要使用者設定檔

每位終端客戶只有一個使用者設定檔，因此一家公司只有一個使用者設定檔，而不是為公司中的每個人各建立一個。在您為該公司中任何人發出的每個請求上，都傳送該使用者設定檔的 ID。若還要告訴 Anthropic 請求來自哪一個人，請參閱[識別公司內的一個人](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#identify-individual-users-within-a-company)。

您設定的 `access_type` 取決於終端客戶是使用您的產品，還是向您購買 API 存取權（例如透過您的閘道）：

| 終端客戶 | `access_type` |
| ----- | ----- |
| 使用您的產品 | `application`（預設值，當您省略 `access_type` 時即會設定） |
| 是向您購買 API 存取權的公司 | `passthrough`（非預設值，因此您必須傳送） |

您自己的用量不需要使用者設定檔。

請勿為工作區建立使用者設定檔。使用者設定檔屬於您的整個組織，因此其 ID 可用於透過組織中任何工作區發出的請求。例外情況是[附加了不同使用者設定檔的工作區](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#if-a-workspace-has-a-profile-attached)。您無法取代或移除該附加關係。

## 為每位終端客戶建立使用者設定檔

為每位終端客戶建立一個使用者設定檔，並在您傳送帶有該使用者設定檔 ID 的第一個請求之前完成。終端客戶導入流程是常見的建立時機。由於 `POST /v1/user_profiles` 並非「idempotent」（冪等）操作，每次呼叫都會建立新的使用者設定檔，即使 `reference_id`（您為該終端客戶使用的自有 ID）與現有使用者設定檔相符也是如此。請儲存呼叫傳回的 ID 並重複使用。

如果您已有尚未建立使用者設定檔的終端客戶，請參閱本節稍後[關於註冊現有客戶群的指引](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#register-existing-end-customers)。

### 要告訴 Anthropic 哪些終端客戶資訊

每個欄位都是選填的，但若終端客戶向您購買 API 存取權，則需將 `access_type` 設為 `passthrough`。除了 `access_type` 之外，您可以傳送 `name`、`metadata`，以及 `external_user_details` 中的這些欄位：`entity_type`、`country`、`reference_id`、`onboarded_at`、`account_status`、`name_hash` 和 `email_hash`。關於每個欄位的類型、格式和長度限制，請參閱[建立使用者設定檔](https://platform.claude.com/docs/zh-TW/api/user_profiles/create)參考文件。

填寫欄位時請遵循以下規則：

* **名稱：** 如果您傳送 `name`，請使用終端客戶的真實名稱。若是公司，且您知道該公司的法定名稱，請使用該名稱。
* **您無法分享的名稱：** 請省略 `name`，改為傳送 `external_user_details.name_hash`。
* **電子郵件地址：** 請傳送 `external_user_details.email_hash`，因為使用者設定檔沒有用於存放電子郵件地址本身的欄位。
* **雜湊值：** 請使用您選擇的函式自行計算雜湊值。這些雜湊值可讓 Anthropic 知道您的哪些使用者設定檔具有相同的名稱或電子郵件地址。由於只有以相同方式計算的值才會相符，請對每個使用者設定檔使用相同的函式，並以相同方式處理大小寫和空白。
* **國家：** `country` 是終端客戶的國家，而非您的國家。
* **您自己的 ID：** `reference_id` 接受您為該終端客戶使用的穩定識別碼，它不必是唯一的。
* **健康資訊：** 請勿在使用者設定檔中包含「protected health information」（受保護健康資訊），即 PHI，因為使用者設定檔 API [不是符合 HIPAA 資格的服務](https://platform.claude.com/docs/zh-TW/manage-claude/api-and-data-retention#feature-eligibility)。

如需更多資訊，請參閱[使用者設定檔包含的內容以及 Anthropic 如何使用它](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/how-user-profiles-work#what-a-profile-contains-and-how-anthropic-uses-it)。

<Warning>
  如果您不知道某個值，請省略它，而不是傳送預留位置值。您之後可以取代 `external_user_details` 中的值，但無法清除它。
</Warning>

### 傳送建立請求

本頁的 cURL 範例會從 `ANTHROPIC_AUTH_TOKEN` 傳送存取權杖，例如[工作負載身分聯合](https://platform.claude.com/docs/zh-TW/manage-claude/workload-identity-federation#authenticate-from-your-workload)權杖。請只在執行這些範例的 shell 中設定該變數，因為它的優先順序高於聯合環境變數和聯合設定檔。

此範例為一家向您購買 API 存取權的公司建立使用者設定檔，因此將 `access_type` 設為 `passthrough`。若是 `application` 使用者設定檔，請省略 `access_type`。

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/user_profiles \
    -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
    -H "anthropic-version: 2026-10-21" \
    -H "content-type: application/json" \
    -d '{
      "name": "Acme Analytics, Inc.",
      "access_type": "passthrough",
      "external_user_details": {
        "reference_id": "cust-8f2a1c",
        "country": "US"
      }
    }'
  ```

  ```bash CLI
  ant user-profiles create \
    --name "Acme Analytics, Inc." \
    --access-type passthrough \
    --external-user-details '{reference_id: cust-8f2a1c, country: US}'
  ```

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

  profile = client.user_profiles.create(
      name="Acme Analytics, Inc.",
      access_type="passthrough",
      external_user_details={"reference_id": "cust-8f2a1c", "country": "US"},
  )

  print(profile.id)
  ```

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

  const profile = await client.userProfiles.create({
    name: "Acme Analytics, Inc.",
    access_type: "passthrough",
    external_user_details: { reference_id: "cust-8f2a1c", country: "US" }
  });

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

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

  var profile = await client.UserProfiles.Create(new()
  {
      Name = "Acme Analytics, Inc.",
      AccessType = UserProfileAccessType.Passthrough,
      ExternalUserDetails = new()
      {
          ReferenceID = "cust-8f2a1c",
          Country = "US"
      }
  });

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

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

  profile, err := client.UserProfiles.New(context.Background(), anthropic.UserProfileNewParams{
  	Name:       anthropic.String("Acme Analytics, Inc."),
  	AccessType: anthropic.UserProfileAccessTypePassthrough,
  	ExternalUserDetails: anthropic.UserProfileExternalUserDetailsParams{
  		ReferenceID: anthropic.String("cust-8f2a1c"),
  		Country:     anthropic.String("US"),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }

  fmt.Println(profile.ID)
  ```

  ```java Java
  import com.anthropic.models.userprofiles.UserProfileAccessType;
  import com.anthropic.models.userprofiles.UserProfileCreateParams;
  import com.anthropic.models.userprofiles.UserProfileExternalUserDetailsParams;

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

      var params = UserProfileCreateParams.builder()
          .name("Acme Analytics, Inc.")
          .accessType(UserProfileAccessType.PASSTHROUGH)
          .externalUserDetails(UserProfileExternalUserDetailsParams.builder()
              .referenceId("cust-8f2a1c")
              .country("US")
              .build())
          .build();
      var profile = client.userProfiles().create(params);

      IO.println(profile.id());
      // ...
  }
  ```

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

  $profile = $client->userProfiles->create(
      name: 'Acme Analytics, Inc.',
      accessType: 'passthrough',
      externalUserDetails: ['referenceID' => 'cust-8f2a1c', 'country' => 'US'],
  );

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

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

  profile = client.user_profiles.create(
    name: "Acme Analytics, Inc.",
    access_type: :passthrough,
    external_user_details: { reference_id: "cust-8f2a1c", country: "US" }
  )

  puts profile.id
  ```
</CodeGroup>

您會收到新的使用者設定檔，此處為節錄內容：

```json
{
  "type": "user_profile",
  "id": "uprof_011CZkZCu8hGbp5mYRQgUmz9",
  "name": "Acme Analytics, Inc.",
  "access_type": "passthrough",
  "external_user_details": {
    "reference_id": "cust-8f2a1c",
    "onboarded_at": null,
    "account_status": null,
    "entity_type": null,
    "country": "US",
    "name_hash": null,
    "email_hash": null
  },
  "metadata": {},
  "programs": {
    "cyber": null
  },
  "enforcement_status": "unrestricted",
  "enforcement_actions": [],
  "created_at": "2026-03-15T10:00:00Z",
  "updated_at": "2026-03-15T10:00:00Z"
}
```

請將 `id` 儲存在您的客戶記錄中，並讓您的服務執行個體從該處讀取，而不是各自建立使用者設定檔。您之後也會使用此 ID 來擷取、更新或刪除使用者設定檔。

Anthropic 會自行設定以下欄位，因此請勿在您的請求中包含它們：

* `programs`：終端客戶在每個 Anthropic 計畫（例如 Cyber Verification Program）中的狀態。歸屬不會使用此欄位。關於其值的意義，請參閱[哪些計畫適用於使用者設定檔](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles-verification-portal#after-the-end-customer-links-the-profile)。
* `enforcement_status` 和 `enforcement_actions`：Anthropic 對該終端客戶施加且仍為開啟狀態的限制或封禁。請參閱[檢查 Anthropic 是否已限制或封禁某個使用者設定檔](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/manage-profiles#check-whether-anthropic-has-restricted-or-banned-a-profile)。

### 註冊現有客戶群

組織中的使用者設定檔數量沒有上限，但使用者設定檔的建立受到速率限制。在大量註冊現有客戶群之前，請聯絡您的 Anthropic 客戶團隊。

## 歸屬每個請求

在您為終端客戶發出的每個請求中，請於 `anthropic-user-profile-id` 標頭中傳送使用者設定檔的 `uprof_` ID，而非您為該終端客戶使用的自有 ID。當您設定 `user_profile_id` (java: `.userProfileId()`; php: `userProfileID`; csharp, go: `UserProfileID`; cli: `--user-profile-id`) 時，SDK 和 [`ant` CLI](https://platform.claude.com/docs/zh-TW/cli-sdks-libraries/cli/quickstart) 會替您加入此標頭。

<CodeGroup>
  ```bash cURL
  curl https://api.anthropic.com/v1/messages \
    -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
    -H "anthropic-version: 2026-10-21" \
    -H "anthropic-user-profile-id: $PROFILE_ID" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {"role": "user", "content": "Hello, Claude"}
      ]
    }'
  ```

  ```bash CLI
  ant messages create \
    --model claude-opus-5-5 \
    --max-tokens 1024 \
    --message '{role: user, content: "Hello, Claude"}' \
    --user-profile-id "$PROFILE_ID"
  ```

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

  message = client.messages.create(
      model="claude-opus-5-5",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Hello, Claude"}],
      user_profile_id=profile_id,
  )

  print(message)
  ```

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

  const message = await client.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Hello, Claude" }],
    user_profile_id: profileId
  });

  console.log(message);
  ```

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

  var parameters = new MessageCreateParams
  {
      Model = Model.ClaudeOpus5_5,
      MaxTokens = 1024,
      Messages = [new UserMessageParam { Content = "Hello, Claude" }],
      UserProfileID = profileId
  };
  var message = await client.Messages.Create(parameters);

  Console.WriteLine(message);
  ```

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

  message, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
  	Model:     anthropic.ModelClaudeOpus5_5,
  	MaxTokens: 1024,
  	Messages: []anthropic.MessageParam{
  		anthropic.NewUserMessage(anthropic.NewTextBlock("Hello, Claude")),
  	},
  	UserProfileID: anthropic.String(profileID),
  })
  if err != nil {
  	log.Fatal(err)
  }

  fmt.Println(message)
  ```

  ```java Java
  import com.anthropic.models.messages.MessageCreateParams;
  import com.anthropic.models.messages.Model;

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

      var params = MessageCreateParams.builder()
          .model(Model.CLAUDE_OPUS_5_5)
          .maxTokens(1024L)
          .addUserMessage("Hello, Claude")
          .userProfileId(profileId)
          .build();
      var message = client.messages().create(params);

      IO.println(message);
  }
  ```

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

  $message = $client->messages->create(
      maxTokens: 1024,
      messages: [['role' => 'user', 'content' => 'Hello, Claude']],
      model: Model::CLAUDE_OPUS_5_5,
      userProfileID: $profileId,
  );

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

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

  message = client.messages.create(
    model: Anthropic::Model::CLAUDE_OPUS_5_5,
    max_tokens: 1024,
    messages: [{ role: "user", content: "Hello, Claude" }],
    user_profile_id: profile_id
  )

  puts message
  ```
</CodeGroup>

在 [token 計數](https://platform.claude.com/docs/zh-TW/build-with-claude/token-counting)、[Message Batches](https://platform.claude.com/docs/zh-TW/build-with-claude/batch-processing) 和 [OpenAI SDK 相容性](https://platform.claude.com/docs/zh-TW/cli-sdks-libraries/libraries/openai-sdk)請求上，請以相同方式傳送此標頭。批次的標頭會套用於其中的每個請求，因此請在每個批次中只放入單一終端客戶的請求。

在 Amazon Bedrock 上，ID 則改放在請求主體中，且僅適用於[接受使用者設定檔 ID 的模型](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/platforms#amazon-bedrock-models)。若要了解 ID 在各雲端平台上的放置位置，請參閱[在雲端平台上使用使用者設定檔](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/platforms)。

以下是 API 處理 ID 的方式：

* **沒有 ID：** Anthropic 會將該請求視為您自己的用量。
* **格式錯誤的 ID，或您的組織無法使用的 ID：** Claude API 會以 `400` 拒絕該請求。請參閱[如果請求傳回 `400`](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#if-a-request-returns-a-400)。
* **批次上的 ID：** 建立批次時，API 只會檢查 ID 的格式，除非工作區附加了使用者設定檔。請參閱[如果您傳送批次](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#if-you-send-a-batch)。

若要將使用者設定檔的請求計費至該客戶自己的 Claude 組織，請參閱 [Linked billing](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing)。

### 識別公司內的一個人

公司的使用者設定檔識別的是該公司，而非發出請求的人員。如果請求來自您可以識別的某一個人，也請在 Messages 請求上將 [`metadata.user_id`](https://platform.claude.com/docs/zh-TW/api/messages/create) 設定為該人員的識別碼。此欄位位於請求本身的 `metadata` 物件中，而非使用者設定檔的 `metadata` 欄位中。該識別碼為選填。

## 規則與特殊情況

### 如果工作區附加了使用者設定檔

工作區一旦附加了使用者設定檔，透過該工作區發出的每個推論請求都必須帶有該使用者設定檔的 ID。API 會拒絕帶有其他 ID 或沒有 ID 的請求。您可以透過在[建立工作區](https://platform.claude.com/docs/zh-TW/api/organization/workspaces/create)或[更新工作區](https://platform.claude.com/docs/zh-TW/api/organization/workspaces/update)中設定 `user_profile_id` 來附加使用者設定檔。只有刪除使用者設定檔才能清除該附加關係。

### 如果請求傳回 `400`

Claude API 和 Claude Platform on AWS 會在每個請求上檢查 ID。Claude Models on Google Cloud (Anthropic managed) 以及[託管在 Anthropic 上](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-in-microsoft-foundry#hosting-options)的 Microsoft Foundry 部署也是如此。如果檢查失敗，它們會傳回類型為 `invalid_request_error` 的 `400` 錯誤。檢查失敗的情況包括：

* ID 格式錯誤。
* ID 屬於另一個組織，包括您在其他平台（例如 Claude Platform on AWS）上的組織。
* 在 [Anthropic 將保存您 Foundry 資源的組織連結](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/platforms#microsoft-foundry)至建立該使用者設定檔的組織之前，請求就送至託管在 Anthropic 上的 Microsoft Foundry 部署。

關於 Claude Models on Google Cloud (Google managed) 和 Amazon Bedrock，請參閱[各平台如何檢查 ID](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/platforms#how-each-platform-checks-the-id)。

### 如果您傳送批次

除非工作區[附加了使用者設定檔](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles/attribute-requests#if-a-workspace-has-a-profile-attached)，否則建立訊息批次時只會檢查 ID 的格式，而不會檢查該 ID 是否屬於您的組織。如果格式正確的 ID 不屬於發送批次的組織，批次仍會被建立。其中的每個請求隨後都會失敗，並產生包含 `invalid_request_error` 的 `errored` 結果。
