separate API calls

This commit is contained in:
geronimi73
2026-04-02 13:19:16 +02:00
committed by Thomas Krijnen
parent eaf7950677
commit 1d7a8ca249
2 changed files with 32 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
export async function chat({ apiKey, model, messages, tools }) {
const res = await fetch("https://api.openai.com/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(`OpenAI error ${res.status}: ${text}`);
}
return await res.json();
}
+16
View File
@@ -0,0 +1,16 @@
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();
}