Fix API controllers to use correct database column names
- 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}
This commit is contained in:
@@ -68,6 +68,7 @@ class ProviderController extends Controller
|
||||
// Get model count for this provider
|
||||
$modelsCount = ModelPricing::where('provider', $providerId)
|
||||
->where('is_active', true)
|
||||
->whereNotNull('model')
|
||||
->count();
|
||||
|
||||
$providerData[] = [
|
||||
@@ -172,19 +173,20 @@ class ProviderController extends Controller
|
||||
// Get models for this provider
|
||||
$models = ModelPricing::where('provider', $provider)
|
||||
->where('is_active', true)
|
||||
->orderBy('display_name')
|
||||
->whereNotNull('model')
|
||||
->orderBy('model')
|
||||
->get()
|
||||
->map(function ($model) {
|
||||
return [
|
||||
'id' => $model->model_id,
|
||||
'name' => $model->display_name,
|
||||
'id' => $model->model,
|
||||
'name' => $this->getModelDisplayName($model->model),
|
||||
'context_window' => $model->context_window,
|
||||
'max_output_tokens' => $model->max_output_tokens,
|
||||
'supports_streaming' => true, // Default to true for now
|
||||
'supports_function_calling' => in_array($model->provider, ['openai', 'anthropic']),
|
||||
'pricing' => [
|
||||
'input_per_1k' => $model->input_price_per_1k,
|
||||
'output_per_1k' => $model->output_price_per_1k,
|
||||
'input_per_1k' => round($model->input_price_per_million / 1000, 6),
|
||||
'output_per_1k' => round($model->output_price_per_million / 1000, 6),
|
||||
'currency' => 'USD',
|
||||
],
|
||||
];
|
||||
@@ -308,4 +310,14 @@ class ProviderController extends Controller
|
||||
default => '#',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get model display name from model ID
|
||||
*/
|
||||
private function getModelDisplayName(string $modelId): string
|
||||
{
|
||||
// Convert model ID to a readable display name
|
||||
// e.g., "gpt-4-turbo" -> "GPT-4 Turbo"
|
||||
return ucwords(str_replace(['-', '_'], ' ', $modelId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user