@@ -3,6 +3,7 @@ import { IncomingMessage } from 'node:http'
33import path from 'node:path'
44import process from 'node:process'
55
6+ import { parseAIGatewayContext , setupAIGateway } from '@netlify/ai/bootstrap'
67import { resolveConfig } from '@netlify/config'
78import {
89 ensureNetlifyIgnore ,
@@ -459,6 +460,35 @@ export class NetlifyDev {
459460
460461 this . #cleanupJobs. push ( ( ) => runtime . stop ( ) )
461462
463+ // Bootstrap AI Gateway: Fetch AI Gateway tokens and inject them into env
464+ if ( this . #features. environmentVariables && config ?. api && siteID && config ?. siteInfo ?. url ) {
465+ await setupAIGateway ( {
466+ api : config . api ,
467+ env : config . env || { } ,
468+ siteID,
469+ siteURL : config . siteInfo . url ,
470+ } )
471+
472+ // Inject AI_GATEWAY into process.env via runtime
473+ if ( config . env . AI_GATEWAY ) {
474+ runtime . env . set ( 'AI_GATEWAY' , config . env . AI_GATEWAY . value )
475+
476+ // Parse and inject AI Gateway env vars
477+ const aiGatewayContext = parseAIGatewayContext ( config . env . AI_GATEWAY . value )
478+ if ( aiGatewayContext ) {
479+ runtime . env . set ( 'NETLIFY_AI_GATEWAY_KEY' , aiGatewayContext . token )
480+ runtime . env . set ( 'NETLIFY_AI_GATEWAY_URL' , aiGatewayContext . url )
481+
482+ if ( aiGatewayContext . envVars ) {
483+ for ( const envVar of aiGatewayContext . envVars ) {
484+ runtime . env . set ( envVar . key , aiGatewayContext . token )
485+ runtime . env . set ( envVar . url , aiGatewayContext . url )
486+ }
487+ }
488+ }
489+ }
490+ }
491+
462492 let serverAddress : string | undefined
463493
464494 // If a custom server has been provided, use it. If not, we must stand up
0 commit comments