---
title: 管理已連結的客戶
url: https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers
description: 檢查並管理已連結的客戶：查看其用量、取消連結或重新連結，以及將其移至另一個組織或從其 API 金鑰移轉。
---

<Warning>
  Claude Platform OAuth 是一項 Beta Service：依據您與 Anthropic 之間的協議（例如[商業服務條款](https://www.anthropic.com/legal/commercial-terms)）以及[特定服務條款](https://www.anthropic.com/legal/service-specific-terms)所提供的預發布軟體。在 Beta 期間，端點、參數與行為可能會變更。它可能不適合用於正式環境。
</Warning>

客戶連結後，您可以從 Claude Console 和您的後端管理他們。每位客戶在您的組織中都有一個 [user profile](https://platform.claude.com/docs/zh-TW/manage-claude/user-profiles)（使用者設定檔），這是您為了連結他們而建立的。連結會建立一個 connection（連線），也就是將客戶的 Claude 組織與該設定檔綁定的記錄。

## 開始之前

* **客戶的 ID：** 您在[連結客戶](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#save-the-connection-and-its-tokens)時儲存的使用者設定檔 ID（`uprof_…`）和 `connection_id`（`ocon_…`）。
* **若要檢查客戶的狀態或使用取消連結端點：** 您應用程式的[操作員服務帳戶](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/set-up-your-app#service-account)，並具備來自[工作負載身分聯合](https://platform.claude.com/docs/zh-TW/manage-claude/workload-identity-federation)的存取權杖。該權杖必須來自具有 `workspace:developer` 範圍的聯合規則，這是預設值。
* **若要透過 `auth.claude.com` 取消連結：** 您應用程式的[用戶端驗證](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/set-up-your-app#set-up-client-authentication)。範例會從 `CLIENT_ASSERTION_FILE` 環境變數所指定的檔案讀取用戶端斷言，或者您可以將其貼上以取代 `YOUR_CLIENT_ASSERTION_JWT`。它是針對您應用程式 **Expected audience** 的 JWT。
* **若要從您的後端讀取用量：** 一個 [Admin API 憑證](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#if-you-read-usage-from-your-back-end)。

## 查看客戶和用量

在 Console 中開啟 [User profiles](https://platform.claude.com/user-profiles) 頁面。您應用程式的 **Overview** 分頁也會列出其已連結的客戶。對於每個使用者設定檔，User profiles 頁面會列出過去 28 天的 **Requests**、**Tokens** 和 **Your spend**。點擊某個設定檔即可查看其過去 7、28 或 90 天的用量。

* 具有有效連線的設定檔顯示為 **Linked**，連線已結束的顯示為 **Unlinked**，從未連結的則顯示為 **Not linked**。只有具備 Admin 角色的成員才能看到這些狀態和 **Unlink**。
* **Your spend** 是您自己為該設定檔的請求所支付的成本，未扣除 Anthropic 套用的任何額度。
* 由客戶付費的請求會計入 **Requests** 和 **Tokens**，但不會計入 **Your spend**。
* 該頁面不會顯示客戶支付的金額或客戶的費率。

這些數據大約每小時更新一次，一個請求可能需要幾個小時才會顯示。

請勿使用這些數據在您選定的金額時停止客戶的用量。客戶自己的[支出上限](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/what-your-customers-see#spend-caps)會負責這件事。

## 檢查客戶是否已連結

從您的後端，使用客戶的使用者設定檔 ID 呼叫 `GET /v1/user_profiles/{id}`。在 `oauth_app_id` 中傳送您應用程式的用戶端 ID，並傳送 `user-profiles-search-2026-08-30` beta 標頭。以您的操作員服務帳戶進行驗證。SDK 不會傳送 `oauth_app_id`，因此範例透過 HTTP 呼叫該端點。

在此範例中，`ANTHROPIC_AUTH_TOKEN` 保存服務帳戶的存取權杖，您可以[從您的工作負載取得](https://platform.claude.com/docs/zh-TW/manage-claude/workload-identity-federation#authenticate-from-your-workload)。請僅在執行 cURL 的地方設定此變數：SDK 和 CLI 會使用它來取代聯合驗證。

<CodeGroup exclude="shell:CLI, python, typescript, csharp, go, java, php, ruby">
  ```bash cURL
  curl "https://api.anthropic.com/v1/user_profiles/uprof_01HV9Z?oauth_app_id=clid_01ABcDeFgHiJkLmNoPqRsTuV" \
    -H "authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
    -H "anthropic-version: 2026-10-21" \
    -H "anthropic-beta: user-profiles-search-2026-08-30"
  ```
</CodeGroup>

在回應中，`connection_status.type` 描述該設定檔與您應用程式的連線：

| `connection_status.type` | 在 Console 中 | 意義 |
| ----- | ----- | ----- |
| `connected` | **Linked** | 與您應用程式的連線處於有效狀態 |
| `disconnected` | **Unlinked** | 該設定檔曾經連結，且其連線已結束 |
| `not_connected` | **Not linked** | 該設定檔從未連結至您的應用程式 |

`connected` 狀態並不保證請求會向客戶計費。在每個向客戶計費的請求上，請處理兩個 `403` 代碼以及兩個 `402` [計費錯誤](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/errors#while-billing)。

對於 `disconnected` 的設定檔，以下欄位會提供更多資訊。所列出的原因僅為範例：

| 欄位 | 說明內容 |
| ----- | ----- |
| `last_revoked_at` | 最後一個連線結束的時間 |
| `last_revoked_reason.type` | 原因。`revoked_by_admin`：客戶組織中具有 Admin 或 Billing 角色的成員取消連結了您的應用程式。`revoked_by_app_owner`：您的組織或您的後端取消連結了該客戶。 |

對於任何狀態，`oauth_connections.data` 會列出該設定檔與您應用程式的連線，最多 100 個，當清單可能不完整時會設定 `truncated`。

## 取消連結客戶

<Warning>
  取消連結會停止向客戶計費的新請求，直到您交換新核准的授權碼為止。
</Warning>

在 Console 中，您可以在兩個地方取消連結客戶：

* **您應用程式的 Overview 分頁：** 在 **Linked customers** 下，客戶列選單中的 **Unlink** 只會結束其與該應用程式的連線。
* **User profiles 頁面：** **Unlink** 位於設定檔的列選單中以及其頁面的右上角。它會結束該設定檔與您所有應用程式的連線，包括測試應用程式。

從您的後端，使用您應用程式的用戶端驗證以及下列其中一項，向 `auth.claude.com` 傳送撤銷請求：

* **`connection_id`：** 結束該單一連線。若您有此 ID，請使用它。
* **`user_profile_id`：** 取代 `connection_id` 傳送，它會結束您的應用程式在該設定檔上的所有連線。這包括客戶在您儲存 ID 之後建立的連線。

<CodeGroup exclude="shell:CLI">
  ```bash cURL
  curl https://auth.claude.com/v1/oauth/revoke \
    -H "content-type: application/json" \
    -d @- <<'JSON'
  {
    "connection_id": "ocon_01HV9Z",
    "client_id": "clid_01ABcDeFgHiJkLmNoPqRsTuV",
    "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    "client_assertion": "YOUR_CLIENT_ASSERTION_JWT"
  }
  JSON
  ```

  <CodeGroupItem language="CLI">
    `ant` CLI 沒有針對 `auth.claude.com` 的命令。請使用 cURL 或您應用程式的程式語言傳送請求。
  </CodeGroupItem>

  ```python Python
  import os
  from pathlib import Path

  import httpx2  # comes with the Anthropic SDK

  # 您在連結該客戶時所儲存的連線 ID
  connection_id = "ocon_01HV9Z"

  assertion_file = Path(os.environ["CLIENT_ASSERTION_FILE"])

  response = httpx2.post(
      "https://auth.claude.com/v1/oauth/revoke",
      json={
          "connection_id": connection_id,
          "client_id": "clid_01ABcDeFgHiJkLmNoPqRsTuV",
          "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
          "client_assertion": assertion_file.read_text().strip(),
      },
      timeout=10,
  )
  if not response.is_success:
      raise RuntimeError(f"Revoke failed: {response.status_code} {response.text}")

  print(response.json()["revoked_connection_ids"])
  ```

  ```typescript TypeScript
  import { readFile } from "node:fs/promises";

  // 您在連結該客戶時所儲存的連線 ID
  const connectionId = "ocon_01HV9Z";

  const jwt = await readFile(process.env.CLIENT_ASSERTION_FILE!, "utf8");

  const response = await fetch("https://auth.claude.com/v1/oauth/revoke", {
    method: "POST",
    redirect: "error",
    signal: AbortSignal.timeout(10_000),
    headers: { "content-type": "application/json" },
    body: JSON.stringify({
      connection_id: connectionId,
      client_id: "clid_01ABcDeFgHiJkLmNoPqRsTuV",
      client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
      client_assertion: jwt.trim()
    })
  });
  if (!response.ok) {
    throw new Error(`Revoke failed: ${response.status} ${await response.text()}`);
  }

  const result = (await response.json()) as { revoked_connection_ids: string[] };
  console.log(result.revoked_connection_ids);
  ```

  ```csharp C#
  using System.Net.Http.Json;
  using System.Text.Json;

  // 您在連結該客戶時所儲存的連線 ID
  var connectionId = "ocon_01HV9Z";

  var assertionFile = Environment.GetEnvironmentVariable("CLIENT_ASSERTION_FILE")!;
  var jwt = await File.ReadAllTextAsync(assertionFile);

  using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(10) };
  using var response = await http.PostAsJsonAsync(
      "https://auth.claude.com/v1/oauth/revoke",
      new Dictionary<string, string>
      {
          ["connection_id"] = connectionId,
          ["client_id"] = "clid_01ABcDeFgHiJkLmNoPqRsTuV",
          ["client_assertion_type"] = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
          ["client_assertion"] = jwt.Trim(),
      }
  );
  if (!response.IsSuccessStatusCode)
  {
      var details = await response.Content.ReadAsStringAsync();
      throw new HttpRequestException($"Revoke failed: {(int)response.StatusCode} {details}");
  }

  var result = await response.Content.ReadFromJsonAsync<JsonElement>();
  Console.WriteLine(result.GetProperty("revoked_connection_ids"));
  ```

  ```go Go
  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"log"
  	"net/http"
  	"os"
  	"strings"
  	"time"
  )

  func main() {
  	// 您在連結該客戶時所儲存的連線 ID
  	connectionID := "ocon_01HV9Z"

  	jwt, err := os.ReadFile(os.Getenv("CLIENT_ASSERTION_FILE"))
  	if err != nil {
  		log.Fatal(err)
  	}

  	body, err := json.Marshal(map[string]string{
  		"connection_id":         connectionID,
  		"client_id":             "clid_01ABcDeFgHiJkLmNoPqRsTuV",
  		"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
  		"client_assertion":      strings.TrimSpace(string(jwt)),
  	})
  	if err != nil {
  		log.Fatal(err)
  	}

  	httpClient := &http.Client{Timeout: 10 * time.Second}
  	endpoint := "https://auth.claude.com/v1/oauth/revoke"
  	response, err := httpClient.Post(endpoint, "application/json", bytes.NewReader(body))
  	if err != nil {
  		log.Fatal(err)
  	}
  	defer response.Body.Close()
  	if response.StatusCode/100 != 2 {
  		details, _ := io.ReadAll(response.Body)
  		log.Fatalf("revoke failed: %d %s", response.StatusCode, details)
  	}

  	var result struct {
  		RevokedConnectionIDs []string `json:"revoked_connection_ids"`
  	}
  	if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
  		log.Fatal(err)
  	}
  	fmt.Println(result.RevokedConnectionIDs)
  }
  ```

  ```java Java
  import module java.base;
  import module java.net.http;
  import com.fasterxml.jackson.databind.ObjectMapper; // Jackson comes with the Anthropic SDK

  void main() throws Exception {
      // 您在連結客戶時儲存的連線 ID
      var connectionId = "ocon_01HV9Z";

      var jwt = Files.readString(Path.of(System.getenv("CLIENT_ASSERTION_FILE")));

      var mapper = new ObjectMapper();
      var body = mapper.createObjectNode()
          .put("connection_id", connectionId)
          .put("client_id", "clid_01ABcDeFgHiJkLmNoPqRsTuV")
          .put("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer")
          .put("client_assertion", jwt.strip());

      var request = HttpRequest.newBuilder(URI.create("https://auth.claude.com/v1/oauth/revoke"))
          .header("content-type", "application/json")
          .timeout(Duration.ofSeconds(10))
          .POST(HttpRequest.BodyPublishers.ofString(body.toString()))
          .build();
      var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
      if (response.statusCode() / 100 != 2) {
          throw new IOException("Revoke failed: " + response.statusCode() + " " + response.body());
      }

      IO.println(mapper.readTree(response.body()).get("revoked_connection_ids"));
  }
  ```

  ```php PHP
  // 您在連結該客戶時所儲存的連線 ID
  $connectionId = 'ocon_01HV9Z';

  $jwt = file_get_contents((string) getenv('CLIENT_ASSERTION_FILE'))
      ?: throw new \RuntimeException('Cannot read the client assertion file');

  $body = json_encode([
      'connection_id' => $connectionId,
      'client_id' => 'clid_01ABcDeFgHiJkLmNoPqRsTuV',
      'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
      'client_assertion' => trim($jwt),
  ], JSON_THROW_ON_ERROR);

  $context = stream_context_create(['http' => [
      'method' => 'POST',
      'header' => 'content-type: application/json',
      'content' => $body,
      'timeout' => 10,
      'ignore_errors' => true, // keep the body of an error response
  ]]);
  $response = file_get_contents('https://auth.claude.com/v1/oauth/revoke', context: $context);
  $status = http_get_last_response_headers()[0] ?? '';
  if ($response === false || !preg_match('{^HTTP/\S+ 2}', $status)) {
      throw new \RuntimeException("Revoke failed: {$status} {$response}");
  }

  /** @var array{revoked_connection_ids: list<string>} $result */
  $result = json_decode($response, associative: true, flags: JSON_THROW_ON_ERROR);
  echo implode(', ', $result['revoked_connection_ids']), PHP_EOL;
  ```

  ```ruby Ruby
  require "json"
  require "net/http"

  # 您在連結該客戶時所儲存的連線 ID
  connection_id = "ocon_01HV9Z"

  jwt = File.read(ENV.fetch("CLIENT_ASSERTION_FILE"))

  body = {
    connection_id:,
    client_id: "clid_01ABcDeFgHiJkLmNoPqRsTuV",
    client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    client_assertion: jwt.strip
  }
  response = Net::HTTP.start("auth.claude.com", 443, use_ssl: true, read_timeout: 10) do |http|
    http.post("/v1/oauth/revoke", body.to_json, "content-type" => "application/json")
  end
  raise "Revoke failed: #{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)

  puts(JSON.parse(response.body).fetch("revoked_connection_ids"))
  ```
</CodeGroup>

回應中的 `revoked_connection_ids` 會列出該請求所結束的連線。空清單表示沒有找到可結束的連線：通常是連線已經結束，或該 ID 不明。這表示您可以安全地重複傳送包含 `connection_id` 的請求。若要確認，請[檢查客戶是否已連結](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#check-a-links-status)。若要改為透過 Claude API 取消連結，請參閱[如果您透過 Claude API 取消連結](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#if-you-unlink-through-the-claude-api)。

取消連結後，會發生以下情況：

* 該設定檔顯示為 **Unlinked**。取消連結不會刪除它。
* 該連線的 OAuth 權杖會停止運作，因此您可以將其從您的密鑰儲存區中刪除。
* 無論是誰取消連結，向客戶計費的新請求通常會在約 10 秒內停止。已在執行中的請求會完成，並向客戶計費。
* 向客戶計費的請求會收到 [`403 user_profile_billing_not_authorized`](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/errors#user-profile-billing-not-authorized)。使用客戶存取權杖傳送的請求則可能改為收到 [`401 authentication_error`](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/errors#authentication-error)。
* 當您透過任一途徑從後端取消連結時，Anthropic 會寄送電子郵件給客戶的 Admin 和 Billing 成員。當您在 Console 中取消連結時，則不會寄送電子郵件給他們。請參閱[您的客戶會收到哪些電子郵件](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/what-your-customers-see#emails)。

您仍然可以使用 [`bill_to: "self"`](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#you-pay) 自行負擔成本為客戶提供服務。每當您取消連結客戶時，請自行告知客戶，因為 Anthropic 不保證電子郵件會被寄出或送達。

## 重新連結客戶

如果客戶的連線已結束（**Unlinked**），請使用其現有的使用者設定檔再次[請他們進行核准](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#send-them-to-approve)。無需取消連結，而建立新的設定檔會分割其用量歷史記錄。

當連線處於有效狀態時，您的做法取決於它是否具有重新整理權杖；如果客戶核准了 `offline_access`，連線就會具有重新整理權杖：

* **連線沒有重新整理權杖：** 請勿取消連結。使用相同的 `scope` 再次請他們進行核准，這會[為您提供新的存取權杖](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#if-a-customer-approves-again)。如果存取權杖外洩，請先[取消連結客戶](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#unlink-a-customer)，因為再次核准並不會撤銷它。
* **連線具有重新整理權杖，即使是您已遺失的：** 取消連結客戶，然後請他們再次核准，如以下步驟所述。

當客戶的連線具有重新整理權杖時，請在下列情況下重新連結客戶：

* 重新整理傳回 `invalid_grant`，或重新整理失敗導致您停止為該客戶重新整理。首先，[排除停權以及您這端的原因](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/credential-for-each-customer#if-a-refresh-fails)。
* 您遺失了重新整理權杖、重新整理權杖外洩，或您遺失了授權碼交換的回應。
* 重新整理權杖即將達到其 1 年的有效期限。
* 您變更了操作員服務帳戶，且您使用此客戶的 OAuth 權杖。

從取消連結到您的新授權碼交換成功之前，透過該連線的計費會停止。首先，請與客戶組織中具有 Admin 或 Billing 角色的人員約定時間。然後：

1. 如果設定檔顯示為 **Linked**，請[取消連結客戶](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#unlink-a-customer)。
2. 使用客戶現有的使用者設定檔以及相同的範圍（包含 `offline_access`），再次[將客戶導向核准](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#send-them-to-approve)。
3. 儲存新的 `connection_id` 和新的 OAuth 權杖，以取代先前的項目。設定檔隨後會再次顯示為 **Linked**。

## 將客戶移至另一個組織

若要透過客戶的另一個 Claude 組織向其計費，請取消連結後再重新連結。在您取消連結之前，核准頁面只會提供已連結的組織。從取消連結到您交換另一個組織的核准授權碼為止，向客戶計費的請求都會被拒絕。

請在另一個組織中具有 Admin 或 Billing 角色的人員準備好進行核准時開始。然後：

1. 除非客戶已在其 [Linked platforms](https://platform.claude.com/linked-platforms) 頁面上取消連結您的應用程式，否則請[取消連結客戶](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#unlink-a-customer)。
2. 使用相同的使用者設定檔和範圍再次[請他們進行核准](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#send-them-to-approve)，並請該人員為另一個組織進行核准。
3. 儲存新的 `connection_id` 以取代先前的 ID，如果您使用 OAuth 權杖，也請儲存新的權杖。設定檔隨後會再次顯示為 **Linked**，透過另一個組織連結。

第一個組織為您的應用程式設定的支出上限不會延續。關於適用於另一個組織的上限，請參閱[「您的客戶會看到什麼」中的支出上限](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/what-your-customers-see#spend-caps)。

## 將客戶從其 API 金鑰移至 Linked billing

在您將客戶從其自己的 API 金鑰移轉之前，請權衡兩項成本：

* **您需為無法向客戶計費的項目付費：** [Message Batches](https://platform.claude.com/docs/zh-TW/build-with-claude/batch-processing)、Claude Managed Agents 以及可計費的程式碼執行。
* **請求在您的組織中執行：** 適用您的速率限制和資料條款。客戶的零資料保留、商業夥伴協議（BAA）、客戶管理的加密金鑰（CMEK）以及 IP 允許清單則不適用。請參閱[適用誰的條款與限制](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing#whose-data-terms-and-rate-limits-apply)。

若要移轉客戶：

1. [連結客戶](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer)，並儲存其 `connection_id`。
2. 不再使用其金鑰，而是以您的操作員服務帳戶為其請求計費，並在 [`billing_policy`](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#bill-a-request) 中設定 `bill_to: "user_profile"`。
3. 刪除已儲存的 API 金鑰，並告知客戶您已這麼做。

他們的請求隨後會計入您 [User profiles](https://platform.claude.com/user-profiles) 頁面上其設定檔的 **Requests**。它們不會計入 **Your spend**。

## 決定檢查客戶是否已連結的頻率

客戶可以隨時在其 [Linked platforms](https://platform.claude.com/linked-platforms) 頁面上取消連結您的應用程式，而 Anthropic 不會通知您。請決定您的產品何時得知：

* **當請求被拒絕時：** 找出[拒絕的原因](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/errors#while-billing)，並[檢查客戶是否仍處於連結狀態](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#check-a-links-status)。
* **在計費之前：** 當客戶在您的產品中開始進行會向其計費的操作時進行檢查。
* **依排程：** 檢查每位客戶，並讓您的產品對於誰已連結的掌握保持最新。

檢查得越頻繁，就能越早發現取消連結，但代價是更多的請求。

## 實作細節、規則和特殊情況

本頁其餘部分涵蓋這些工作背後的 API 細節，也涵蓋特殊情況，例如取消連結失敗。

### 如果您透過 Claude API 取消連結

您也可以改為透過 Claude API 的取消連結端點取消連結：在 `oauth_app_id` 中傳送您應用程式的用戶端 ID 至 `POST /v1/user_profiles/{id}/unlink`。它會結束的連線與使用 `user_profile_id` 的撤銷請求相同。

| 細節 | 撤銷請求 | 取消連結端點 |
| ----- | ----- | ----- |
| 主機 | `auth.claude.com` | `api.anthropic.com` |
| 驗證 | 您應用程式的用戶端驗證 | 您的操作員服務帳戶 |
| Beta 標頭 | 無 | `user-profiles-search-2026-08-30` |
| 結束的內容 | 一個連線，或您的應用程式在某設定檔上的所有連線 | 您的應用程式在某設定檔上的所有連線 |

在此範例中，`ANTHROPIC_AUTH_TOKEN` 保存您操作員服務帳戶的存取權杖，如同[檢查客戶是否已連結](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#check-a-links-status)中所述。

<CodeGroup exclude="shell:CLI, python, typescript, csharp, go, java, php, ruby">
  ```bash cURL
  curl https://api.anthropic.com/v1/user_profiles/uprof_01HV9Z/unlink \
    -H "authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
    -H "anthropic-version: 2026-10-21" \
    -H "anthropic-beta: user-profiles-search-2026-08-30" \
    -H "content-type: application/json" \
    -d '{"oauth_app_id": "clid_01ABcDeFgHiJkLmNoPqRsTuV"}'
  ```
</CodeGroup>

回應包含 `revoked_connection_ids`，如果沒有有效的連線，則為空。

### 如果取消連結端點傳回 503

取消連結端點傳回 `503` 表示它可能只結束了部分連線。請為在失敗請求之前已儲存的每個 `connection_id` 傳送撤銷請求。這在任何時候都有效。它會結束剩餘的連線，且不會影響客戶之後建立的連線。

在第一個請求後的一天內，以退避方式重複取消連結也有效，但它也會結束客戶之後建立的連線。一天之後，重複請求可能會傳回 `200` 和空清單。該較晚的重複請求也不會撤銷失敗請求所結束之連線的剩餘部分，因此它們可能保有 OAuth 權杖或計費存取權。

### 如果狀態檢查或取消連結端點拒絕請求

| 狀態 | 狀態檢查 | 取消連結端點 |
| ----- | ----- | ----- |
| `400` | `oauth_app_id` 不符合用戶端 ID 的格式，或缺少 beta 標頭 | 缺少 `oauth_app_id`，或其不符合用戶端 ID 的格式 |
| `401` | 憑證缺少或無效，或其聯合規則未授予 `workspace:developer` | 相同 |
| `403` | 呼叫者不是 `oauth_app_id` 中應用程式的操作員服務帳戶，或其使用的是該帳戶僅限單一工作階段的權杖 | 相同 |
| `404` | 使用者設定檔不存在 | 使用者設定檔不存在，或缺少 beta 標頭 |
| `503` | 以退避方式重試 | 請參閱[如果取消連結端點傳回 503](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/manage-customers#if-an-unlink-returns-a-503) |

撤銷請求本身的錯誤請參閱[撤銷端點的錯誤](https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/endpoints-and-parameters#errors-from-the-revocation-endpoint)。

### 如果您從後端讀取用量

[用量與成本分析 API](https://platform.claude.com/docs/zh-TW/manage-claude/usage-cost-analytics-api) 會回報每個使用者設定檔的用量。與 Console 一樣，它會同時計算您付費的請求以及客戶付費的請求。

請使用 Admin API 憑證呼叫它，例如具有 `org:admin` 範圍的 OAuth 存取權杖或 [Admin API 金鑰](https://platform.claude.com/docs/zh-TW/manage-claude/admin-api#authentication)。請勿使用您的操作員服務帳戶：其聯合規則預設授予的是 `workspace:developer`，而非 `org:admin`。請勿為其新增 `org:admin`，因為該範圍涵蓋整個 Admin API。

若要為每個使用者設定檔取得一列資料，請呼叫[用量端點](https://platform.claude.com/docs/zh-TW/manage-claude/usage-cost-analytics-api#usage-endpoint)或[成本端點](https://platform.claude.com/docs/zh-TW/manage-claude/usage-cost-analytics-api#cost-endpoint)。僅依 `user_profile_id` 分組，並省略 `time_bucket_width`。只有在該時間範圍內有用量的設定檔才會有一列。`user_profile_id` 為 null 的列保存未指定任何設定檔的用量，以及在請求之外計量的用量，例如程式碼執行容器時間。

在成本端點上，您可以從兩個欄位判斷誰付費：

| 欄位 | 您付費的請求 | 您的客戶付費的請求 |
| ----- | ----- | ----- |
| `amount` | 其成本，與 **Your spend** 的衡量方式相同 | 0 |
| `list_amount` | 其定價 | 其定價 |

API 沒有用於判斷誰付費的欄位或篩選條件。`amount` 為 0 且 `list_amount` 大於 0 的列，通常表示客戶支付了全部費用。關於資料可能延遲多久，請參閱[資料新鮮度](https://platform.claude.com/docs/zh-TW/manage-claude/usage-cost-analytics-api#data-freshness)。

### 適用於代理程式

* 將 `null` 的 `connection_status` 或您無法辨識的 `type` 視為未知。
* 將您無法辨識的 `last_revoked_reason.type` 視為 `other`。

## 後續步驟

<CardGroup cols={1}>
  <Card title="測試並發布您的應用程式" icon="rocket" href="https://platform.claude.com/docs/zh-TW/manage-claude/oauth-apps/linked-billing/test-and-publish">
    新增測試使用者、發布您的應用程式，以及變更或刪除它
  </Card>
</CardGroup>
