Anthropic with LangSpend (Python)

← Back to Docs

Track Anthropic Claude API costs with zero-code attribution in Python

Learn how to track Anthropic Claude API costs with LangSpend in Python. Works with Claude-4.5 Opus, Sonnet, and Haiku models and all the other Anthropic models.

Installation

Install required packages

Using pip:

terminal

Using uv:

terminal

Or install with Anthropic extras:

terminal

Basic Setup

Wrap your Anthropic client

setup.py

Claude Messages

Claude 4 Opus Example with Customer & Feature Tracking

💡 Custom Metadata: Use the meta property in customer and feature dictionaries to pass any custom properties for advanced tracking and analytics.

claude-chat.py