mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
guide claude granular cost tracking
This commit is contained in:
parent
244720d8a3
commit
4552872993
1 changed files with 51 additions and 12 deletions
|
|
@ -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`.
|
|||
|
||||

|
||||
|
||||
### 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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue