Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"packages/redirects",
"packages/runtime",
"packages/static",
"packages/dev",
"packages/ai",
"packages/dev",
"packages/nuxt-module",
"packages/vite-plugin",
"packages/vite-plugin-tanstack-start"
Expand Down
1 change: 1 addition & 0 deletions packages/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"vitest": "^3.0.0"
},
"dependencies": {
"@netlify/ai": "^0.3.3",
"@netlify/blobs": "10.3.3",
"@netlify/config": "^23.2.0",
"@netlify/dev-utils": "4.3.1",
Expand Down
30 changes: 30 additions & 0 deletions packages/dev/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IncomingMessage } from 'node:http'
import path from 'node:path'
import process from 'node:process'

import { parseAIGatewayContext, setupAIGateway } from '@netlify/ai/bootstrap'
import { resolveConfig } from '@netlify/config'
import {
ensureNetlifyIgnore,
Expand Down Expand Up @@ -459,6 +460,35 @@ export class NetlifyDev {

this.#cleanupJobs.push(() => runtime.stop())

// Bootstrap AI Gateway: Fetch AI Gateway tokens and inject them into env
if (this.#features.environmentVariables && config?.api && siteID && config?.siteInfo?.url) {
await setupAIGateway({
api: config.api,
env: config.env || {},
siteID,
siteURL: config.siteInfo.url,
})

// Inject AI_GATEWAY into process.env via runtime
if (config.env.AI_GATEWAY) {
runtime.env.set('AI_GATEWAY', config.env.AI_GATEWAY.value)
Comment on lines +472 to +474
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.


// Parse and inject AI Gateway env vars
const aiGatewayContext = parseAIGatewayContext(config.env.AI_GATEWAY.value)
if (aiGatewayContext) {
runtime.env.set('NETLIFY_AI_GATEWAY_KEY', aiGatewayContext.token)
runtime.env.set('NETLIFY_AI_GATEWAY_URL', aiGatewayContext.url)

if (aiGatewayContext.envVars) {
for (const envVar of aiGatewayContext.envVars) {
runtime.env.set(envVar.key, aiGatewayContext.token)
runtime.env.set(envVar.url, aiGatewayContext.url)
}
}
}
}
}

let serverAddress: string | undefined

// If a custom server has been provided, use it. If not, we must stand up
Expand Down
1 change: 1 addition & 0 deletions packages/dev/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export default defineConfig([
watch: argv.includes('--watch'),
platform: 'node',
bundle: true,
external: ['@netlify/ai'],
},
])