Skip to content

fix(azure): skip /v1 and api-version when baseURL is provided#14171

Open
Dulani wants to merge 3 commits intovercel:mainfrom
Dulani:fix/azure-baseurl-no-v1-api-version
Open

fix(azure): skip /v1 and api-version when baseURL is provided#14171
Dulani wants to merge 3 commits intovercel:mainfrom
Dulani:fix/azure-baseurl-no-v1-api-version

Conversation

@Dulani
Copy link
Copy Markdown

@Dulani Dulani commented Apr 6, 2026

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 /v1 path segment or api-version query parameter.

This PR adds a baseURL branch to the URL construction logic that uses {baseURL}{path} directly — no /v1 appended, no api-version added.

Problem

// Before: baseURL + /v1 + api-version
createAzure({ baseURL: 'https://my-gateway.example.com/azure' })
// → https://my-gateway.example.com/azure/v1/chat/completions?api-version=v1
//                                        ^^^                 ^^^^^^^^^^^^^^
//                                        breaks gateway      breaks gateway

Fix

// After: baseURL used as-is
createAzure({ baseURL: 'https://my-gateway.example.com/azure' })
// → https://my-gateway.example.com/azure/chat/completions

The fix is a 6-line change in the url() function inside createAzure:

  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

Configuration URL constructed
resourceName (default) https://{name}.openai.azure.com/openai/v1{path}?api-version=v1 ✅ unchanged
useDeploymentBasedUrls: true {baseURL}/deployments/{id}{path}?api-version=v1 ✅ unchanged
baseURL (new behavior) {baseURL}{path} — no /v1, no api-version ✅ fixed

Breaking Change

None. The resourceName and useDeploymentBasedUrls paths are unchanged. Only the baseURL path changes, and the previous behavior (appending /v1 and api-version) was undocumented and unintended — the JSDoc said "use a different URL prefix" without mentioning the /v1 suffix.

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.]

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.
@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/azure Issues related to the @ai-sdk/azure provider labels Apr 6, 2026
@Dulani Dulani marked this pull request as ready for review April 6, 2026 20:18
Dulani added 2 commits April 8, 2026 12:51
…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`.
@Dulani
Copy link
Copy Markdown
Author

Dulani commented Apr 8, 2026

Thanks for the catch. Fixed in 56942ca — changed the api-version guard from !options.baseURL to !options.baseURL || options.useDeploymentBasedUrls, so deployment-based URLs get api-version even when baseURL is also set. Added a test in 513493b covering the baseURL + useDeploymentBasedUrls combo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/azure Issues related to the @ai-sdk/azure provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@ai-sdk/azure: baseURL mode appends /v1 and api-version — breaks custom gateways

1 participant