PHPackages                             tourze/anthropic-token-usage-bundle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/anthropic-token-usage-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/anthropic-token-usage-bundle
===================================

Symfony bundle for tracking Anthropic API token usage

1.0.2(5mo ago)00MITPHPPHP ^8.2CI passing

Since Nov 3Pushed 5mo agoCompare

[ Source](https://github.com/tourze/anthropic-token-usage-bundle)[ Packagist](https://packagist.org/packages/tourze/anthropic-token-usage-bundle)[ RSS](/packages/tourze-anthropic-token-usage-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (41)Versions (4)Used By (0)

Anthropic Token Usage Bundle
============================

[](#anthropic-token-usage-bundle)

[中文](README.zh-CN.md) | [English](README.md)

A Symfony bundle for tracking and analyzing Anthropic API token usage with comprehensive statistics, admin interface, and data aggregation capabilities.

Features
--------

[](#features)

- **Token Usage Tracking**: Track input/output tokens, cache usage, and request counts
- **Multi-dimensional Analysis**: Support for both AccessKey and User-based usage tracking
- **Data Aggregation**: Pre-aggregated statistics by hour, day, and month
- **Admin Interface**: EasyAdmin integration for browsing usage data
- **Async Processing**: Symfony Messenger integration for high-performance usage collection
- **Batch Processing**: Support for bulk usage data collection
- **Comprehensive Metrics**: Cache creation/read tokens, request details, and more
- **Data Quality Monitoring**: Built-in metrics for data consistency and completeness

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

[](#installation)

```
composer require tourze/anthropic-token-usage-bundle
```

Configuration
-------------

[](#configuration)

### 1. Enable the Bundle

[](#1-enable-the-bundle)

Add the bundle to your `bundles.php`:

```
return [
    // ...
    Tourze\AnthropicTokenUsageBundle\AnthropicTokenUsageBundle::class => ['all' => true],
];
```

### 2. Database Schema

[](#2-database-schema)

The bundle will automatically create the following database tables:

- `access_key_usage`: Individual AccessKey usage records
- `user_usage`: Individual user usage records
- `usage_statistics`: Pre-aggregated statistics

### 3. Configure Messenger (Optional)

[](#3-configure-messenger-optional)

For async usage collection, configure Symfony Messenger:

```
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'

        routing:
            'Tourze\AnthropicTokenUsageBundle\Message\UsageCollectionMessage': async
```

Usage
-----

[](#usage)

### Basic Usage Collection

[](#basic-usage-collection)

```
