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:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\LlmRequest;
|
||||
use App\Models\UsageLog;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -19,7 +19,7 @@ class LogLlmRequest implements ShouldQueue
|
||||
public int $maxExceptions = 3;
|
||||
|
||||
public function __construct(
|
||||
private int $userId,
|
||||
private string $userId, // Changed from int to string for gateway_user_id
|
||||
private string $provider,
|
||||
private string $model,
|
||||
private array $requestPayload,
|
||||
@@ -42,8 +42,9 @@ class LogLlmRequest implements ShouldQueue
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
LlmRequest::create([
|
||||
'user_id' => $this->userId,
|
||||
UsageLog::create([
|
||||
'request_id' => $this->requestId,
|
||||
'gateway_user_id' => $this->userId, // Changed from user_id
|
||||
'provider' => $this->provider,
|
||||
'model' => $this->model,
|
||||
'request_payload' => $this->requestPayload,
|
||||
@@ -52,20 +53,17 @@ class LogLlmRequest implements ShouldQueue
|
||||
'completion_tokens' => $this->completionTokens,
|
||||
'total_tokens' => $this->totalTokens,
|
||||
'response_time_ms' => $this->responseTimeMs,
|
||||
'prompt_cost' => $this->promptCost,
|
||||
'completion_cost' => $this->completionCost,
|
||||
'total_cost' => $this->totalCost,
|
||||
'cost' => $this->totalCost, // UsageLog has single 'cost' field
|
||||
'status' => $this->status,
|
||||
'error_message' => $this->errorMessage,
|
||||
'http_status' => $this->httpStatus,
|
||||
'ip_address' => $this->ipAddress,
|
||||
'user_agent' => $this->userAgent,
|
||||
'request_id' => $this->requestId,
|
||||
'timestamp' => now(), // UsageLog uses 'timestamp' instead of created_at
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to log LLM request', [
|
||||
Log::error('Failed to log LLM request to UsageLog', [
|
||||
'error' => $e->getMessage(),
|
||||
'user_id' => $this->userId,
|
||||
'gateway_user_id' => $this->userId,
|
||||
'provider' => $this->provider,
|
||||
'model' => $this->model,
|
||||
'request_id' => $this->requestId,
|
||||
@@ -78,7 +76,7 @@ class LogLlmRequest implements ShouldQueue
|
||||
public function failed(\Throwable $exception): void
|
||||
{
|
||||
Log::critical('LogLlmRequest job failed after all retries', [
|
||||
'user_id' => $this->userId,
|
||||
'gateway_user_id' => $this->userId,
|
||||
'provider' => $this->provider,
|
||||
'model' => $this->model,
|
||||
'request_id' => $this->requestId,
|
||||
|
||||
Reference in New Issue
Block a user