Download the PHP package tokentifyai/usagemeter without Composer
On this page you can find all versions of the php package tokentifyai/usagemeter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tokentifyai/usagemeter
More information about tokentifyai/usagemeter
Files in tokentifyai/usagemeter
Package usagemeter
Short Description Out-of-band AI API usage metering SDK
License MIT
Homepage https://github.com/infinistackai/tokentify-sdk-php
Informations about the package usagemeter
Tokentify UsageMeter (PHP)
Out-of-band AI API usage metering for PHP. After setup, call your provider’s HTTP API yourself, then record usage with Meter::track() (the PHP SDK does not auto-wrap HTTP clients).
Install
Optional: load .env in development (recommended):
Setup
1. Environment (API key is global)
Copy .env.example to .env. The API key lives only in .env (or your deployment environment)—never in init() code.
2. Initialize
| Call | When to use |
|---|---|
Tokentify::init(..., ['verify_connection' => true, 'verify_api_key' => true]) |
First run; verifies collector + USAGEMETER_API_KEY from .env |
Tokentify::init(...) |
Same; control verify_connection / verify_api_key |
Init parameters (API key is not accepted):
| Parameter | Source |
|---|---|
bucket |
First argument (value of USAGEMETER_BUCKET) or USAGEMETER_BUCKET in .env |
tracking_fields |
Second argument (must include account_id, user_id) |
app_name |
Third-argument merge array or USAGEMETER_APP_NAME in .env |
environment |
Merge array or USAGEMETER_ENVIRONMENT in .env (default production) |
load_env_file |
Default true when phpdotenv is installed — loads .env before reading env vars |
verify_connection |
Default false (set true for first-time setup) |
verify_api_key |
Default true |
Call init() before provider HTTP calls and Meter::track() events.
Agent tool tracking
After your app executes a tool (any provider / agent framework), call
Meter::trackTool() once:
Provider APIs expose tool-call data in different places (response content vs
client-side MCP loops; never in billing usage). See the
provider research matrix
before adding auto-capture.
Token breakdown (v0.4.0)
The SDK extracts input, output, cache read, and cache write tokens from provider JSON via UsageParser.
Recommended — trackFromResponse
Alternative — track(['response_body' => ...])
Field mapping
| Ingest field | Anthropic source | OpenAI source |
|---|---|---|
input_tokens |
usage.input_tokens |
prompt_tokens − cached_tokens |
output_tokens |
usage.output_tokens |
usage.completion_tokens |
cache_read_tokens |
usage.cache_read_input_tokens |
usage.prompt_tokens_details.cached_tokens |
cache_write_tokens |
usage.cache_creation_input_tokens |
— |
Anti-pattern
3. Launch (v0.4.0)
.env (USAGEMETER_API_KEY + USAGEMETER_BUCKET):
app.php:
4. Develop from this repo
Quick init check:
All versions of usagemeter with dependencies
ext-json Version *