PHP code example of aaix / laravel-ai-costs

1. Go to this page and download the library: Download aaix/laravel-ai-costs 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/ */

    

aaix / laravel-ai-costs example snippets


use Aaix\LaravelAiCosts\Concerns\TracksAiCost;

class MyAgent implements \Laravel\Ai\Contracts\Agent
{
    use TracksAiCost; // replaces Promptable
}

$agent = MyAgent::make();
$agent->prompt('...');

$agent->lastCost()->totalCostUsd; // 0.000345
$agent->totalCostUsd();           // sum across all prompts on this instance