Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🤖 feat: Azure OpenAI Responses API (#8195)

Danny Avila56ad92fb1c3d
diff --git a/packages/api/src/endpoints/openai/llm.ts b/packages/api/src/endpoints/openai/llm.ts
index 0c3135c554..e5251bb83e 100644
--- a/packages/api/src/endpoints/openai/llm.ts
+++ b/packages/api/src/endpoints/openai/llm.ts
@@ -1,5 +1,6 @@
import { ProxyAgent } from 'undici';
import { KnownEndpoints, removeNullishValues } from 'librechat-data-provider';
+import type { AzureOpenAIInput } from '@langchain/openai';
import type { OpenAI } from 'openai';
import type * as t from '~/types';
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
@@ -42,7 +43,9 @@ export function getOpenAIConfig(
dropParams,
} = options;
const { reasoning_effort, reasoning_summary, ...modelOptions } = _modelOptions;
- const llmConfig: Partial<t.ClientOptions> & Partial<t.OpenAIParameters> = Object.assign(
+ const llmConfig: Partial<t.ClientOptions> &
+ Partial<t.OpenAIParameters> &
+ Partial<AzureOpenAIInput> = Object.assign(
{
streaming,
model: modelOptions.model ?? '',
@@ -100,7 +103,10 @@ export function getOpenAIConfig(
llmConfig.model = process.env.AZURE_OPENAI_DEFAULT_MODEL;
}
- if (configOptions.baseURL) {
+ const constructBaseURL = () => {
+ if (!configOptions.baseURL) {
+ return;
+ }
const azureURL = constructAzureURL({
baseURL: configOptions.baseURL,
azureOptions: updatedAzure,
@@ -108,9 +114,39 @@ export function getOpenAIConfig(
updatedAzure.azureOpenAIBasePath = azureURL.split(
`/${updatedAzure.azureOpenAIApiDeploymentName}`,
)[0];
- }
+ };
+ constructBaseURL();
Object.assign(llmConfig, updatedAzure);
+
+ const constructAzureResponsesApi = () => {
+ if (!llmConfig.useResponsesApi) {
+ return;
+ }
+
+ configOptions.baseURL = constructAzureURL({
+ baseURL: configOptions.baseURL || 'https://${INSTANCE_NAME}.openai.azure.com/openai/v1',
+ azureOptions: llmConfig,
+ });
+
+ delete llmConfig.azureOpenAIApiDeploymentName;
+ delete llmConfig.azureOpenAIApiInstanceName;
+ delete llmConfig.azureOpenAIApiVersion;
+ delete llmConfig.azureOpenAIBasePath;
+ delete llmConfig.azureOpenAIApiKey;
+
+ configOptions.defaultHeaders = {
+ ...configOptions.defaultHeaders,
+ 'api-key': apiKey,
+ };
+ configOptions.defaultQuery = {
+ ...configOptions.defaultQuery,
+ 'api-version': 'preview',
+ };
+ };
+
+ constructAzureResponsesApi();
+
llmConfig.model = updatedAzure.azureOpenAIApiDeploymentName;
} else {
llmConfig.apiKey = apiKey;