PHP code example of kanary / laravel-ai-observatory

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

    

kanary / laravel-ai-observatory example snippets


use Illuminate\Http\Request;
use Kanary\AiObservatory\AiObservatory;

AiObservatory::auth(
    fn (Request $request): bool => $request->user()?->isAdmin() === true,
);

'pricing' => [
    '_meta' => [
        'version' => 'internal-2026-07',
        'effective_date' => '2026-07-01',
    ],
    'provider-name' => [
        'model-name' => [
            'input_per_million' => 10,
            'output_per_million' => 30,
            'cached_input_per_million' => 1,
            'cache_write_input_per_million' => 12.5,
            'currency' => 'USD',
        ],
    ],
],

use Kanary\AiObservatory\Queue\PropagateAiTraceContext;

public function middleware(): array
{
    return [
        new PropagateAiTraceContext,
    ];
}

AiObservatory::withContext([
    'feature' => 'ticket-reply',
    'user' => auth()->user(),
    'tenant' => $organization,
], fn () => SupportAgent::make()->prompt($message));

use Kanary\AiObservatory\AiObservatory;

AiObservatory::redactUsing(function (mixed $payload): mixed {
    // Apply application-specific masking after the built-in redactor.
    return $payload;
});

use Kanary\AiObservatory\AiObservatory;

AiObservatory::registerEventAdapter(App\Observability\CustomAiEventAdapter::class);
bash
composer ai-observatory:install
php artisan migrate
bash
php artisan ai-observatory:recover-stale
php artisan ai-observatory:recover-stale --minutes=30
bash
php artisan ai-observatory:status
php artisan ai-observatory:prune
php artisan ai-observatory:prune --days=30
php artisan ai-observatory:recover-stale
php artisan ai-observatory:clear