---
title: 创建用户配置文件并归属请求
url: https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests
description: 为每个终端客户创建用户配置文件，并在为其发出的每个请求中发送该用户配置文件的 ID。这样，安全限制或封禁就可以仅作用于该终端客户。
---

用户配置文件用于告知 Anthropic 每个 API 请求是为您的哪位终端客户发出的。这样，安全执行措施（例如限制或封禁）就可以仅作用于某一位终端客户，而不是您的整个组织。如果您不确定是否需要用户配置文件，请参阅[用户配置文件的工作原理](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/how-user-profiles-work)。

如果您编写为终端客户提供服务的代码，则需使用 `POST /v1/user_profiles` 为每个终端客户创建用户配置文件。您保存返回的不透明 `uprof_` ID，并在您为其发出的每个请求中发送该 ID。

如果您通过云平台使用 Claude，则由该平台决定哪个组织持有您的用户配置文件以及您如何发送用户配置文件 ID。在创建第一个用户配置文件之前，请阅读[在云平台上使用用户配置文件](https://platform.claude.com/docs/zh-CN/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-CN/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-CN/manage-claude/user-profiles/platforms#microsoft-foundry)。

## 确定为谁创建用户配置文件

每个终端客户对应一个用户配置文件，因此一家公司只对应一个用户配置文件，而不是为公司中的每个人分别创建。在您为该公司中任何人发出的每个请求中，都发送该用户配置文件的 ID。如果还要告知 Anthropic 请求来自哪个人，请参阅[识别公司内的某一个人](https://platform.claude.com/docs/zh-CN/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-CN/manage-claude/user-profiles/attribute-requests#if-a-workspace-has-a-profile-attached)。您无法替换或移除该附加关系。

## 为每个终端客户创建用户配置文件

请为每个终端客户创建一个用户配置文件，并在您发送带有该用户配置文件 ID 的第一个请求之前完成创建。终端客户入驻流程是常见的创建时机。由于 `POST /v1/user_profiles` 不是幂等的，每次调用都会创建一个新的用户配置文件，即使 `reference_id`（您为该终端客户使用的 ID）与现有用户配置文件相同也是如此。请存储返回的 ID 并重复使用它。

如果您已有尚未创建用户配置文件的终端客户，请参阅本节后面[关于注册现有客户群的指导](https://platform.claude.com/docs/zh-CN/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-CN/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-CN/manage-claude/api-and-data-retention#feature-eligibility)。

如需了解更多信息，请参阅[用户配置文件包含的内容以及 Anthropic 如何使用它](https://platform.claude.com/docs/zh-CN/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-CN/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-CN/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-CN/manage-claude/user-profiles/manage-profiles#check-whether-anthropic-has-restricted-or-banned-a-profile)。

### 注册现有客户群

一个组织可以拥有任意数量的用户配置文件，但用户配置文件的创建受"rate limit"（速率限制）约束。在批量注册现有客户群之前，请联系您的 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-CN/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>

在[令牌计数](https://platform.claude.com/docs/zh-CN/build-with-claude/token-counting)、[Message Batches](https://platform.claude.com/docs/zh-CN/build-with-claude/batch-processing) 和 [OpenAI SDK 兼容性](https://platform.claude.com/docs/zh-CN/cli-sdks-libraries/libraries/openai-sdk)请求中，以相同方式发送该标头。批处理的标头适用于其中的每个请求，因此每个批处理中只应放入一个终端客户的请求。

在 Amazon Bedrock 上，ID 改为放在请求体中，并且仅适用于[接受用户配置文件 ID 的模型](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/platforms#amazon-bedrock-models)。要了解在每个云平台上 ID 应放在哪里，请参阅[在云平台上使用用户配置文件](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/platforms)。

API 对 ID 的处理方式如下：

* **没有 ID：** Anthropic 会将该请求计为您自己的使用量。
* **格式错误的 ID 或您的组织无法使用的 ID：** Claude API 会以 `400` 拒绝该请求。请参阅[如果请求返回 `400`](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#if-a-request-returns-a-400)。
* **批处理中的 ID：** 创建批处理时，除非工作区附加了用户配置文件，否则 API 只检查 ID 的格式。请参阅[如果您发送批处理](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#if-you-send-a-batch)。

要将某个用户配置文件的请求计费到该客户自己的 Claude 组织，请参阅 [Linked billing](https://platform.claude.com/docs/zh-CN/manage-claude/oauth-apps/linked-billing)。

### 识别公司内的某一个人

公司的用户配置文件标识的是该公司，而不是发出请求的个人。如果请求来自您能够识别的某一个人，还请在 Messages 请求中将 [`metadata.user_id`](https://platform.claude.com/docs/zh-CN/api/messages/create) 设置为该人的标识符。此字段位于请求自身的 `metadata` 对象中，而不是用户配置文件的 `metadata` 字段中。该标识符是可选的。

## 规则和特殊情况

### 如果工作区附加了用户配置文件

一旦工作区附加了用户配置文件，通过该工作区发出的每个推理请求都必须携带该用户配置文件的 ID。API 会拒绝携带其他 ID 或不带 ID 的请求。您可以通过在[创建工作区](https://platform.claude.com/docs/zh-CN/api/organization/workspaces/create)或[更新工作区](https://platform.claude.com/docs/zh-CN/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-CN/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-CN/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-CN/manage-claude/user-profiles/platforms#how-each-platform-checks-the-id)。

### 如果您发送批处理

除非工作区[附加了用户配置文件](https://platform.claude.com/docs/zh-CN/manage-claude/user-profiles/attribute-requests#if-a-workspace-has-a-profile-attached)，否则创建消息批处理时只检查 ID 的格式，而不检查该 ID 是否属于您的组织。如果格式正确的 ID 不属于发送批处理的组织，批处理仍会被创建。其中的每个请求随后都会失败，返回包含 `invalid_request_error` 的 `errored` 结果。
