Skip to content

feat(provider/gateway): support AI_GATEWAY_BASE_URL env for the base URL#16401

Open
brycedbjork wants to merge 1 commit into
vercel:mainfrom
brycedbjork:feat/gateway-base-url-env
Open

feat(provider/gateway): support AI_GATEWAY_BASE_URL env for the base URL#16401
brycedbjork wants to merge 1 commit into
vercel:mainfrom
brycedbjork:feat/gateway-base-url-env

Conversation

@brycedbjork

Copy link
Copy Markdown

Summary

The Gateway provider's base URL is only configurable via createGateway({ baseURL }). The default / global gateway provider — the one the AI SDK uses to resolve plain provider/model strings (e.g. generateText({ model: 'anthropic/claude-...' })) — is constructed internally, so callers have no way to point it at a custom endpoint without building a provider by hand and threading it through every call site.

This adds an AI_GATEWAY_BASE_URL environment-variable fallback, symmetric with the existing AI_GATEWAY_API_KEY env, so the gateway endpoint can be overridden process-wide — useful for a self-hosted gateway, a local proxy that injects auth/headers, testing, or enterprise egress.

Change

const baseURL =
  withoutTrailingSlash(options.baseURL ?? process.env.AI_GATEWAY_BASE_URL) ??
  'https://ai-gateway.vercel.sh/v4/ai';

Precedence: explicit options.baseURLAI_GATEWAY_BASE_URL → default. No behavior change when neither is set. The doc comment on GatewayProviderSettings.baseURL is updated to mention the env var, and a changeset is included.

The gateway provider's base URL was only settable via `createGateway({ baseURL })`.
The default/global gateway provider (used to resolve plain `provider/model` strings)
is constructed internally, so callers can't point it at a custom endpoint without
building a provider by hand. Add an `AI_GATEWAY_BASE_URL` fallback, symmetric with
the existing `AI_GATEWAY_API_KEY` env.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

const baseURL =
withoutTrailingSlash(options.baseURL) ??
withoutTrailingSlash(options.baseURL ?? process.env.AI_GATEWAY_BASE_URL) ??

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct process.env.AI_GATEWAY_BASE_URL access at module-load time throws ReferenceError: process is not defined in browser/edge runtimes where process is not a global.

Fix on Vercel

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant