PHPackages                             boriskwemo/llm-ledger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. boriskwemo/llm-ledger

ActiveLibrary

boriskwemo/llm-ledger
=====================

Framework-agnostic PHP package to call and track costs of LLMs (OpenAI, Anthropic, Google, Mistral, DeepSeek, Qwen and more) with a unified API, a bundled model registry, and Symfony 8 / Laravel integrations.

v1.0.0(today)10MITPHPPHP &gt;=8.2

Since Aug 29Pushed todayCompare

[ Source](https://github.com/boriskwemo/llm-ledger)[ Packagist](https://packagist.org/packages/boriskwemo/llm-ledger)[ RSS](/packages/boriskwemo-llm-ledger/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (7)Versions (2)Used By (0)

LLM Ledger - PHP LLM Cost Tracking &amp; Multi-Provider AI Gateway
==================================================================

[](#llm-ledger---php-llm-cost-tracking--multi-provider-ai-gateway)

> Track, analyze and **control your LLM spend** from one clean PHP API - compatible with **OpenAI, Anthropic, Google Gemini, Mistral, DeepSeek, Qwen, Kimi, GLM, Grok** and any OpenAI-compatible endpoint. Works natively with **Symfony 8** and **Laravel**, installs from **Composer**, and ships with a **customizable cost dashboard**, a **deprecation-aware model catalog** and **batch processing** - all under the **MIT license**.

```
$llm = Llm::fromYaml('llm.yaml');

$result = $llm->chat('deepseek-chat', 'Explain quantum computing in one sentence.');

echo $result->text();              // the answer
echo $result->usage->totalTokens;  // 42
echo $result->usage->reasoningTokens; // hidden thinking tokens, exposed
echo $result->cost->total;         // 0.000123  (USD)
```

Every call - tokens, reasoning tokens, latency, model, provider and dollar cost - is recorded automatically and visualized in a dashboard. **No more guessing what AI actually costs you.**

---

Table of contents
-----------------

[](#table-of-contents)

1. [Why LLM Ledger?](#why-llm-cost-tracker)
2. [Features](#features)
3. [Who is it for?](#who-is-it-for)
4. [How it compares](#how-it-compares)
5. [Requirements](#requirements)
6. [Installation](#installation)
7. [Quickstart](#quickstart-plain-php)
8. [Configuration](#configuration-llmyaml)
9. [Model registry &amp; deprecation](#model-registry--deprecation)
10. [Thinking / reasoning tokens](#tracking-thinking--reasoning-tokens)
11. [Batch processing](#batch-processing)
12. [API key handling](#api-key-handling)
13. [Symfony 8 integration](#symfony-8-integration)
14. [Laravel integration](#laravel-integration)
15. [CLI](#cli)
16. [Model coverage](#model-coverage)
17. [Architecture](#architecture)
18. [Testing](#testing)
19. [Contributing](#contributing)
20. [Security](#security)
21. [License](#license)

Why LLM Ledger?
---------------

[](#why-llm-ledger)

Modern apps rarely use one AI provider. They use **four or five** - a frontier model from OpenAI, Claude for coding, Gemini for long context, DeepSeek or Qwen when cost matters, Mistral for EU data residency. That fragmentation creates three real problems:

Pain pointWhat you hit todayWhat LLM Ledger does**N vendor SDKs**A different client, auth, and response shape for every providerOne `chat()` / `complete()` / `batch()` API across 19 providers**Invisible spend**Reasoning/thinking tokens and cache reads silently change your billNormalizes and stores `reasoning_tokens`, cache reads/writes, finish reason and tool calls**No oversight**You find out the bill at the end of the monthPer-call cost, per-model/per-provider/per-day aggregates, dashboard + CLI**Surprise deprecations**A model disappears and your code breaksA deprecation-aware model registry (`superseded_by`, `date`, `note`)The result: **one dependency instead of five, and a complete, queryable audit trail of your AI usage and cost** - for free, open-source, without locking you into a gateway or a hosted dashboard.

Features
--------

[](#features)

- **Unified multi-provider API** - a single `chat()` method for OpenAI, Anthropic, Google, Mistral, DeepSeek, Qwen, xAI, Groq, Cohere and any OpenAI-compatible server (vLLM, LiteLLM, local endpoints).
- **American, French &amp; Chinese models** - OpenAI · Anthropic · Google · xAI · Groq · Cohere · Meta (US), Mistral · Kyutai · LightOn (France), DeepSeek · Qwen · Kimi · GLM · Ernie · MiniMax · Doubao · Hunyuan (China).
- **Automatic cost tracking** - per-call token usage and USD cost, including cached-input and Anthropic cache-write pricing, aggregated by model/provider/day.
- **Thinking / reasoning token visibility** - captures reasoning text and token counts across providers so no token is invisible in your bill.
- **Batch processing** - run hundreds of prompts through OpenAI, Anthropic or Gemini batch APIs with one `batch()` call and track every item.
- **Deprecation-aware model registry** - curated, editable YAML with descriptions, context windows, pricing, modalities and a `deprecated` / `superseded_by` lifecycle.
- **YAML configuration** - providers, storage, defaults and UI in one `llm.yaml`.
- **Customizable dashboard** - light/dark themable UI with Twig (Symfony), Blade (Laravel) and a standalone PHP version; every template is overridable.
- **Secure by default** - API keys live in memory only and are never persisted or logged.
- **CLI** - `models:list`, `models:show`, `usage:report`, `call`.

Who is it for?
--------------

[](#who-is-it-for)

- **SaaS &amp; AI-feature teams** that call multiple LLMs and need to bill customers or teams accurately.
- **Symfony / Laravel shops** that want a first-class, idiomatic integration - autowired service or facade - not a raw HTTP client.
- **Agencies &amp; indie developers** who want to track AI spend per client or project without building infrastructure.
- **Cost-conscious engineers** comparing models (GPT vs Claude vs Gemini vs DeepSeek vs Qwen) on real, recorded numbers.

How it compares
---------------

[](#how-it-compares)

Raw vendor SDKsGeneric HTTP client**LLM Ledger**Multi-provider, one API❌ one SDK per vendor⚠️ you wire each one✅ 19 providers, one APIAutomatic cost tracking❌❌ manual math✅ + dashboard &amp; CLIReasoning/thinking token visibility⚠️ vendor-specific parsing❌✅ normalizedBatch across providers❌ per-SDK❌✅ one `batch()`Model deprecation awareness❌❌✅ built-in registrySymfony 8 &amp; Laravel supportDIYDIY✅ bundle + provider + facadeOpen source / self-hosted--✅ MIT, data stays with youRequirements
------------

[](#requirements)

- PHP **8.2+** (Symfony 8.1 requires 8.4+, Laravel 12 requires 8.2+)
- `ext-json`, `ext-pdo`
- [Composer](https://getcomposer.org)

Installation
------------

[](#installation)

```
composer require boriskwemo/llm-ledger
```

Quickstart (plain PHP)
----------------------

[](#quickstart-plain-php)

```
