PHPackages                             1manfactory/ai-costs - 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. [Payment Processing](/categories/payments)
4. /
5. 1manfactory/ai-costs

ActiveLibrary[Payment Processing](/categories/payments)

1manfactory/ai-costs
====================

Unofficial PHP library for calculating LLM API costs from usage payloads.

v0.1.7(1w ago)046↓25%MITPHPPHP ^8.2CI passing

Since May 4Pushed 2d agoCompare

[ Source](https://github.com/1manfactory/ai-costs)[ Packagist](https://packagist.org/packages/1manfactory/ai-costs)[ RSS](/packages/1manfactory-ai-costs/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (8)Versions (9)Used By (0)

ai-costs
========

[](#ai-costs)

`ai-costs` is an unofficial PHP library for calculating LLM API costs from usage payloads.

It is designed to stay SDK-agnostic: feed it an OpenAI, Anthropic Claude, or Google Gemini usage payload, or a normalized usage object, and it returns a detailed cost breakdown.

Warning

This library provides estimates only. I do not guarantee the accuracy, completeness, or fitness of the calculated values for any billing purpose. The amounts actually billed by the provider are authoritative and always take precedence.

Units
-----

[](#units)

All calculated cost values are returned as integers in `usd_microcent`.

- `usd_microcent` is the only money unit used by this package
- `1 USD = 100_000 usd_microcent`
- `1 usd_microcent = 0.00001 USD = 0.001 cents`
- `1 cent = 1_000 usd_microcent`
- Provider APIs do not return money amounts; they return usage counts, and this package converts those counts into estimated `usd_microcent`
- Public variable and method names use explicit unit suffixes like `InUsdMicrocent`
- The package returns integers only

Current scope
-------------

[](#current-scope)

- OpenAI `Responses API` usage extraction
- OpenAI `Chat Completions API` usage extraction
- Anthropic `Messages API` usage extraction
- Google Gemini `generateContent` usage extraction
- Text token pricing for selected GPT-5.4 and GPT-5.5 family models
- Text token pricing for current Claude and Gemini 2.5 text-output models
- Automatic long-context pricing for `gpt-5.5`, `gpt-5.4`, `gpt-5.4-pro`, and `gemini-2.5-pro`
- Helper charges for web search, file search, and container sessions

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

[](#installation)

```
composer require 1manfactory/ai-costs
```

Quick start
-----------

[](#quick-start)

```
