PHP code example of token27 / nexus-ai-tracking
1. Go to this page and download the library: Download token27/nexus-ai-tracking library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
token27 / nexus-ai-tracking example snippets
use Token27\NexusAI\Tracking\Engine\TrackingEngine;
use Token27\NexusAI\Tracking\Enum\ExecutionEventType;
// 1. Initialize tracker
$tracker = TrackingEngine::using('sqlite', '/var/data/tracking.sqlite');
// 2. Fluent Event Recording
$tracker
->track(ExecutionEventType::PROMPT_EXECUTED, 'run-abc123')
->withModel('gpt-4o')
->withTokens(1500)
->withCostUsd(0.045)
->withLatencyMs(850)
->with('prompt', [
'source' => 'seo/article',
'version' => 'v2.1',
'content' => 'Prompt content generated here',
])
->with('metadata', [
'title' => 'Article title seo optimized',
'content' => 'Article content seo optimized',
'created' => '2026-05-21'
])
->record();
// 3. Fluent Querying
$metrics = $tracker->query()
->withData('model', 'gpt-4o')
->withLastPeriod('-7 days')
->metrics();
echo "Total cost last 7 days: \${$metrics->totalCostUsd}\n";
echo "Total tokens: {$metrics->totalTokens}\n";
echo "Avg latency: {$metrics->avgLatencyMs}ms\n";