feat(action): allow an explicit Azure endpoint via AZURE_BASE_URL - #71
Open
theoephraim wants to merge 1 commit into
Open
feat(action): allow an explicit Azure endpoint via AZURE_BASE_URL#71theoephraim wants to merge 1 commit into
theoephraim wants to merge 1 commit into
Conversation
@ai-sdk/azure derives its endpoint from a resource name as https://<AZURE_RESOURCE_NAME>.openai.azure.com/openai, which can't express an AI Foundry / AI Services host, an API Management front door, or an AI gateway. Those deployments are unreachable today. Add AZURE_BASE_URL (and the cognitive-services equivalent), surfaced as provider.<id>.options.baseURL in the generated OpenCode config. OpenCode merges config provider options over its own and forwards options.baseURL into the createAzure factory, and the SDK drops the resourceName requirement once a base URL is set — so a custom endpoint needs no dummy resource name. Lives in opencodeShared.ts and is spread into both the v1 and v2 config builders, so the two runners can't drift. Returns an empty object when unset, so the config is byte-identical for everyone else.
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — adds an optional explicit-endpoint override for the Azure OpenCode providers so deployments behind AI Foundry, API Management, or a gateway are reachable without relying on resource-name URL derivation.
- Add
azureBaseUrlOverrides()helper — new function inagents/opencodeShared.tsmapsAZURE_BASE_URL→provider.azure.options.baseURLandAZURE_COGNITIVE_SERVICES_BASE_URL→provider.azure-cognitive-services.options.baseURL, trimming values and returning{}when unset. - Wire into both harnesses — spread into the
providerblock ofbuildSecurityConfigin bothagents/opencode.ts(v1) andagents/opencode_v2.ts(v2), keeping the two runners aligned. - Tests — six cases in
agents/opencode.test.tscovering each provider, independent dual mapping, whitespace trimming, whitespace-only-as-unset, and the empty-by-default contract.
Notes from review, all clean:
- The
...azureBaseUrlOverrides()spread sits last in theproviderliteral but only ever emitsazure/azure-cognitive-serviceskeys, so it cannot clobber the existinggoogle/openrouterentries. - Logging the resolved base URL at info level is appropriate —
AZURE_BASE_URL/AZURE_COGNITIVE_SERVICES_BASE_URLend in_URL, outside the_KEY/_SECRET/_TOKEN/_PASSWORD/_CREDENTIALsensitive-suffix set, so they are intentionally treated as non-secret config rather than masked. - The author's forward note about adding these vars to #69's non-secret allowlist (if it lands first) is the right follow-up and needs no action here.
Claude Opus (free via Pullfrog for OSS) | 𝕏
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.

Problem
Azure models work today through the models.dev passthrough, but only for one endpoint shape.
@ai-sdk/azurederives its URL from a resource name:That can't express an Azure AI Foundry / AI Services host, an API Management front door, or an AI gateway. Those deployments are simply unreachable — there's no config surface to point the provider anywhere else.
Change
AZURE_BASE_URL(plusAZURE_COGNITIVE_SERVICES_BASE_URLfor the sibling provider), surfaced asprovider.<id>.options.baseURLin the generated OpenCode config.It lives in
opencodeShared.tsand is spread into both the v1 and v2buildSecurityConfigprovider blocks, per that module's stated purpose of keeping the two runners from drifting. It returns{}when unset, so the emitted config is byte-identical for anyone not using it.Verification
I traced this through OpenCode rather than assuming the schema key was wired:
getSDKspreadsprovider.options, callsloadBaseURL(options["baseURL"] ?? model.api.url), and passes the result toBUNDLED_PROVIDERS["@ai-sdk/azure"] === createAzureprovider.<id>.optionsis merged over OpenCode's own viamergeDeepresourceNameis ignored and no longer required oncebaseURLis setThen confirmed end to end against a local probe server, with
AZURE_API_KEYset andprovider.azure.options.baseURLpointed at it:So the override reaches the SDK, and the Responses API is used (matching the
azurecustom loader'ssdk.responses()). The base URL should carry the/openaisuffix — the SDK appends/v1{path}.One nice consequence, also verified empirically: OpenCode enables a provider when any of its models.dev env vars is present (
provider.env.map(...).find(Boolean)).AZURE_API_KEYalone lists 66azure/*models, zero with no azure var set. So a custom endpoint needs no dummyAZURE_RESOURCE_NAMEto pass the authorization gate.Tests
Six cases in
agents/opencode.test.tscovering both providers, trimming, whitespace-only, and the empty-by-default contract.pnpm typecheckclean;utils/+agents/347/347. Full suite not run locally (no GitHub App credentials).Notes
Branched off
main, independent of #69 and #70. If #69 lands,AZURE_BASE_URLandAZURE_RESOURCE_NAMEare both worth adding to its non-secret allowlist so they stay readable in run logs — happy to do that in whichever merges second.Note
Low Risk
Config-only change gated on optional env vars; default emitted config is unchanged when vars are absent.
Overview
Adds optional Azure endpoint overrides for OpenCode by mapping
AZURE_BASE_URLandAZURE_COGNITIVE_SERVICES_BASE_URLintoprovider.<id>.options.baseURLin the generated security config, so deployments behind AI Foundry, API Management, or custom gateways are reachable without relying on resource-name URL derivation.The helper
azureBaseUrlOverrides()lives inopencodeShared.ts(trimmed values, empty when unset) and is spread into theproviderblock in both v1 and v2 OpenCode harnesses so behavior stays aligned. When a var is set, an info log records which provider was overridden.Tests cover both env vars, independent dual mapping, trimming, whitespace-only treated as unset, and the default
{}no-op contract.Reviewed by Cursor Bugbot for commit ff33573. Bugbot is set up for automated code reviews on this repo. Configure here.