Files
IfcOpenShell/src/ifcchat/api_openrouter.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

17 lines
525 B
JavaScript
Raw Normal View History

2026-04-02 13:19:16 +02:00
export async function chat({ apiKey, model, messages, tools }) {
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`,
},
body: JSON.stringify({ model, messages, tools }),
});
if (!res.ok) {
const text = await res.text();
throw new Error(`OpenRouter error ${res.status}: ${text}`);
}
return await res.json();
}