From 1d7a8ca2491226549603f828787113ac3ac37131 Mon Sep 17 00:00:00 2001 From: geronimi73 Date: Thu, 2 Apr 2026 13:19:16 +0200 Subject: [PATCH] separate API calls --- src/ifcchat/api_openai.js | 16 ++++++++++++++++ src/ifcchat/api_openrouter.js | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/ifcchat/api_openai.js create mode 100644 src/ifcchat/api_openrouter.js diff --git a/src/ifcchat/api_openai.js b/src/ifcchat/api_openai.js new file mode 100644 index 0000000000..0fa6d7a88f --- /dev/null +++ b/src/ifcchat/api_openai.js @@ -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(); +} diff --git a/src/ifcchat/api_openrouter.js b/src/ifcchat/api_openrouter.js new file mode 100644 index 0000000000..9a02ee3025 --- /dev/null +++ b/src/ifcchat/api_openrouter.js @@ -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(); +}