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

View File

@@ -0,0 +1,223 @@
<x-app-layout>
<x-slot name="header">
<div class="flex justify-between items-center">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Create New API Key') }}
</h2>
<a href="{{ route('keys.index') }}"
class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
Back to List
</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
<!-- Info Box -->
<div class="mb-6 bg-blue-50 border-l-4 border-blue-400 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-blue-400" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-blue-800">Important Information</h3>
<div class="mt-2 text-sm text-blue-700">
<ul class="list-disc list-inside space-y-1">
<li>The API key will be shown only once after creation</li>
<li>Make sure to copy and store it securely</li>
<li>Keys are associated with a specific user and inherit their budget limits</li>
<li>Expired keys can be deleted but not renewed</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Error Messages -->
@if ($errors->any())
<div class="mb-6 bg-red-50 border-l-4 border-red-400 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">There were errors with your submission</h3>
<div class="mt-2 text-sm text-red-700">
<ul class="list-disc list-inside space-y-1">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
</div>
</div>
</div>
@endif
<!-- Create Form -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900">
<form method="POST" action="{{ route('keys.store') }}" class="space-y-6">
@csrf
<!-- Key Name -->
<div>
<label for="key_name" class="block text-sm font-medium text-gray-700">
Key Name <span class="text-red-500">*</span>
</label>
<div class="mt-1">
<input type="text"
name="key_name"
id="key_name"
value="{{ old('key_name') }}"
required
placeholder="e.g., Production API Key, Development Key, Mobile App Key"
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md @error('key_name') border-red-300 @enderror">
</div>
<p class="mt-2 text-sm text-gray-500">
A descriptive name to identify this key's purpose.
</p>
@error('key_name')
<p class="mt-2 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- User Selection -->
<div>
<label for="user_id" class="block text-sm font-medium text-gray-700">
Associated User <span class="text-red-500">*</span>
</label>
<div class="mt-1">
<select name="user_id"
id="user_id"
required
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md @error('user_id') border-red-300 @enderror">
<option value="">-- Select User --</option>
@foreach($gatewayUsers as $user)
<option value="{{ $user->user_id }}"
{{ old('user_id') == $user->user_id ? 'selected' : '' }}
data-spend="{{ $user->spend }}"
data-budget="{{ $user->budget ? $user->budget->max_budget : 'N/A' }}">
{{ $user->alias ?? $user->user_id }}
(Spend: ${{ number_format($user->spend, 2) }}
@if($user->budget)
/ Budget: ${{ number_format($user->budget->max_budget, 2) }})
@else
/ No Budget)
@endif
</option>
@endforeach
</select>
</div>
<p class="mt-2 text-sm text-gray-500">
The user whose budget and limits will apply to this key.
</p>
@error('user_id')
<p class="mt-2 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Expiration Date (Optional) -->
<div>
<label for="expires_at" class="block text-sm font-medium text-gray-700">
Expiration Date (Optional)
</label>
<div class="mt-1">
<input type="datetime-local"
name="expires_at"
id="expires_at"
value="{{ old('expires_at') }}"
min="{{ now()->format('Y-m-d\TH:i') }}"
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md @error('expires_at') border-red-300 @enderror">
</div>
<p class="mt-2 text-sm text-gray-500">
Leave empty for a key that never expires. The key will be automatically deactivated after this date.
</p>
@error('expires_at')
<p class="mt-2 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Metadata (Optional) -->
<div>
<label for="metadata" class="block text-sm font-medium text-gray-700">
Metadata (Optional)
</label>
<div class="mt-1">
<textarea name="metadata"
id="metadata"
rows="3"
placeholder='{"environment": "production", "app": "mobile"}'
class="shadow-sm focus:ring-blue-500 focus:border-blue-500 block w-full sm:text-sm border-gray-300 rounded-md @error('metadata') border-red-300 @enderror">{{ old('metadata') }}</textarea>
</div>
<p class="mt-2 text-sm text-gray-500">
Optional JSON metadata for tracking additional information about this key.
</p>
@error('metadata')
<p class="mt-2 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Submit Buttons -->
<div class="flex items-center justify-end space-x-4 pt-4">
<a href="{{ route('keys.index') }}"
class="inline-flex justify-center py-2 px-4 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
Cancel
</a>
<button type="submit"
class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
Create API Key
</button>
</div>
</form>
</div>
</div>
<!-- User Info Display -->
<div id="user-info" class="mt-6 bg-white overflow-hidden shadow-sm sm:rounded-lg hidden">
<div class="p-6">
<h3 class="text-lg font-medium text-gray-900 mb-4">Selected User Information</h3>
<dl class="grid grid-cols-1 gap-x-4 gap-y-6 sm:grid-cols-2">
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">Current Spend</dt>
<dd id="user-spend" class="mt-1 text-sm text-gray-900">-</dd>
</div>
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">Budget Limit</dt>
<dd id="user-budget" class="mt-1 text-sm text-gray-900">-</dd>
</div>
</dl>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
// Show user info when a user is selected
document.getElementById('user_id').addEventListener('change', function() {
const selectedOption = this.options[this.selectedIndex];
const userInfo = document.getElementById('user-info');
if (this.value) {
const spend = selectedOption.dataset.spend;
const budget = selectedOption.dataset.budget;
document.getElementById('user-spend').textContent = '$' + parseFloat(spend).toFixed(2);
document.getElementById('user-budget').textContent = budget !== 'N/A' ? '$' + parseFloat(budget).toFixed(2) : 'No Limit';
userInfo.classList.remove('hidden');
} else {
userInfo.classList.add('hidden');
}
});
</script>
@endpush
</x-app-layout>

View File

@@ -0,0 +1,258 @@
<x-app-layout>
<x-slot name="header">
<div class="flex justify-between items-center">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('API Keys Management') }}
</h2>
<a href="{{ route('keys.create') }}"
class="inline-flex items-center px-4 py-2 bg-blue-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-blue-700 focus:bg-blue-700 active:bg-blue-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition ease-in-out duration-150">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
Create New Key
</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<!-- Success/Error Messages -->
@if (session('success'))
<div class="mb-4 bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative" role="alert">
<span class="block sm:inline">{{ session('success') }}</span>
</div>
@endif
@if (session('error'))
<div class="mb-4 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
<span class="block sm:inline">{{ session('error') }}</span>
</div>
@endif
<!-- New API Key Display (only shown once) -->
@if (session('new_api_key'))
<div class="mb-6 bg-yellow-50 border-l-4 border-yellow-400 p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-yellow-400" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-yellow-800">Save this API Key!</h3>
<div class="mt-2 text-sm text-yellow-700">
<p>This is the only time you'll see this key. Copy it now:</p>
<div class="mt-2 flex items-center">
<code id="new-api-key" class="bg-white px-4 py-2 rounded border border-yellow-300 font-mono text-sm">{{ session('new_api_key') }}</code>
<button onclick="copyToClipboard('new-api-key', event)"
class="ml-2 px-3 py-2 bg-yellow-500 text-white rounded hover:bg-yellow-600">
Copy
</button>
</div>
</div>
</div>
</div>
</div>
@endif
<!-- Filters -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg mb-6">
<div class="p-6">
<form method="GET" action="{{ route('keys.index') }}" class="grid grid-cols-1 md:grid-cols-4 gap-4">
<!-- Search -->
<div>
<label for="search" class="block text-sm font-medium text-gray-700 mb-1">Search</label>
<input type="text"
name="search"
id="search"
value="{{ request('search') }}"
placeholder="Key name..."
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm">
</div>
<!-- Status Filter -->
<div>
<label for="status" class="block text-sm font-medium text-gray-700 mb-1">Status</label>
<select name="status"
id="status"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm">
<option value="">All</option>
<option value="active" {{ request('status') == 'active' ? 'selected' : '' }}>Active</option>
<option value="expired" {{ request('status') == 'expired' ? 'selected' : '' }}>Expired</option>
<option value="inactive" {{ request('status') == 'inactive' ? 'selected' : '' }}>Inactive</option>
</select>
</div>
<!-- User Filter -->
<div>
<label for="user_id" class="block text-sm font-medium text-gray-700 mb-1">User</label>
<select name="user_id"
id="user_id"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm">
<option value="">All Users</option>
@foreach($gatewayUsers as $user)
<option value="{{ $user->user_id }}" {{ request('user_id') == $user->user_id ? 'selected' : '' }}>
{{ $user->alias ?? $user->user_id }}
</option>
@endforeach
</select>
</div>
<!-- Submit -->
<div class="flex items-end">
<button type="submit"
class="w-full inline-flex justify-center items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 focus:bg-gray-700 active:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 transition ease-in-out duration-150">
Filter
</button>
</div>
</form>
</div>
</div>
<!-- API Keys Table -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900">
@if($apiKeys->count() > 0)
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Key Name
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
User
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Masked Key
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Status
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Last Used
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Created
</th>
<th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($apiKeys as $key)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm font-medium text-gray-900">
{{ $key->key_name }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900">
<a href="{{ route('gateway-users.show', $key->user_id) }}"
class="text-blue-600 hover:text-blue-900">
{{ $key->gatewayUser->alias ?? $key->user_id }}
</a>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<code class="text-xs text-gray-600 bg-gray-100 px-2 py-1 rounded">
{{ $key->masked_key }}
</code>
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($key->is_active && !$key->is_expired)
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
Active
</span>
@elseif($key->is_expired)
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
Expired
</span>
@else
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
Revoked
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $key->last_used_at ? $key->last_used_at->diffForHumans() : 'Never' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $key->created_at->format('Y-m-d H:i') }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="{{ route('keys.show', $key->token) }}"
class="text-blue-600 hover:text-blue-900 mr-3">View</a>
@if($key->is_active && !$key->is_expired)
<form action="{{ route('keys.revoke', $key->token) }}"
method="POST"
class="inline"
onsubmit="return confirm('Are you sure you want to revoke this API key? This action cannot be undone.');">
@csrf
<button type="submit" class="text-red-600 hover:text-red-900">
Revoke
</button>
</form>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="mt-4">
{{ $apiKeys->links() }}
</div>
@else
<div class="text-center py-12">
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
</svg>
<h3 class="mt-2 text-sm font-medium text-gray-900">No API keys found</h3>
<p class="mt-1 text-sm text-gray-500">Get started by creating a new API key.</p>
<div class="mt-6">
<a href="{{ route('keys.create') }}"
class="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
<svg class="-ml-1 mr-2 h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
New API Key
</a>
</div>
</div>
@endif
</div>
</div>
</div>
</div>
@push('scripts')
<script>
function copyToClipboard(elementId, event) {
const element = document.getElementById(elementId);
const text = element.textContent;
navigator.clipboard.writeText(text).then(() => {
// Show success message
const btn = event.target;
const originalText = btn.textContent;
btn.textContent = 'Copied!';
btn.classList.remove('bg-yellow-500', 'hover:bg-yellow-600');
btn.classList.add('bg-green-500');
setTimeout(() => {
btn.textContent = originalText;
btn.classList.remove('bg-green-500');
btn.classList.add('bg-yellow-500', 'hover:bg-yellow-600');
}, 2000);
}).catch(err => {
alert('Failed to copy: ' + err);
});
}
</script>
@endpush
</x-app-layout>

View File

@@ -0,0 +1,246 @@
<x-app-layout>
<x-slot name="header">
<div class="flex justify-between items-center">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('API Key Details') }}
</h2>
<a href="{{ route('keys.index') }}"
class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
Back to List
</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<!-- Key Information Card -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<div class="flex justify-between items-start mb-6">
<div>
<h3 class="text-lg font-semibold text-gray-900">{{ $apiKey->key_name }}</h3>
<p class="mt-1 text-sm text-gray-500">Created {{ $apiKey->created_at->format('F d, Y \a\t H:i') }}</p>
</div>
<div>
@if($apiKey->is_active && !$apiKey->is_expired)
<span class="px-3 py-1 inline-flex text-sm leading-5 font-semibold rounded-full bg-green-100 text-green-800">
Active
</span>
@elseif($apiKey->is_expired)
<span class="px-3 py-1 inline-flex text-sm leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
Expired
</span>
@else
<span class="px-3 py-1 inline-flex text-sm leading-5 font-semibold rounded-full bg-red-100 text-red-800">
Revoked
</span>
@endif
</div>
</div>
<dl class="grid grid-cols-1 gap-x-4 gap-y-6 sm:grid-cols-2 lg:grid-cols-3">
<!-- Masked Key -->
<div class="sm:col-span-2">
<dt class="text-sm font-medium text-gray-500">Masked Key</dt>
<dd class="mt-1">
<code class="text-sm text-gray-900 bg-gray-100 px-3 py-2 rounded inline-block">
{{ $apiKey->masked_key }}
</code>
</dd>
</div>
<!-- Associated User -->
<div>
<dt class="text-sm font-medium text-gray-500">Associated User</dt>
<dd class="mt-1 text-sm text-gray-900">
<a href="{{ route('gateway-users.show', $apiKey->user_id) }}"
class="text-blue-600 hover:text-blue-900">
{{ $apiKey->gatewayUser->alias ?? $apiKey->user_id }}
</a>
</dd>
</div>
<!-- Last Used -->
<div>
<dt class="text-sm font-medium text-gray-500">Last Used</dt>
<dd class="mt-1 text-sm text-gray-900">
{{ $apiKey->last_used_at ? $apiKey->last_used_at->format('Y-m-d H:i:s') : 'Never' }}
@if($apiKey->last_used_at)
<span class="text-gray-500">({{ $apiKey->last_used_at->diffForHumans() }})</span>
@endif
</dd>
</div>
<!-- Expires At -->
<div>
<dt class="text-sm font-medium text-gray-500">Expires At</dt>
<dd class="mt-1 text-sm text-gray-900">
{{ $apiKey->expires_at ? $apiKey->expires_at->format('Y-m-d H:i:s') : 'Never' }}
@if($apiKey->expires_at)
@if($apiKey->is_expired)
<span class="text-red-600">(Expired)</span>
@else
<span class="text-gray-500">({{ $apiKey->expires_at->diffForHumans() }})</span>
@endif
@endif
</dd>
</div>
<!-- Metadata -->
@if($apiKey->metadata)
<div class="sm:col-span-3">
<dt class="text-sm font-medium text-gray-500">Metadata</dt>
<dd class="mt-1 text-sm text-gray-900">
<pre class="bg-gray-100 p-3 rounded overflow-x-auto"><code>{{ json_encode($apiKey->metadata, JSON_PRETTY_PRINT) }}</code></pre>
</dd>
</div>
@endif
</dl>
<!-- Action Buttons -->
@if($apiKey->is_active && !$apiKey->is_expired)
<div class="mt-6 pt-6 border-t border-gray-200">
<form action="{{ route('keys.revoke', $apiKey->id) }}"
method="POST"
onsubmit="return confirm('Are you sure you want to revoke this API key? This action cannot be undone and all requests using this key will be rejected immediately.');">
@csrf
<button type="submit"
class="inline-flex items-center px-4 py-2 bg-red-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-red-700 focus:bg-red-700 active:bg-red-900 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 transition ease-in-out duration-150">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
Revoke This Key
</button>
</form>
</div>
@endif
</div>
</div>
<!-- Usage Statistics -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<dt class="text-sm font-medium text-gray-500 truncate">Total Requests</dt>
<dd class="mt-1 text-3xl font-semibold text-gray-900">
{{ number_format($stats['total_requests']) }}
</dd>
</div>
</div>
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<dt class="text-sm font-medium text-gray-500 truncate">Total Cost</dt>
<dd class="mt-1 text-3xl font-semibold text-green-600">
${{ number_format($stats['total_cost'], 4) }}
</dd>
</div>
</div>
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<dt class="text-sm font-medium text-gray-500 truncate">Total Tokens</dt>
<dd class="mt-1 text-3xl font-semibold text-purple-600">
{{ number_format($stats['total_tokens']) }}
</dd>
</div>
</div>
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<dt class="text-sm font-medium text-gray-500 truncate">Last 30 Days</dt>
<dd class="mt-1 text-3xl font-semibold text-blue-600">
{{ number_format($stats['last_30_days_requests']) }}
</dd>
<p class="mt-1 text-xs text-gray-500">requests</p>
</div>
</div>
</div>
<!-- Recent Activity -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Recent Activity</h3>
@if($recentLogs->count() > 0)
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Timestamp
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Model
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Provider
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Tokens
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Cost
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Status
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($recentLogs as $log)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
{{ $log->timestamp->format('Y-m-d H:i:s') }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
{{ $log->model }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full
@if($log->provider === 'openai') bg-green-100 text-green-800
@elseif($log->provider === 'anthropic') bg-purple-100 text-purple-800
@else bg-gray-100 text-gray-800
@endif">
{{ ucfirst($log->provider) }}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ number_format($log->total_tokens) }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
${{ number_format($log->cost, 4) }}
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($log->status === 'success')
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
Success
</span>
@else
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
{{ ucfirst($log->status) }}
</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="text-center py-8">
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
<h3 class="mt-2 text-sm font-medium text-gray-900">No activity yet</h3>
<p class="mt-1 text-sm text-gray-500">This API key hasn't been used yet.</p>
</div>
@endif
</div>
</div>
</div>
</div>
</x-app-layout>