All skills
Skillintermediate

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.

Claude Code Knowledge Pack7/10/2026

Overview

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 ByHeaderUse Case
Customerx-litellm-customer-idBill customers, per-user budgets
Tagsx-litellm-tagsProject tracking, cost centers, environments

Environment Variables

VariableDescriptionExample
ANTHROPIC_BASE_URLLiteLLM proxy URLhttp://localhost:4000
ANTHROPIC_API_KEYLiteLLM API keysk-1234
ANTHROPIC_CUSTOM_HEADERSCustom headers (header-name: value format)See examples below

Option 1: Track by Customer

Use this to attribute costs to specific customers or end-users.

Option 2: Track by Tags

Use this to attribute costs to projects, cost centers, or environments. Pass comma-separated tags.

Quick Start

1. Set Environment Variables

2. Use Claude Code

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

HeaderDescription
x-litellm-customer-idTrack by customer/end-user ID
x-litellm-end-user-idAlternative customer ID header
x-litellm-tagsComma-separated tags for cost attribution

Related