-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-key.js
More file actions
50 lines (44 loc) · 1.87 KB
/
Copy pathdebug-key.js
File metadata and controls
50 lines (44 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Debug script to check the exact API key value including whitespace
require('dotenv').config({ path: '.env.local' });
const key = process.env.OPENROUTER_API_KEY;
console.log('=== API KEY DEBUG ===\n');
console.log('Key exists:', !!key);
console.log('Key type:', typeof key);
console.log('Key length:', key ? key.length : 0);
console.log('Key (first 30 chars):', key ? key.substring(0, 30) : 'N/A');
console.log('Key has newlines:', key ? (key.includes('\n') || key.includes('\r')) : false);
console.log('Key has spaces:', key ? (key.trim() !== key) : false);
console.log('Trimmed length:', key ? key.trim().length : 0);
console.log('\nKey starts with:', key ? key.substring(0, 10) : 'N/A');
console.log('Key ends with:', key ? '...' + key.substring(key.length - 10) : 'N/A');
if (key) {
const cleaned = key.trim();
console.log('\n=== TESTING WITH CLEANED KEY ===\n');
const testKey = async () => {
try {
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${cleaned}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'mistralai/mistral-7b-instruct:free',
messages: [{ role: 'user', content: 'test' }],
max_tokens: 5
})
});
console.log('Status:', response.status);
if (response.ok) {
console.log('✅ API KEY WORKS!');
} else {
const error = await response.text();
console.log('❌ API KEY FAILED');
console.log('Error:', error.substring(0, 200));
}
} catch (error) {
console.log('❌ Request failed:', error.message);
}
};
testKey();
}