feat: add Azure OpenAI provider support

This commit is contained in:
decolua
2026-04-24 10:04:59 +07:00
parent 5abc9e5c74
commit 65f11a603e
9 changed files with 236 additions and 6 deletions
+29
View File
@@ -63,6 +63,35 @@ export async function POST(request) {
});
}
if (provider === "azure") {
const { providerSpecificData } = body;
const endpoint = (providerSpecificData?.azureEndpoint || "").replace(/\/$/, "");
const deployment = providerSpecificData?.deployment || "gpt-4";
const apiVersion = providerSpecificData?.apiVersion || "2024-10-01-preview";
const organization = providerSpecificData?.organization;
const url = `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`;
const headers = {
"api-key": apiKey,
"Content-Type": "application/json",
};
if (organization) headers["OpenAI-Organization"] = organization;
const azureRes = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify({
messages: [{ role: "user", content: "test" }],
max_tokens: 1,
}),
});
isValid = azureRes.status !== 401 && azureRes.status !== 403;
return NextResponse.json({
valid: isValid,
error: isValid ? null : "Invalid API key or Azure configuration",
});
}
switch (provider) {
case "openai":
const openaiRes = await fetch("https://api.openai.com/v1/models", {