Dynamic Intelligence commited on
Commit
6e4988e
·
1 Parent(s): abd54b8

Fix 401 error: Add authenticated API proxy for private datasets

Browse files
Files changed (1) hide show
  1. src/app/api/hf-proxy/route.ts +8 -4
src/app/api/hf-proxy/route.ts CHANGED
@@ -25,12 +25,16 @@ async function handleRequest(request: NextRequest, method: 'GET' | 'HEAD') {
25
  }
26
 
27
  // Get token from environment variable (set in Hugging Face Space secrets)
28
- const token = process.env.HF_TOKEN || process.env.HUGGINGFACE_TOKEN;
 
29
 
 
30
  if (!token) {
31
- // If no token, try without auth (for public repos)
32
- // But log a warning
33
- console.warn('HF_TOKEN not configured in Space secrets - requests may fail for private repos');
 
 
34
  }
35
 
36
  try {
 
25
  }
26
 
27
  // Get token from environment variable (set in Hugging Face Space secrets)
28
+ // Hugging Face Spaces automatically inject secrets as environment variables
29
+ const token = process.env.HF_TOKEN || process.env.HUGGINGFACE_TOKEN || process.env.HF_API_TOKEN;
30
 
31
+ // Log token status for debugging (don't log actual token value)
32
  if (!token) {
33
+ console.error('❌ HF_TOKEN not found in environment variables!');
34
+ console.error('Available env vars:', Object.keys(process.env).filter(k => k.includes('HF') || k.includes('TOKEN')).join(', '));
35
+ console.warn('⚠️ Requests to private repos will fail with 401');
36
+ } else {
37
+ console.log('✓ HF_TOKEN found in environment (length:', token.length, 'chars)');
38
  }
39
 
40
  try {