File size: 730 Bytes
608081c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
async function send() {
const key = document.getElementById("apiKey").value;
const model = document.getElementById("model").value;
const prompt = document.getElementById("prompt").value;
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
"HTTP-Referer": "https://example.com"
},
body: JSON.stringify({
model,
messages: [{ role: "user", content: prompt }],
temperature: 0.7
})
});
const data = await res.json();
document.getElementById("response").textContent =
data.choices?.[0]?.message?.content || JSON.stringify(data, null, 2);
}
|