-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-openrouter-simple.html
More file actions
73 lines (69 loc) · 2.99 KB
/
test-openrouter-simple.html
File metadata and controls
73 lines (69 loc) · 2.99 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
<!DOCTYPE html>
<html>
<head>
<title>OpenRouter API Test</title>
</head>
<body>
<h1>OpenRouter API Test</h1>
<button onclick="testAPI()">Test Current API Key</button>
<div id="result"></div>
<script>
async function testAPI() {
const result = document.getElementById('result');
result.innerHTML = 'Testing...';
try {
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer 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',
'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 in one word"
}
],
max_tokens: 10,
temperature: 0.7
})
});
const data = await response.json();
console.log('Full response:', data);
if (response.ok && data.choices && data.choices[0]) {
result.innerHTML = `
<div style="color: green; border: 1px solid green; padding: 15px; margin: 10px 0;">
<h3>✅ API KEY WORKS!</h3>
<p><strong>Response:</strong> ${data.choices[0].message.content}</p>
<p><strong>Model:</strong> ${data.model}</p>
</div>
`;
} else {
result.innerHTML = `
<div style="color: red; border: 1px solid red; padding: 15px; margin: 10px 0;">
<h3>❌ API KEY FAILED</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>
</div>
`;
}
} catch (error) {
result.innerHTML = `
<div style="color: red; border: 1px solid red; padding: 15px; margin: 10px 0;">
<h3>❌ REQUEST FAILED</h3>
<p>${error.message}</p>
</div>
`;
}
}
</script>
</body>
</html>