- Any-LLM Gateway setup with Docker Compose - Laravel 11 admin interface with Livewire - Dashboard with usage statistics and charts - Gateway Users management with budget tracking - API Keys management with revocation - Budget templates with assignment - Usage Logs with filtering and CSV export - Model Pricing management with calculator - PostgreSQL database integration - Complete authentication system for admins
76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class UsageLog extends Model
|
|
{
|
|
protected $primaryKey = 'id';
|
|
public $incrementing = false;
|
|
protected $keyType = 'string';
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [
|
|
'id',
|
|
'api_key_id',
|
|
'user_id',
|
|
'timestamp',
|
|
'model',
|
|
'provider',
|
|
'endpoint',
|
|
'prompt_tokens',
|
|
'completion_tokens',
|
|
'total_tokens',
|
|
'cost',
|
|
'status',
|
|
'error_message',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'timestamp' => 'datetime',
|
|
'prompt_tokens' => 'integer',
|
|
'completion_tokens' => 'integer',
|
|
'total_tokens' => 'integer',
|
|
'cost' => 'double',
|
|
];
|
|
}
|
|
|
|
public function gatewayUser()
|
|
{
|
|
return $this->belongsTo(GatewayUser::class, 'user_id', 'user_id');
|
|
}
|
|
|
|
public function apiKey()
|
|
{
|
|
return $this->belongsTo(ApiKey::class, 'api_key_id', 'id');
|
|
}
|
|
|
|
public function scopeSuccess($query)
|
|
{
|
|
return $query->where('status', 'success');
|
|
}
|
|
|
|
public function scopeFailed($query)
|
|
{
|
|
return $query->where('status', '!=', 'success');
|
|
}
|
|
|
|
public function scopeToday($query)
|
|
{
|
|
return $query->whereDate('timestamp', today());
|
|
}
|
|
|
|
public function scopeDateRange($query, $start, $end)
|
|
{
|
|
return $query->whereBetween('timestamp', [$start, $end]);
|
|
}
|
|
|
|
public function getCostFormattedAttribute()
|
|
{
|
|
return $this->cost ? '$' . number_format($this->cost, 4) : 'N/A';
|
|
}
|
|
}
|