Skip to content

Conversation

@kathmbeck
Copy link
Contributor

@kathmbeck kathmbeck commented Nov 6, 2025

Added AI Gateway bootstrap support to @netlify/dev package:

  • Adds @netlify/ai as dep
  • Fetches AI gateway token
  • Parses the AI gateway context and injects the provider environment variables via runtime.env.set()

Tested with dogs-explorer template referenced on ticket with debug logs and by manually patching node modules to include the AI Gateway bootstrap logic:
https://github.com/netlify-templates/dogs-explorer
https://linear.app/netlify/issue/RUN-2155/support-ai-gateway-bootstrap-in-our-vite-plugin

Running npm run dev

11:48:35 PM [vite] ⬥ Netlify [AI Gateway] Fetching token...
11:48:35 PM [vite] ⬥ Netlify [AI Gateway] Environment variables set
11:48:35 PM [vite] ⬥ Netlify Environment loaded

Verified env vars present in function with curl to test function

{
  "OPENAI_API_KEY": "SET",
  "AI_GATEWAY": "SET"
}

@kathmbeck kathmbeck force-pushed the feat/ai-gateway-vite-plugin-support branch from 5f73002 to b7f47d9 Compare November 6, 2025 19:14
@kathmbeck kathmbeck marked this pull request as ready for review November 6, 2025 19:28
@kathmbeck kathmbeck requested review from a team as code owners November 6, 2025 19:28
Comment on lines +472 to +474
// Inject AI_GATEWAY into process.env via runtime
if (config.env.AI_GATEWAY) {
runtime.env.set('AI_GATEWAY', config.env.AI_GATEWAY.value)
Copy link
Member

Choose a reason for hiding this comment

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

did we change this to NETLIFY_AI_GATEWAY https://docs.netlify.com/build/ai-gateway/overview/

NETLIFY_AI_GATEWAY_KEY and NETLIFY_AI_GATEWAY_BASE_URL environment variables are always injected into the AI Gateway-supported runtimes. If you want to mix different setups with your own keys and Netlify’s or you want to be explicit about using AI Gateway keys in your calls, use these env variables as they will never collide with other environment variables values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch that we need to set it, but it would be where we decode the context stored in AI_GATEWAY and set all the env vars. Added it to main.ts.

@kathmbeck kathmbeck merged commit e6823d4 into main Nov 7, 2025
29 of 31 checks passed
@kathmbeck kathmbeck deleted the feat/ai-gateway-vite-plugin-support branch November 7, 2025 15:48
@token-generator-app token-generator-app bot mentioned this pull request Nov 7, 2025
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