-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-new-api-key.html
More file actions
103 lines (97 loc) · 4.53 KB
/
test-new-api-key.html
File metadata and controls
103 lines (97 loc) · 4.53 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html>
<head>
<title>Test New OpenRouter API Key</title>
</head>
<body>
<h1>Test New OpenRouter API Key</h1>
<div>
<label for="apiKey">Enter your new API key:</label><br>
<input type="text" id="apiKey" placeholder="sk-or-v1-..." style="width: 500px; padding: 5px; margin: 10px 0;">
<br>
<button onclick="testNewKey()">Test New API Key</button>
</div>
<div id="result"></div>
<script>
async function testNewKey() {
const apiKey = document.getElementById('apiKey').value.trim();
const result = document.getElementById('result');
if (!apiKey) {
result.innerHTML = '<div style="color: red;">Please enter an API key</div>';
return;
}
result.innerHTML = 'Testing new API key...';
try {
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
'HTTP-Referer': 'https://localhost:5173',
'X-Title': 'Chatbot Test'
},
body: JSON.stringify({
model: "meta-llama/llama-3.1-8b-instruct:free",
messages: [
{
role: "user",
content: "Say hello"
}
],
max_tokens: 20,
temperature: 0.7
})
});
const data = await response.json();
console.log('API Test response:', data);
if (response.ok && data.choices && data.choices[0]) {
result.innerHTML = `
<div style="color: green; border: 2px solid green; padding: 20px; margin: 10px 0;">
<h3>🎉 NEW API KEY WORKS!</h3>
<p><strong>Response:</strong> ${data.choices[0].message.content}</p>
<p><strong>Model:</strong> ${data.model}</p>
<div style="background: #f0f8f0; padding: 10px; margin: 10px 0;">
<strong>✅ Your new API key is:</strong><br>
<code style="background: #e0e0e0; padding: 5px;">${apiKey}</code>
</div>
<p><strong>Next steps:</strong></p>
<ol>
<li>Copy this API key</li>
<li>Update your .env file</li>
<li>Update your n8n workflow</li>
<li>Test your chatbot again</li>
</ol>
</div>
`;
} else {
result.innerHTML = `
<div style="color: red; border: 2px solid red; padding: 20px; margin: 10px 0;">
<h3>❌ API KEY STILL NOT WORKING</h3>
<p><strong>Status:</strong> ${response.status}</p>
<p><strong>Error:</strong> ${data.error?.message || JSON.stringify(data)}</p>
<details>
<summary>Full Error Response</summary>
<pre>${JSON.stringify(data, null, 2)}</pre>
</details>
<p><strong>Suggestions:</strong></p>
<ul>
<li>Make sure you're signed in to OpenRouter</li>
<li>Verify your account is activated</li>
<li>Check if you need to add credits</li>
<li>Try creating another new key</li>
</ul>
</div>
`;
}
} catch (error) {
result.innerHTML = `
<div style="color: red; border: 2px solid red; padding: 20px; margin: 10px 0;">
<h3>❌ REQUEST FAILED</h3>
<p>${error.message}</p>
</div>
`;
}
}
</script>
</body>
</html>