@@ -378,6 +378,14 @@ export class GuardrailEval {
378378 private _createContext ( ) : Context {
379379 // Azure OpenAI
380380 if ( this . azureEndpoint ) {
381+ // Validate API key availability
382+ const apiKey = this . apiKey || process . env . OPENAI_API_KEY ;
383+ if ( ! apiKey ) {
384+ throw new Error (
385+ 'API key is required for Azure OpenAI. Please provide --api-key or set OPENAI_API_KEY environment variable.'
386+ ) ;
387+ }
388+
381389 const azureKwargs : Record < string , string > = {
382390 azureEndpoint : this . azureEndpoint ,
383391 apiVersion : this . azureApiVersion ,
@@ -388,8 +396,8 @@ export class GuardrailEval {
388396
389397 // Note: Azure OpenAI client creation would need AzureOpenAI import
390398 // For now, fall back to regular OpenAI with base URL
391- const openaiClient = new OpenAI ( {
392- apiKey : this . apiKey || process . env . OPENAI_API_KEY ,
399+ const openaiClient = new OpenAI ( {
400+ apiKey : apiKey ,
393401 baseURL : `https://${ this . azureEndpoint . replace ( / ^ h t t p s ? : \/ \/ / , '' ) } /openai/deployments` ,
394402 } ) ;
395403 console . info ( `event="client_created" type="azure" endpoint="${ this . azureEndpoint } "` ) ;
@@ -651,7 +659,7 @@ export class GuardrailEval {
651659 const modelContext = this . _createContext ( ) ;
652660
653661 const guardrails = await instantiateGuardrails ( stageBundle ) ;
654- const engine = new AsyncRunEngine ( guardrails , this . multiTurn ) ;
662+ const engine = new AsyncRunEngine ( guardrails , this . multiTurn ) ;
655663 const chunkTotal = this . benchmarkChunkSize && samples . length > 0
656664 ? Math . max ( 1 , Math . ceil ( samples . length / this . benchmarkChunkSize ) )
657665 : 1 ;
0 commit comments