fix(azure): skip /v1 and api-version when baseURL is provided#14171
Open
Dulani wants to merge 3 commits intovercel:mainfrom
Open
fix(azure): skip /v1 and api-version when baseURL is provided#14171Dulani wants to merge 3 commits intovercel:mainfrom
Dulani wants to merge 3 commits intovercel:mainfrom
Conversation
When createAzure({ baseURL }) is used, the provider now constructs
{baseURL}{path} instead of {baseURL}/v1{path}?api-version=...
This allows custom API gateways and proxies that handle routing
internally to work without receiving unexpected path segments or
query parameters.
Closes vercel#13956. Also addresses vercel#14009.
…s are both set When both options are provided, the deployment-based URL format is used (first branch of the if/else), so the api-version guard should not suppress it. Fix: `!options.baseURL` → `!options.baseURL || options.useDeploymentBasedUrls`.
Author
|
Thanks for the catch. Fixed in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
createAzure({ baseURL: '...' })is used, the provider currently constructs{baseURL}/v1{path}?api-version=.... This breaks custom API gateways and proxies that handle routing internally and don't expect the/v1path segment orapi-versionquery parameter.This PR adds a
baseURLbranch to the URL construction logic that uses{baseURL}{path}directly — no/v1appended, noapi-versionadded.Problem
Fix
The fix is a 6-line change in the
url()function insidecreateAzure:if (options.useDeploymentBasedUrls) { fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path}`); + } else if (options.baseURL) { + fullUrl = new URL(`${baseUrlPrefix}${path}`); } else { fullUrl = new URL(`${baseUrlPrefix}/v1${path}`); } - fullUrl.searchParams.set('api-version', apiVersion); + if (!options.baseURL) { + fullUrl.searchParams.set('api-version', apiVersion); + }Behavior
resourceName(default)https://{name}.openai.azure.com/openai/v1{path}?api-version=v1✅ unchangeduseDeploymentBasedUrls: true{baseURL}/deployments/{id}{path}?api-version=v1✅ unchangedbaseURL(new behavior){baseURL}{path}— no/v1, noapi-version✅ fixedBreaking Change
None. The
resourceNameanduseDeploymentBasedUrlspaths are unchanged. Only thebaseURLpath changes, and the previous behavior (appending/v1andapi-version) was undocumented and unintended — the JSDoc said "use a different URL prefix" without mentioning the/v1suffix.Tests
Updated 4 existing
'should use the baseURL correctly'tests (responses, chat, image, responses-explicit) to assert the new correct behavior. All 55 tests pass in both node and edge environments.Related
Closes #13956
Also addresses the api-version issue in #14009 (Foundry project endpoints)
[Authorship: ~40% AI-assisted, ~60% human review and testing. Tested against a corporate Azure OpenAI gateway at RAND.]