🔗 fix: Provided Azure Base URL Construction for Responses API (#10289)

* fix: response api works with azure base url configured

* add unit test

---------

Co-authored-by: Peter Rothlaender <peter.rothlaender@ginkgo.com>
This commit is contained in:
Peter 2025-10-30 19:57:03 +01:00 committed by GitHub
parent ce6456c39f
commit 658921af88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -737,6 +737,27 @@ describe('getOpenAIConfig', () => {
).toBeUndefined();
});
it('should create correct Azure baseURL when response api is selected', () => {
const azure = {
azureOpenAIApiInstanceName: 'test-instance',
azureOpenAIApiDeploymentName: 'test-deployment',
azureOpenAIApiVersion: '2023-08-15',
azureOpenAIApiKey: 'azure-key',
};
const result = getOpenAIConfig(mockApiKey, {
azure,
modelOptions: { useResponsesApi: true },
reverseProxyUrl:
'https://${INSTANCE_NAME}.openai.azure.com/openai/deployments/${DEPLOYMENT_NAME}',
});
expect(result.configOptions?.baseURL).toBe(
'https://test-instance.openai.azure.com/openai/v1',
);
expect(result.configOptions?.baseURL).not.toContain('deployments');
});
it('should handle Azure with organization from environment', () => {
const originalOrg = process.env.OPENAI_ORGANIZATION;
process.env.OPENAI_ORGANIZATION = 'test-org-123';

View file

@ -113,8 +113,10 @@ export function getOpenAIConfig(
return;
}
const updatedUrl = configOptions.baseURL?.replace(/\/deployments(?:\/.*)?$/, '/v1');
configOptions.baseURL = constructAzureURL({
baseURL: configOptions.baseURL || 'https://${INSTANCE_NAME}.openai.azure.com/openai/v1',
baseURL: updatedUrl || 'https://${INSTANCE_NAME}.openai.azure.com/openai/v1',
azureOptions: azure,
});