Skip to main content

llmapi-tracker

What API Tracker Is

llmapi-tracker is a local-first API usage and cost observability platform for LLM applications. It records request counts, token usage, latency, errors, and versioned pricing for provider models such as OpenAI and Gemini.

The project is designed to keep data local by default. It stores usage and pricing in a local SQLite database and does not persist prompts, responses, or raw API keys in the application database.

Features

  • Local FastAPI backend with SQLite storage
  • Versioned pricing records for historical cost tracking
  • Usage capture for input, output, thinking, cached, and total tokens
  • Request-level and analytics-level cost calculation
  • React + Vite dashboard for usage, analytics, providers, models, and pricing
  • SDK wrappers for OpenAI and Gemini
  • Packaged launcher command that starts the local app and opens the browser
  • Open-source repository with tests, CI, and release automation

Installation

Prerequisites

  • Python 3.10 or newer
  • Node.js 20 or newer for frontend development

Local development install

python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
cd frontend
npm install

Package install

pip install llmapi-tracker

If you want optional provider SDK support:

pip install "llmapi-tracker[openai]"
pip install "llmapi-tracker[gemini]"
pip install "llmapi-tracker[all]"

Starting the Application

Backend only

uvicorn backend.app.main:app --reload

Frontend only

cd frontend
npm run dev

Packaged app

After the frontend assets are built and packaged into the backend static directory:

api-tracker

The launcher starts the backend server and opens the browser to the local dashboard.

SDK Usage

Initialize the SDK

import os
from api_tracker import APITracker

tracker = APITracker(
    project="Pharmacy-AI",
    backend_url=os.getenv("TRACKER_BACKEND_URL", "http://localhost:8000"),
    openai_api_key=os.getenv("OPENAI_API_KEY"),
    gemini_api_key=os.getenv("GEMINI_API_KEY"),
)

OpenAI

response = tracker.openai.chat(
    model="gpt-5",
    messages=[{"role": "user", "content": "Analyze this prescription"}],
)

Gemini

response = tracker.gemini.generate(
    model="gemini-2.5-flash",
    contents="Analyze this prescription",
)

The SDK reads usage metadata from the provider response and sends it to the local backend automatically.

Database Location

By default, the SQLite database is stored in a stable user data directory so it survives uninstall and reinstall.

The path is resolved in this order:

  1. API_TRACKER_DB_PATH if set
  2. DATABASE_URL if set
  3. A user-data location based on the operating system

Typical defaults:

  • Windows: %LOCALAPPDATA%\\APITracker\\api_tracker.db
  • macOS/Linux: ~/.local/share/APITracker/api_tracker.db

If the preferred user-data directory cannot be created, the app falls back to a writable local .api-tracker-data/ directory in the current workspace.

Configuration

Environment variables:

DATABASE_URL=sqlite:///./api_tracker.db
API_TRACKER_DATA_DIR=
API_TRACKER_DB_PATH=
API_TRACKER_HOST=127.0.0.1
API_TRACKER_PORT=8000
API_TRACKER_OPEN_BROWSER=true
OPENAI_API_KEY=
GEMINI_API_KEY=
TRACKER_BACKEND_URL=http://localhost:8000
VITE_API_BASE_URL=http://localhost:8000

Notes:

  • DATABASE_URL overrides the database connection string
  • API_TRACKER_DATA_DIR sets the user-data root used for SQLite storage
  • API_TRACKER_DB_PATH points directly to a specific SQLite file
  • API_TRACKER_OPEN_BROWSER=false disables browser auto-open for the launcher

Development Setup

Backend

python -m compileall backend sdk tests
pytest -q

Frontend

cd frontend
npm run build

Packaging assets

cd frontend
npm run build
cd ..
python scripts/package_frontend_assets.py
python scripts/verify_frontend_assets.py

Contributing

llmapi-tracker is intended to be open source and contributor friendly.

Contribution files:

Contribution expectations:

  • Open changes through pull requests
  • Require review before merge
  • Keep the app local-first
  • Avoid storing prompts, responses, or raw API keys
  • Add tests for behavior changes

License

llmapi-tracker is released under the MIT License. See LICENSE.

Download files

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

Source Distribution

llmapi_tracker-1.0.3.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

llmapi_tracker-1.0.3-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file llmapi_tracker-1.0.3.tar.gz.

File metadata

  • Download URL: llmapi_tracker-1.0.3.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llmapi_tracker-1.0.3.tar.gz
Algorithm Hash digest
SHA256 3adfa500fa3bf49c916e6deddf1c6bddda0e16f591d24aca5f5d2baadb51a4cc
MD5 e6b02e8b804ee76a190702316466bf85
BLAKE2b-256 b91ec50507a3566218bbcb8f96cf855ed79e5de7dba799d51ec6897c66c94b95

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmapi_tracker-1.0.3.tar.gz:

Publisher: release.yml on Lns9777/API-Usage-Tracker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llmapi_tracker-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: llmapi_tracker-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llmapi_tracker-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ba9d30fe7c11629b9866817c1ace03ba21de252078461441ac568b0b0a82513
MD5 47c18e85dbbfc772cd189369e63879f8
BLAKE2b-256 20329d18d3b55d7fe81c6a096c73c9a5f5e0fcf1605461b0c5a9aa185767245b

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmapi_tracker-1.0.3-py3-none-any.whl:

Publisher: release.yml on Lns9777/API-Usage-Tracker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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