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:
wtrinkl
2025-11-19 19:36:58 +01:00
parent c65643ac1f
commit cb495e18e3
38 changed files with 1045 additions and 823 deletions

58
IMPLEMENTATION_STATUS.txt Normal file
View File

@@ -0,0 +1,58 @@
Laravel LLM Gateway - Implementierungs-Status
==============================================
Datum: 2025-11-19
Phase 2: API-Key Authentication System ✓ ABGESCHLOSSEN
--------------------------------------------------------
2.1 config/auth.php anpassen ✓
- gateway_users Provider hinzugefügt
- api Guard konfiguriert (driver: api-key)
2.2 ApiKeyGuard implementieren ✓
- Bereits vorhanden und funktional
- Bug-Fix: gateway_user_id statt user_id
2.3 AppServiceProvider für Guard-Registrierung ✓
- Custom Guard 'api-key' registriert
- Auth::extend() implementiert
2.4 Middleware anpassen ✓
- CheckBudget: Nutzt jetzt GatewayUser-Methoden direkt
- CheckRateLimit: Cache-basierte Implementation
Phase 3: API-Code anpassen
---------------------------
3.1 Routes aktualisieren ✓
- routes/api.php bereits korrekt konfiguriert
- auth:api middleware verwendet
- checkbudget und checkratelimit middleware aktiv
3.2 GatewayUser Model erweitern ✓
- Authenticatable Interface implementiert
- Alle Relations (apiKeys, credentials, usageLogs)
- Budget-Helper-Methoden vorhanden
- GatewayUserCredential Model vollständig
3.3 API-Services anpassen ✓
- GatewayService: Verwendet GatewayUser und GatewayUserCredential
- RequestLogger: Nutzt gateway_user_id statt user_id
- LogLlmRequest Job: Schreibt in usage_logs Tabelle
- UsageLog Model: gateway_user_id Foreign Key
- ChatCompletionController: Verwendet auth:api Guard
- ChatCompletionRequest: Validierung für Provider und Model
3.4 Testing & Verification ⏸
- WARTET AUF INTERAKTIVEN TEST
- Backup erstellt: backup_phase3_20251119_084642.sql (32K)
Phase 3: ✓ ABGESCHLOSSEN (Code-seitig)
----------------------------------------
Alle Code-Änderungen implementiert und bereit für Tests.
Nächste Schritte:
-----------------
- Interaktiver Test der API-Funktionalität
- Falls Tests erfolgreich: Phase 4 Admin-Interface erweitern
- Falls Probleme: Debugging und Fixes