Files
9router/open-sse/executors/azure.js
kundeng 6ac3f4a97a feat: add Azure OpenAI as a dedicated provider
Azure OpenAI uses a different URL scheme (deployments-based) and api-key
header auth instead of Bearer tokens. This adds a dedicated AzureExecutor
that constructs the correct URL and headers, plus dashboard UI fields for
endpoint, deployment, API version, and organization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-20 01:06:45 -04:00

58 lines
1.5 KiB
JavaScript

import { DefaultExecutor } from "./default.js";
export class AzureExecutor extends DefaultExecutor {
constructor() {
super("azure");
}
buildUrl(model, stream, urlIndex = 0, credentials = null) {
const azureEndpoint = credentials?.providerSpecificData?.azureEndpoint
|| process.env.AZURE_ENDPOINT
|| "https://api.openai.com";
const apiVersion = credentials?.providerSpecificData?.apiVersion
|| process.env.AZURE_API_VERSION
|| "2024-10-01-preview";
const deployment = credentials?.providerSpecificData?.deployment
|| model
|| process.env.AZURE_DEPLOYMENT
|| "gpt-4";
const endpoint = azureEndpoint.replace(/\/$/, "");
return `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`;
}
buildHeaders(credentials, stream = true) {
const headers = {
"Content-Type": "application/json",
...this.config.headers
};
const apiKey = credentials?.apiKey
|| credentials?.accessToken
|| process.env.OPENAI_API_KEY;
if (apiKey) {
headers["api-key"] = apiKey;
}
const organization = credentials?.providerSpecificData?.organization
|| process.env.AZURE_ORGANIZATION;
if (organization) {
headers["OpenAI-Organization"] = organization;
}
if (stream) {
headers["Accept"] = "text/event-stream";
}
return headers;
}
transformRequest(model, body, stream, credentials) {
return body;
}
}