diff --git a/docs/my-website/docs/tutorials/claude_code_customer_tracking.md b/docs/my-website/docs/tutorials/claude_code_customer_tracking.md index 78a9a644fcf..fc8f6e5dbac 100644 --- a/docs/my-website/docs/tutorials/claude_code_customer_tracking.md +++ b/docs/my-website/docs/tutorials/claude_code_customer_tracking.md @@ -1,18 +1,57 @@ -# Claude Code - Track Customer Usage +# Claude Code - Granular Cost Tracking -Track usage per customer when using Claude Code with LiteLLM proxy. This enables per-customer cost tracking and budget management for Claude Code users. +Track Claude Code usage by customer or tags using LiteLLM proxy. This enables granular cost attribution for billing, budgeting, and analytics. ## How It Works -LiteLLM supports standard customer ID headers that work out-of-the-box with Claude Code's custom headers feature. Set `ANTHROPIC_CUSTOM_HEADERS` to pass a customer ID with every request. +Claude Code supports custom headers via `ANTHROPIC_CUSTOM_HEADERS`. LiteLLM automatically tracks requests with specific headers for cost attribution. + +## Tracking Options + +Choose how you want to attribute costs: + +| Track By | Header | Use Case | +|----------|--------|----------| +| Customer | `x-litellm-customer-id` | Bill customers, per-user budgets | +| Tags | `x-litellm-tags` | Project tracking, cost centers, environments | ## Environment Variables | Variable | Description | Example | |----------|-------------|---------| | `ANTHROPIC_BASE_URL` | LiteLLM proxy URL | `http://localhost:4000` | -| `ANTHROPIC_API_KEY` | LiteLLM API key (master key or virtual key) | `sk-1234` | -| `ANTHROPIC_CUSTOM_HEADERS` | Custom headers in `header-name: value` format | `x-litellm-customer-id: my-customer` | +| `ANTHROPIC_API_KEY` | LiteLLM API key | `sk-1234` | +| `ANTHROPIC_CUSTOM_HEADERS` | Custom headers (`header-name: value` format) | See examples below | + +## Option 1: Track by Customer + +Use this to attribute costs to specific customers or end-users. + +```bash +export ANTHROPIC_BASE_URL=http://localhost:4000 +export ANTHROPIC_API_KEY=sk-1234 +export ANTHROPIC_CUSTOM_HEADERS="x-litellm-customer-id: claude-ishaan-local" +``` + +## Option 2: Track by Tags + +Use this to attribute costs to projects, cost centers, or environments. Pass comma-separated tags. + +```bash +export ANTHROPIC_BASE_URL=http://localhost:4000 +export ANTHROPIC_API_KEY=sk-1234 +export ANTHROPIC_CUSTOM_HEADERS="x-litellm-tags: project:acme,env:prod,team:backend" +``` + +## Option 3: Track by Both + +Combine customer and tag tracking by passing multiple headers separated by a comma. + +```bash +export ANTHROPIC_BASE_URL=http://localhost:4000 +export ANTHROPIC_API_KEY=sk-1234 +export ANTHROPIC_CUSTOM_HEADERS="x-litellm-customer-id: ishaan,x-litellm-tags: project:acme" +``` ## Quick Start @@ -24,8 +63,6 @@ export ANTHROPIC_API_KEY=sk-1234 export ANTHROPIC_CUSTOM_HEADERS="x-litellm-customer-id: claude-ishaan-local" ``` -The `ANTHROPIC_CUSTOM_HEADERS` format is `header-name: value`. LiteLLM automatically tracks requests with `x-litellm-customer-id` or `x-litellm-end-user-id` headers. - ### 2. Use Claude Code ```bash @@ -40,7 +77,7 @@ All requests will now be tracked under the customer ID `claude-ishaan-local`. ![](https://colony-recorder.s3.amazonaws.com/files/2026-01-16/0c30309e-7117-4999-a3df-d22a2d5629c1/ascreenshot_d76a48c53b9a4fad8f6727baf4aa6a9c_text_export.jpeg) -### 3. View Customer Usage +### 3. View Usage in LiteLLM UI Navigate to the **Logs** tab in the LiteLLM UI. @@ -56,14 +93,16 @@ Filter by customer ID to see all requests for that customer. ## Supported Headers -LiteLLM checks these headers automatically (no configuration required): - -- `x-litellm-customer-id` -- `x-litellm-end-user-id` +| Header | Description | +|--------|-------------| +| `x-litellm-customer-id` | Track by customer/end-user ID | +| `x-litellm-end-user-id` | Alternative customer ID header | +| `x-litellm-tags` | Comma-separated tags for cost attribution | ## Related - [Claude Code Quickstart](./claude_responses_api.md) - [Customer Budgets](../proxy/customers.md) +- [Tag Budgets](../proxy/tag_budgets.md) - [Track Usage for Coding Tools](./cost_tracking_coding.md)