Rename project from any-llm to laravel-llm

- Remove old any-llm related files (Dockerfile, config.yml, web/, setup-laravel.sh)
- Update README.md with new Laravel LLM Gateway documentation
- Keep docker-compose.yml with laravel-llm container names
- Clean project structure for Laravel-only implementation
This commit is contained in:
wtrinkl
2025-11-18 22:05:05 +01:00
parent b1363aeab9
commit bef36c7ca2
33 changed files with 1341 additions and 2930 deletions

View File

@@ -70,52 +70,39 @@ class ApiKeyController extends Controller
{
$validated = $request->validate([
'key_name' => 'required|string|max:255',
'user_id' => 'required|string|exists:users,user_id',
'user_id' => 'required|string|exists:gateway_users,user_id',
'expires_at' => 'nullable|date|after:now',
'metadata' => 'nullable|json',
]);
try {
// Get master key from config
$masterKey = env('GATEWAY_MASTER_KEY');
if (!$masterKey) {
return back()->with('error', 'Gateway Master Key not configured');
// Generate a unique API token
$token = 'llmg_' . Str::random(48);
// Parse metadata if provided
$metadata = null;
if (!empty($validated['metadata'])) {
$metadata = json_decode($validated['metadata'], true);
if (json_last_error() !== JSON_ERROR_NONE) {
return back()->with('error', 'Invalid JSON in metadata field');
}
}
// Prepare request payload
$payload = [
// Create API key directly in database
$apiKey = ApiKey::create([
'token' => $token,
'user_id' => $validated['user_id'],
'key_name' => $validated['key_name'],
];
'key_alias' => $validated['key_name'], // Use key_name as alias
'expires' => $validated['expires_at'] ?? null,
'metadata' => $metadata,
'permissions' => [], // Default empty permissions
'models' => [], // Default empty models
]);
// Add optional fields only if they have values
if (!empty($validated['expires_at'])) {
$payload['expires_at'] = $validated['expires_at'];
}
if (!empty($validated['metadata'])) {
$payload['metadata'] = json_decode($validated['metadata'], true) ?: new \stdClass();
}
// Create Virtual Key via Any-LLM Gateway API
$response = Http::withHeaders([
'X-AnyLLM-Key' => 'Bearer ' . $masterKey,
'Content-Type' => 'application/json',
])->post(env('GATEWAY_API_URL', 'http://gateway:8000') . '/v1/keys', $payload);
if (!$response->successful()) {
Log::error('Failed to create API key', [
'status' => $response->status(),
'body' => $response->body()
]);
return back()->with('error', 'Failed to create API key: ' . $response->body());
}
$data = $response->json();
// The actual key is only available once - store it in session for display
session()->flash('new_api_key', $data['key'] ?? null);
session()->flash('new_api_key_id', $data['id'] ?? null);
// Store the token in session for one-time display
session()->flash('new_api_key', $token);
session()->flash('new_api_key_id', $apiKey->token);
return redirect()->route('api-keys.index')
->with('success', 'API Key created successfully! Make sure to copy it now - it won\'t be shown again.');
@@ -160,26 +147,8 @@ class ApiKeyController extends Controller
try {
$apiKey = ApiKey::findOrFail($id);
// Get master key from config
$masterKey = env('GATEWAY_MASTER_KEY');
if (!$masterKey) {
return back()->with('error', 'Gateway Master Key not configured');
}
// Revoke via Any-LLM Gateway API
$response = Http::withHeaders([
'X-AnyLLM-Key' => 'Bearer ' . $masterKey,
'Content-Type' => 'application/json',
])->delete(env('GATEWAY_API_URL', 'http://gateway:8000') . '/v1/keys/' . $id);
if (!$response->successful()) {
Log::error('Failed to revoke API key', [
'key_id' => $id,
'status' => $response->status(),
'body' => $response->body()
]);
return back()->with('error', 'Failed to revoke API key: ' . $response->body());
}
// Delete the API key from database
$apiKey->delete();
return redirect()->route('api-keys.index')
->with('success', 'API Key revoked successfully');