link-and-bill-a-customer changedmanage-claude/oauth-apps/linked-billing/link-and-bill-a-customer
Nearest release: v2.1.332, published under an hour before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
## Before you begin ### Sample setup ## Choose the user profile ## Link the customer ### Create the user profile ### Send the customer to approve ### Save the connection and its OAuth tokens ## Bill a request ### Your customer pays ### You pay ## Check the result ## What to tell your customers ## Rules and special cases ### If your federation rule and client authentication expect different audiences ### If the code exchange times out ### If you have a profile for each person ### If you resell API access ### If a customer approves again ### For agents ## Next steps
The whole hunk
1623 lines, new pageA whole new page. There's nothing to diff it against, so here is what it says.
---
title: Link and bill a customer
url: https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer
description: Send a customer to approve your OAuth app, save the connection, and bill Claude API requests to their Claude organization.
featureMetadata:
status: beta
betaHeader: user-profiles-billing-2026-10-01
supportedModels:
- claude-fable-5-2
- claude-mythos-5-2
- claude-fable-5-1
- claude-mythos-5-1
- claude-fable-5
- claude-mythos-5
- claude-mythos-preview
- claude-opus-5-5
- claude-opus-5
- claude-sonnet-5-5
- claude-sonnet-5
- claude-haiku-5-5
- claude-haiku-4-5-20251001
- claude-opus-4-8
- claude-opus-4-7
- claude-opus-4-6
- claude-sonnet-4-6
- claude-opus-4-5-20251101
- claude-sonnet-4-5-20250929
supportedPlatforms:
Claude API:
availability: beta
note: Only requests that send `billing_policy` need the beta header.
---
<Warning>
Claude Platform OAuth is a Beta Service: prerelease software provided under your agreement with Anthropic, such as the [Commercial Terms of Service](https://www.anthropic.com/legal/commercial-terms), and the [Service Specific Terms](https://www.anthropic.com/legal/service-specific-terms). Endpoints, parameters, and behavior can change during the beta. It might not be suitable for production use.
</Warning>
This page shows how to build Linked billing into your product. A customer approves your app once, which creates a connection between their Claude organization and one of your user profiles. After that, your back end bills the customer by sending requests as your own [operator service account](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/set-up-your-app#service-account), naming the customer’s [user profile](https://platform.claude.com/docs/en/manage-claude/user-profiles). You try the flow first on a test customer, a second organization of your own. For how the feature works and whether it fits your product, see [Linked billing](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing).
## Before you begin
You need these:
* **An app set up for Linked billing:** It needs client authentication, an operator service account, and a default workspace: see [Set up your app for Linked billing](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/set-up-your-app).
* **A test customer:** A second Claude organization of yours, because the organization that owns your app can’t link to it. It must pay Anthropic directly, through invoiced billing or [credit that can pay for these requests](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing#which-credits-can-pay).
* **A test user:** A person with the Admin or Billing role in the test customer’s organization, who approves for it. Until your app is live, only people on its **Test users** list can link it. [Add this person’s Claude email address](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/test-and-publish#add-test-users) to that list.
### Sample setup
The samples read these values:
| Samples | What they need | Where it comes from |
| ----- | ----- | ----- |
| SDK and CLI | Your operator service account’s federation settings, in environment variables, including the federation JWT’s file in `ANTHROPIC_IDENTITY_TOKEN_FILE` | [Construct the SDK client](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#construct-the-sdk-client) |
| cURL requests to the Claude API | Your service account’s access token, in `ANTHROPIC_AUTH_TOKEN` | [Authenticate from your workload](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#authenticate-from-your-workload) |
| Requests to `auth.claude.com` | A client assertion: a JWT for your app’s **Expected audience**, in the file that `CLIENT_ASSERTION_FILE` names or in place of `YOUR_CLIENT_ASSERTION_JWT` | Your identity provider |
| All | Your app’s client ID and redirect URI, in place of the sample’s client ID and redirect URI | Your app’s page in the Claude Console |
Set `ANTHROPIC_AUTH_TOKEN` only where the cURL samples run. Where the SDK and CLI samples run, unset it and `ANTHROPIC_API_KEY`, because [each one takes priority over federation](https://platform.claude.com/docs/en/manage-claude/workload-identity-federation#credential-precedence).
The client assertion and the federation JWT usually need different audiences, so keep them in separate files: see [when the two audiences differ](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#if-the-audiences-differ). The samples that use `CLIENT_ASSERTION_FILE` read it for each request, because the JWT in it rotates.
## Choose the user profile
A [user profile](https://platform.claude.com/docs/en/manage-claude/user-profiles) is a record in your own organization that stands for one of your customers. A request that bills the customer carries the profile’s ID, which tells Anthropic whom to bill. You can link a profile that you already have, unless it’s archived, and linking doesn’t change its ID or usage history.
Within one app, a customer’s Claude organization can link to only one of your profiles, and a profile can link to only one organization. Decide which profile stands for which organization before you link your first customer. The organization is the one that your customer selects when they approve, so ask them how their teams use Claude organizations:
* **Several teams share one Claude organization:** Use one profile for all of the teams.
* **Each team has its own Claude organization:** Use one profile for each organization.
If the customer selects an organization that’s already linked to another of your profiles, the approval is refused: see [`user_profile_already_linked` in Linked billing errors](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/errors#user-profile-already-linked).
Two cases change the profile that you create: [If you have a profile for each person](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#if-you-have-a-profile-for-each-person) and [If you resell API access](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#if-you-resell-api-access).
## Link the customer
<Frame>

</Frame>
### Create the user profile
Create one user profile for each Claude organization that will link, as you mapped them in [Choose the user profile](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#choose-the-user-profile). Skip this step for a profile that you already have. Send a name and your own ID for the customer (`reference_id`). Create the profile once, and store its ID with the customer’s record: each create request makes a new profile, even with the same `reference_id`.
<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": "Example Customer Inc.",
"external_user_details": {"reference_id": "cust_2abc3def"}
}'
```
```bash CLI
ant user-profiles create \
--name "Example Customer Inc." \
--external-user-details.reference-id cust_2abc3def
```
```python Python
client = anthropic.Anthropic()
profile = client.user_profiles.create(
name="Example Customer Inc.",
external_user_details={"reference_id": "cust_2abc3def"},
)
print(profile.id)
```
```typescript TypeScript
const client = new Anthropic();
const profile = await client.userProfiles.create({
name: "Example Customer Inc.",
external_user_details: { reference_id: "cust_2abc3def" }
});
console.log(profile.id);
```
```csharp C#
AnthropicClient client = new();
var profile = await client.UserProfiles.Create(
new()
{
Name = "Example Customer Inc.",
ExternalUserDetails = new() { ReferenceID = "cust_2abc3def" },
}
);
Console.WriteLine(profile.ID);
```
```go Go
client := anthropic.NewClient()
profile, err := client.UserProfiles.New(context.Background(), anthropic.UserProfileNewParams{
Name: anthropic.String("Example Customer Inc."),
ExternalUserDetails: anthropic.UserProfileExternalUserDetailsParams{
ReferenceID: anthropic.String("cust_2abc3def"),
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(profile.ID)
```
```java Java
import com.anthropic.models.userprofiles.UserProfileCreateParams;
import com.anthropic.models.userprofiles.UserProfileExternalUserDetailsParams;
void main() {
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
var params = UserProfileCreateParams.builder()
.name("Example Customer Inc.")
.externalUserDetails(UserProfileExternalUserDetailsParams.builder()
.referenceId("cust_2abc3def")
.build())
.build();
var profile = client.userProfiles().create(params);
IO.println(profile.id());
}
```
```php PHP
$client = new Client();
$profile = $client->userProfiles->create(
name: 'Example Customer Inc.',
externalUserDetails: ['referenceID' => 'cust_2abc3def'],
);
echo $profile->id, PHP_EOL;
```
```ruby Ruby
client = Anthropic::Client.new
profile = client.user_profiles.create(
name: "Example Customer Inc.",
external_user_details: { reference_id: "cust_2abc3def" }
)
puts(profile.id)
```
</CodeGroup>
The response holds the profile’s `id`, such as `uprof_01HV9Z`.
### Send the customer to approve
Add a [Link your Claude organization button](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/link-button) to your product, where your customers manage billing or integrations. Its HTML, colors, and logo are ready to copy.
The approval page offers only the organizations of the signed-in Claude account, and the organization that the customer selects pays. For what to show beside the button, see [What to tell your customers](https://platform.claude.com/docs/en/manage-claude/oauth-apps/linked-billing/link-and-bill-a-customer#what-to-tell-your-customers).
When the customer clicks the button, do these three things in your back end:
1. **Create a `state` value and a PKCE code verifier,** a random secret that proves your back end started this approval. Store both on your back end, tied to the browser session and the customer’s record.
2. **Send a pushed authorization request** to `auth.claude.com`, which passes the approval’s details from your back end instead of through the browser.
3. **Redirect the browser** to `https://auth.claude.com/oauth/authorize` with your `client_id` and the `request_uri` from the response. A `request_uri` works once and expires after 10 minutes, so send a new pushed authorization request for each click.
No SDK covers `auth.claude.com`, so the samples for these steps call it over HTTP:
<CodeGroup exclude="shell:CLI">
```bash cURL
curl https://auth.claude.com/v1/oauth/par \
-H "content-type: application/json" \
-d @- <<'JSON'
{
"response_type": "code",
"client_id": "clid_01ABcDeFgHiJkLmNoPqRsTuV",
"redirect_uri": "https://app.example.com/claude/billing/callback",
"scope": "billing:attribution",
"connection_type": "organization_shared",
"connection_auth_target": "platform",
"user_profile_id": "uprof_01HV9Z",
"state": "RANDOM_STATE",
"code_challenge": "BASE64URL_SHA256_OF_VERIFIER",
"code_challenge_method": "S256",
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": "YOUR_CLIENT_ASSERTION_JWT"
}
JSON
```
<CodeGroupItem language="CLI">
The `ant` CLI has no command for `auth.claude.com`. Send the request with cURL or in your application’s language.
</CodeGroupItem>
```python Python
import base64
import hashlib
import os
import secrets
from pathlib import Path
from urllib.parse import urlencode
import httpx2 # comes with the Anthropic SDK
CLIENT_ID = "clid_01ABcDeFgHiJkLmNoPqRsTuV"
def push_authorization_request(user_profile_id: str) -> dict[str, str]:
state = secrets.token_urlsafe(32)
code_verifier = secrets.token_urlsafe(64)
digest = hashlib.sha256(code_verifier.encode()).digest()
assertion_file = Path(os.environ["CLIENT_ASSERTION_FILE"])
response = httpx2.post(
"https://auth.claude.com/v1/oauth/par",
json={
"response_type": "code",
"client_id": CLIENT_ID,
"redirect_uri": "https://app.example.com/claude/billing/callback",
"scope": "billing:attribution",
"connection_type": "organization_shared",
"connection_auth_target": "platform",
"user_profile_id": user_profile_id,
"state": state,
"code_challenge": base64.urlsafe_b64encode(digest).rstrip(b"=").decode(),
"code_challenge_method": "S256",
"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"Request failed: {response.status_code} {response.text}")
query = {"client_id": CLIENT_ID, "request_uri": response.json()["request_uri"]}
return {
"approval_url": f"https://auth.claude.com/oauth/authorize?{urlencode(query)}",
"state": state,
"code_verifier": code_verifier,
}
```
```typescript TypeScript
import { createHash, randomBytes } from "node:crypto";
import { readFile } from "node:fs/promises";
const CLIENT_ID = "clid_01ABcDeFgHiJkLmNoPqRsTuV";
async function pushAuthorizationRequest(userProfileId: string) {
const state = randomBytes(32).toString("base64url");
const codeVerifier = randomBytes(64).toString("base64url");
const jwt = await readFile(process.env.CLIENT_ASSERTION_FILE!, "utf8");
const response = await fetch("https://auth.claude.com/v1/oauth/par", {
method: "POST",
Cut at 300 lines. The page has the rest.
No line in this hunk matches that.