Skip to content

Conversation

@kathmbeck
Copy link
Contributor

@kathmbeck kathmbeck commented Jan 23, 2026

Respects opt out flow for ai gateway in @netlify/dev package (which vite plugin depends on) by checking account capabilities.
https://linear.app/netlify/issue/RUN-1883/build-an-opt-out-flow-for-account-and-sites

Tested locally with npm link and running npm run dev

Running npm run dev

When disabled, we log:

> dev
> vite dev --port 3000

4:49:05 PM [vite] ⬥ Netlify AI Gateway is disabled for this account
4:49:05 PM [vite] ⬥ Netlify Environment loaded
4:49:05 PM [vite] ⬥ Netlify Middleware loaded. Emulating features: blobs, edgeFunctions, environmentVariables, functions, geolocation, headers, images, redirects, static.

@kathmbeck kathmbeck marked this pull request as ready for review January 23, 2026 22:02
@kathmbeck kathmbeck requested a review from a team as a code owner January 23, 2026 22:02
Comment on lines +465 to +475
let aiGatewayDisabled = false
try {
const api = config.api as import('@netlify/api').NetlifyAPI
const accounts = await api.listAccountsForUser()
const account = accounts.find((acc) => acc.slug === config.siteInfo?.account_slug)
aiGatewayDisabled =
(account?.capabilities as { ai_gateway_disabled?: { included?: boolean } } | undefined)?.ai_gateway_disabled
?.included ?? false
} catch {
// If we can't fetch accounts, proceed with AI Gateway enabled
}
Copy link
Member

Choose a reason for hiding this comment

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

🤔 This would be the first case of making API requests like this in the @netlify/dev package, which would change the current separation of responsibilities a bit. As is, @netlify/config is responsible for fetching all the account and site information needed and all the primitives packages receive what they need via @netlify/dev which is a sort of orchestrator.

tbh, I would wager that capabilities are already on the config object that's in scope here, but the types are just unfortunately incomplete.

🤔 https://github.com/netlify/build/blob/64a8ed230f49628560e8d2c59023a14f0632a921/packages/config/src/api/site_info.ts#L58

maybe try adding a console.log of the full config and try against a real site?

}
}
} else {
this.#logger?.log('AI Gateway is disabled for this account')
Copy link
Member

Choose a reason for hiding this comment

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

🤔 This is existing stuff, but is there any reason AI Gateway isn't set up the same way as other primitives?

4:49:05 PM [vite] ⬥ Netlify AI Gateway is disabled for this account
4:49:05 PM [vite] ⬥ Netlify Environment loaded
4:49:05 PM [vite] ⬥ Netlify Middleware loaded. Emulating features: blobs, edgeFunctions, environmentVariables, functions, geolocation, headers, images, redirects, static.

We could just set enabled like the others, maybe?

public getEnabledFeatures(): string[] {
return Object.entries(this.#features)
.filter(([_, enabled]) => enabled)
.map(([feature]) => feature)
}

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.

3 participants