Skip to main content

Track LLM tokens, cost, latency, and model usage in production.

Project description

Spendline Python SDK

Spendline tracks LLM usage in production with one line of code. The SDK captures tokens, model, latency, cost, timestamp, workflow ID, and request metadata without collecting prompt or completion text.

Install

pip install spendline

Quick Start

from openai import OpenAI
from spendline import track

client = OpenAI()

response = track(
    client.chat.completions.create(
        model="gpt-5-mini",
        messages=[{"role": "user", "content": "Say hello"}],
    ),
    workflow_id="support-bot",
    session_id="session-123",
    metadata={"feature": "chat", "environment": "production"},
)

print(response.choices[0].message.content)

Auto-Patch Supported Clients

from spendline import patch

patch()

LangChain

from spendline.langchain import SpendlineCallbackHandler

handler = SpendlineCallbackHandler(workflow_id="chatbot")

Supported Providers

Provider Support
OpenAI track() and patch()
Anthropic track() and patch()
Google Gemini track()
DeepSeek track()
Bedrock track()

Environment Variables

Variable Purpose
SPENDLINE_API_KEY Default ingest key
SPENDLINE_API_URL Override API base URL
SPENDLINE_DISABLE Disable tracking when true
SPENDLINE_LOG Print tracked events locally

Privacy

Spendline does not collect:

  • Prompt text
  • Completion text
  • Raw request bodies
  • Secrets from your application context

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spendline-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spendline-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file spendline-0.1.0.tar.gz.

File metadata

  • Download URL: spendline-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for spendline-0.1.0.tar.gz
Algorithm Hash digest
SHA256 915a2887569164aa2b901d35a0bb20f95dbea415b1fb247c756990cc9d303265
MD5 c9ee8085a78eca51f74d37fbaaa907c3
BLAKE2b-256 b8c0b0ce4d44685db5f9927facd79e73d269f0a6a282aa0c0fe7a24c80cc58ed

See more details on using hashes here.

File details

Details for the file spendline-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spendline-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for spendline-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c85e8c46b2163e962b0e96915fb7081abf549100bbb09aed9d30f3d100cdb506
MD5 5e579ba62133b93b7d31ce444eeba6bf
BLAKE2b-256 eba4e8e09d75b624a4dc0296459f0d8710e851ef133b6c31fabed6a49b79d049

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page