feat: add OpenAI integration with custom header logging and request aborting

This commit is contained in:
MythEclipse
2026-05-26 01:34:37 +07:00
parent c1c149855a
commit 2156c52c35
2 changed files with 48 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "sk-test",
baseURL: "https://9router.imrnes.team/v1",
fetch: async (url, init) => {
console.log("Headers passed by OpenAI:");
const headers = new Headers(init.headers);
for (const [k, v] of headers.entries()) {
console.log(` ${k}: ${v}`);
}
// abort early to avoid making the request
throw new Error("aborted");
}
});
openai.chat.completions.create({
model: "test",
messages: [{role: "user", content: "test"}]
}).catch(e => {
if (e.message !== "aborted") console.error(e);
});