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,6 +2,12 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Auth\ApiKeyGuard;
|
||||
use Dedoc\Scramble\Scramble;
|
||||
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
||||
use Dedoc\Scramble\Support\Generator\Server;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -19,6 +25,71 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
// Register custom API-Key Guard for gateway_users authentication
|
||||
Auth::extend('api-key', function ($app, $name, array $config) {
|
||||
return new ApiKeyGuard(
|
||||
Auth::createUserProvider($config['provider']),
|
||||
$app['request']
|
||||
);
|
||||
});
|
||||
|
||||
// Configure Scramble API Documentation
|
||||
Scramble::extendOpenApi(function (OpenApi $openApi) {
|
||||
$openApi->secure(
|
||||
SecurityScheme::http('bearer', 'API-Key')
|
||||
);
|
||||
|
||||
// Add development server
|
||||
$openApi->servers = [
|
||||
new Server('http://localhost', 'Local Development'),
|
||||
];
|
||||
|
||||
// Add comprehensive API description
|
||||
$openApi->info->description = "
|
||||
# Laravel LLM Gateway API
|
||||
|
||||
Multi-provider LLM Gateway supporting OpenAI, Anthropic, Google Gemini, DeepSeek, and Mistral AI.
|
||||
|
||||
## Authentication
|
||||
|
||||
All API requests require authentication via API key in the `Authorization` header:
|
||||
|
||||
```
|
||||
Authorization: Bearer llmg_your_api_key_here
|
||||
```
|
||||
|
||||
Gateway users receive API keys from the admin interface. Each key is linked to a specific gateway user
|
||||
with their own budget limits, rate limits, and provider credentials.
|
||||
|
||||
## Providers
|
||||
|
||||
- **openai** - OpenAI models (GPT-4, GPT-3.5-turbo, etc.)
|
||||
- **anthropic** - Anthropic Claude models (Claude 4, Claude 3.5 Sonnet, etc.)
|
||||
- **google** - Google Gemini models (Gemini Pro, Gemini Flash, etc.)
|
||||
- **deepseek** - DeepSeek models (DeepSeek Chat, DeepSeek Coder)
|
||||
- **mistral** - Mistral AI models (Mistral Large, Mistral Medium, etc.)
|
||||
|
||||
## Rate Limits
|
||||
|
||||
Each gateway user has configurable rate limits (default: 60 requests/hour).
|
||||
Rate limit information is returned in error responses when exceeded.
|
||||
|
||||
## Budgets
|
||||
|
||||
Monthly budget limits are enforced per gateway user. Costs are calculated based on
|
||||
token usage and provider-specific pricing.
|
||||
|
||||
## Error Handling
|
||||
|
||||
The API returns structured error responses:
|
||||
|
||||
- **400**: Bad Request - Invalid parameters
|
||||
- **401**: Unauthorized - Invalid or missing API key
|
||||
- **402**: Payment Required - Budget exceeded
|
||||
- **403**: Forbidden - User blocked
|
||||
- **429**: Too Many Requests - Rate limit exceeded
|
||||
- **500**: Internal Server Error - Unexpected error
|
||||
";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user