- Fix model_pricing table references (model_id -> model, display_name -> model)
- Fix price columns (output_price_per_1k -> output_price_per_million)
- Add price conversion (per_million / 1000 = per_1k) in all API responses
- Add whereNotNull('model') filters to exclude invalid entries
- Add getModelDisplayName() helper method to all controllers
- Fix AccountController to use gateway_users budget fields directly
- Remove Budget model dependencies from AccountController
- Add custom Scramble server URL configuration for API docs
- Create ScrambleServiceProvider to set correct /api prefix
- Add migration to rename user_id to gateway_user_id in llm_requests
- Add custom ApiGuard for gateway_users authentication
- Update all API controllers: AccountController, ModelController, PricingController, ProviderController
All API endpoints now working correctly:
- GET /api/account
- GET /api/models
- GET /api/pricing
- GET /api/providers/{provider}
61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Budget extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'budgets';
|
|
protected $primaryKey = 'budget_id';
|
|
public $incrementing = false;
|
|
protected $keyType = 'string';
|
|
|
|
protected $fillable = [
|
|
'budget_id',
|
|
'name',
|
|
'monthly_limit',
|
|
'daily_limit',
|
|
'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'monthly_limit' => 'decimal:2',
|
|
'daily_limit' => 'decimal:2',
|
|
];
|
|
|
|
/**
|
|
* Get formatted max budget display
|
|
*/
|
|
public function getMaxBudgetFormattedAttribute(): string
|
|
{
|
|
if ($this->monthly_limit) {
|
|
return '$' . number_format($this->monthly_limit, 2);
|
|
}
|
|
if ($this->daily_limit) {
|
|
return '$' . number_format($this->daily_limit, 2) . '/day';
|
|
}
|
|
return 'Unlimited';
|
|
}
|
|
|
|
/**
|
|
* Get human-readable duration
|
|
*/
|
|
public function getDurationHumanAttribute(): string
|
|
{
|
|
if ($this->monthly_limit && $this->daily_limit) {
|
|
return 'Monthly';
|
|
}
|
|
if ($this->daily_limit && !$this->monthly_limit) {
|
|
return 'Daily';
|
|
}
|
|
return 'Unlimited';
|
|
}
|
|
|
|
// Note: gateway_users have their own budget system (monthly_budget_limit, current_month_spending)
|
|
// and are not linked to this budgets table
|
|
}
|