Spaces:
Paused
Paused
dr-data
Fix preview component: eliminate blinking, ensure HTML updates, add smooth transitions
dcd5e1d
π OpenRouter Model Loading Debug Guide
π Issue: Cannot load models via OpenRouter
π Debugging Steps Added
I've added comprehensive logging to help identify the issue:
Hook Debugging (
/hooks/useOpenRouterModels.ts):- Console logs for fetch start/end
- Response status logging
- Model count logging
API Route Debugging (
/app/api/openrouter/models/route.ts):- Request logging
- API key status logging
- Success/error logging
OpenRouter Client Debugging (
/lib/openrouter.ts):- Request headers logging
- Response status logging
- Error details logging
Component Debugging (
/components/openrouter-model-selector/index.tsx):- Render state logging
π§ Fixes Applied
- Fixed Infinite Loop: Removed dependency array issue in useOpenRouterModels hook
- Updated Referer: Changed from
deepsite.hf.cotolocalhost:3000for local development - Enhanced Error Handling: Better error messages and logging
π§ͺ How to Debug
Step 1: Open Browser Console
- Go to
http://localhost:3000 - Open Developer Tools (F12)
- Go to Console tab
Step 2: Test Settings Panel
- Open the AI chat settings
- Toggle "Use Custom OpenRouter Models" ON
- Watch console for logs starting with:
- π (fetch start)
- π‘ (request details)
- π₯ (response status)
- β (success) or β (error)
Step 3: Test Model Selector
- Click "Select Model" button
- Watch console for:
- π OpenRouterModelSelector render logs
- Loading state changes
- Model count updates
Step 4: Test Direct API
- Go to
http://localhost:3000/test-openrouter.html - Click "Test API" button
- Check both page result and console logs
π Common Issues to Look For
Network Issues
- Check Console β Network tab
- Look for
/api/openrouter/modelsrequest - Status should be 200, not 404/500
CORS Issues
- Error messages mentioning CORS
- OpenRouter API blocking requests
- Referer header issues
API Rate Limiting
- OpenRouter returning 429 status
- "Too many requests" errors
Environment Issues
- Missing environment variables
- Local development configuration
Code Issues
- JavaScript errors in console
- Component not mounting
- Hook not calling fetch
π Expected Console Output
Successful Flow:
π Fetching OpenRouter models...
π‘ Requesting: http://localhost:3000/api/openrouter/models
π OpenRouter models API called
π API key provided: false
π‘ Fetching models from OpenRouter...
π Headers: ['Content-Type', 'HTTP-Referer', 'X-Title']
π₯ OpenRouter API response status: 200
β
OpenRouter API returned 200+ models
β
Successfully fetched 200+ models from OpenRouter
π₯ Response status: 200
π Response data: { success: true, data: [...] }
β
Successfully fetched 200+ models
π OpenRouterModelSelector render: { modelsCount: 200+, loading: false, error: null }
Error Flow Examples:
β Error fetching models: Failed to fetch
β OpenRouter API error: 403 Forbidden
β Network error: fetch failed
π¨ If Still Not Working
Check 1: API Endpoint Accessibility
Try: http://localhost:3000/api/openrouter/models
Should return JSON with success: true
Check 2: OpenRouter API Direct
Try: https://openrouter.ai/api/v1/models
Should return list of models
Check 3: Network Tab
- Failed requests (red)
- CORS errors
- Timeout issues
Check 4: Console Errors
- JavaScript compilation errors
- React component errors
- Network fetch errors
Let me know what you see in the console and I'll help identify the specific issue! π§