The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Docs Guide] Litellm claude code end user tracking (#19176)
Ishaan Jaffb5b9c39beb8c
diff --git a/docs/my-website/docs/tutorials/claude_code_customer_tracking.md b/docs/my-website/docs/tutorials/claude_code_customer_tracking.mdnew file mode 100644index 00000000000..fc6a3ccc9bb--- /dev/null+++ b/docs/my-website/docs/tutorials/claude_code_customer_tracking.md@@ -0,0 +1,99 @@+# Claude Code - Granular Cost Tracking++Track Claude Code usage by customer or tags using LiteLLM proxy. This enables granular cost attribution for billing, budgeting, and analytics.++## How It Works++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 | `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"+```+++## Quick Start++### 1. Set Environment Variables++```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"+```++### 2. Use Claude Code++```bash+claude+```++All requests will now be tracked under the customer ID `claude-ishaan-local`.++++++++### 3. View Usage in LiteLLM UI++Navigate to the **Logs** tab in the LiteLLM UI.++++Click on a request to see details.++++Filter by customer ID to see all requests for that customer.++++## Supported Headers++| 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)+diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.jsindex 046b38323b2..619bbed6808 100644--- a/docs/my-website/sidebars.js+++ b/docs/my-website/sidebars.js@@ -121,6 +121,7 @@ const sidebars = {label: "Claude Code",items: ["tutorials/claude_responses_api",+ "tutorials/claude_code_customer_tracking","tutorials/claude_mcp","tutorials/claude_non_anthropic_models",]