Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: allow azure openai to pass custom uri #920

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/handlers/handlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ export function constructConfigFromRequestHeaders(
openaiBeta:
requestHeaders[`x-${POWERED_BY}-openai-beta`] ||
requestHeaders[`openai-beta`],
azureCustomUri: requestHeaders[`x-${POWERED_BY}-azure-custom-uri`],
};

const stabilityAiConfig = {
Expand Down
31 changes: 22 additions & 9 deletions src/providers/azure-openai/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import {

const AzureOpenAIAPIConfig: ProviderAPIConfig = {
getBaseURL: ({ providerOptions }) => {
const { resourceName } = providerOptions;
const { resourceName, azureCustomUri } = providerOptions;
/**
* Uses the standard OpenAI endpoint (openai.azure.com) by default.
* If a custom subdomain is provided, that endpoint is used instead.
* Example: DeepSeek-R1 uses `https://{resourceName}.services.ai.azure.com/models`.
*/
if (azureCustomUri) {
return `https://${resourceName}.${azureCustomUri}`;
}
return `https://${resourceName}.openai.azure.com/openai`;
},
headers: async ({ providerOptions, fn }) => {
Expand Down Expand Up @@ -55,7 +63,8 @@ const AzureOpenAIAPIConfig: ProviderAPIConfig = {
return headersObj;
},
getEndpoint: ({ providerOptions, fn, gatewayRequestURL }) => {
const { apiVersion, urlToFetch, deploymentId } = providerOptions;
const { apiVersion, urlToFetch, deploymentId, azureCustomUri } =
providerOptions;
let mappedFn = fn;

if (fn === 'proxy' && urlToFetch) {
Expand All @@ -79,27 +88,31 @@ const AzureOpenAIAPIConfig: ProviderAPIConfig = {
const segments = gatewayRequestURL?.split('/');
const id = segments?.at(-1) ?? '';

const deploymentPrefix = azureCustomUri
? ''
: `/deployments/${deploymentId}`;

switch (mappedFn) {
case 'complete': {
return `/deployments/${deploymentId}/completions?api-version=${apiVersion}`;
return `${deploymentPrefix}/completions?api-version=${apiVersion}`;
}
case 'chatComplete': {
return `/deployments/${deploymentId}/chat/completions?api-version=${apiVersion}`;
return `${deploymentPrefix}/chat/completions?api-version=${apiVersion}`;
}
case 'embed': {
return `/deployments/${deploymentId}/embeddings?api-version=${apiVersion}`;
return `${deploymentPrefix}/embeddings?api-version=${apiVersion}`;
}
case 'imageGenerate': {
return `/deployments/${deploymentId}/images/generations?api-version=${apiVersion}`;
return `${deploymentPrefix}/images/generations?api-version=${apiVersion}`;
}
case 'createSpeech': {
return `/deployments/${deploymentId}/audio/speech?api-version=${apiVersion}`;
return `${deploymentPrefix}/audio/speech?api-version=${apiVersion}`;
}
case 'createTranscription': {
return `/deployments/${deploymentId}/audio/transcriptions?api-version=${apiVersion}`;
return `${deploymentPrefix}/audio/transcriptions?api-version=${apiVersion}`;
}
case 'createTranslation': {
return `/deployments/${deploymentId}/audio/translations?api-version=${apiVersion}`;
return `${deploymentPrefix}/audio/translations?api-version=${apiVersion}`;
}
case 'realtime': {
return `/realtime?api-version=${apiVersion}&deployment=${providerOptions.deploymentId}`;
Expand Down
1 change: 1 addition & 0 deletions src/types/requestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface Options {
azureEntraClientId?: string;
azureEntraClientSecret?: string;
azureEntraTenantId?: string;
azureCustomUri?: string;
/** Workers AI specific */
workersAiAccountId?: string;
/** The parameter to set custom base url */
Expand Down