|
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); |
|
} |
|
|