PHP code example of fuseboxie / sdk

1. Go to this page and download the library: Download fuseboxie/sdk 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/ */

    

fuseboxie / sdk example snippets




use function Fuseboxie\init;

$fuseboxie = init([
    'projectKey' => getenv('FUSEBOXIE_PROJECT_KEY'),
    'apiUrl' => getenv('FUSEBOXIE_API_URL') ?: 'https://api.fuseboxie.com',
    'guardFailureMode' => 'throw',
]);

$fuseboxie = init([
    'projectKey' => getenv('FUSEBOXIE_PROJECT_KEY'),
    'apiUrl' => 'https://api.fuseboxie.com',
    'caBundlePath' => 'C:\\Program Files\\Git\\mingw64\\etc\\ssl\\certs\\ca-bundle.crt',
]);

$decision = $fuseboxie->canUseAI([
    'userId' => 'user_123',
    'customerId' => 'customer_123',
    'role' => 'trial',
    'estimatedTokens' => 2000,
    'estimatedCostUsd' => 0.02,
    'operation' => 'chat.completion',
]);

if (!$decision['allowed']) {
    throw new RuntimeException($decision['reason'] ?? 'AI usage is blocked.');
}

$response = $openai->chat()->create([...]);

$fuseboxie->trackOpenAI($response, [
    'userId' => 'user_123',
    'customerId' => 'customer_123',
    'role' => 'trial',
    'operation' => 'chat.completion',
]);

$fuseboxie->trackUsage([
    'provider' => 'openai',
    'model' => 'gpt-4.1-mini',
    'inputTokens' => 1200,
    'outputTokens' => 420,
    'userId' => 'user_123',
    'customerId' => 'customer_123',
    'role' => 'trial',
    'operation' => 'chat.completion',
]);

use Fuseboxie\Laravel\Middleware\FuseboxieContext;

Route::middleware([FuseboxieContext::class])->post('/chat', ChatController::class);

use Fuseboxie\Laravel\Facades\Fuseboxie;

$decision = Fuseboxie::canUseAI([
    'estimatedTokens' => 2000,
    'estimatedCostUsd' => 0.02,
    'operation' => 'chat.completion',
]);

if (!$decision['allowed']) {
    abort(402, $decision['reason'] ?? 'AI usage is blocked.');
}

$response = $openai->chat()->create([...]);

Fuseboxie::trackOpenAI($response, [
    'operation' => 'chat.completion',
]);
bash
php artisan vendor:publish --tag=fuseboxie-config