Track LLM costs in your Python applications with zero-code attribution

Installation

Install the LangSpend Python SDK to start tracking your LLM costs in Python applications. The SDK is published to PyPI and includes full type hints support.

Install the Package

Using pip (recommended)

terminal

Using uv (fast alternative)

terminal

uv is a fast Python package manager. Install it with: pip install uv

Provider-specific installations

Using pip:

terminal

Using uv:

terminal

Get Your API Key

LangSpend is a commercial SaaS product with a free tier available.

Get your LangSpend API key at app.langspend.com - Sign up here

Environment Variables

Set up your environment variables:

.env

Type Hints Support

The SDK is written in Python with full type hints support:

types.py

CLI Support

The LangSpend Python SDK includes a command-line interface for testing and debugging.

terminal

Framework Support

FastAPI

Perfect for building APIs with automatic request tracking.

Django

Integrate with Django views and middleware for comprehensive tracking.

Flask

Lightweight integration with Flask applications and decorators.