- 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}
63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
class GatewayUserCredential extends Model
|
|
{
|
|
protected $fillable = [
|
|
'gateway_user_id',
|
|
'provider',
|
|
'api_key',
|
|
'organization_id',
|
|
'is_active',
|
|
'last_used_at',
|
|
'last_tested_at',
|
|
'test_status',
|
|
'test_error',
|
|
];
|
|
|
|
protected $hidden = ['api_key'];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'last_used_at' => 'datetime',
|
|
'last_tested_at' => 'datetime',
|
|
];
|
|
|
|
|
|
// Automatic encryption for API keys
|
|
public function setApiKeyAttribute($value): void
|
|
{
|
|
$this->attributes['api_key'] = Crypt::encryptString($value);
|
|
}
|
|
|
|
public function getApiKeyAttribute($value): string
|
|
{
|
|
return Crypt::decryptString($value);
|
|
}
|
|
|
|
// Relationships
|
|
public function gatewayUser()
|
|
{
|
|
return $this->belongsTo(GatewayUser::class, 'gateway_user_id', 'user_id');
|
|
}
|
|
|
|
// Helper methods
|
|
public function markAsUsed(): void
|
|
{
|
|
$this->update(['last_used_at' => now()]);
|
|
}
|
|
|
|
public function markAsTested(bool $success, ?string $error = null): void
|
|
{
|
|
$this->update([
|
|
'last_tested_at' => now(),
|
|
'test_status' => $success ? 'success' : 'failed',
|
|
'test_error' => $error,
|
|
]);
|
|
}
|
|
}
|