feat: add Gemini AI tracking and fix admin dashboard

- Integrated API tracking into analyze-bottle service
- Added credit balance check before Gemini API calls
- Deduct credits after successful Gemini analysis
- Track both successful and failed Gemini API calls
- Added debug logging to admin dashboard for recent API calls
- Fixed error handling in analyze-bottle

Now tracks both Google Search and Gemini AI API usage!
This commit is contained in:
2025-12-18 15:35:02 +01:00
parent b18f8907a3
commit 1cfa9cab8c
2 changed files with 50 additions and 2 deletions

View File

@@ -30,7 +30,8 @@ export default async function AdminPage() {
const stats = await getGlobalApiStats();
// Fetch recent API usage
const { data: recentUsage } = await supabase
console.log('[Admin Page] Fetching recent API usage...');
const { data: recentUsage, error: recentError } = await supabase
.from('api_usage')
.select(`
*,
@@ -41,6 +42,8 @@ export default async function AdminPage() {
.order('created_at', { ascending: false })
.limit(50);
console.log('[Admin Page] Recent usage - count:', recentUsage?.length, 'error:', recentError);
// Fetch per-user statistics
const { data: userStats } = await supabase
.from('api_usage')