@@ -122,7 +122,7 @@ function resolveOutputIds(
122122export async function executeWorkflow (
123123 workflow : any ,
124124 requestId : string ,
125- input ? : any ,
125+ input : any | undefined ,
126126 actorUserId : string ,
127127 streamConfig ?: {
128128 enabled : boolean
@@ -638,37 +638,29 @@ export async function POST(
638638 let authenticatedUserId : string
639639 let triggerType : TriggerType = 'manual'
640640
641- const session = await getSession ( )
642- const apiKeyHeader = request . headers . get ( 'X-API-Key' )
643- if ( session ?. user ?. id && ! apiKeyHeader ) {
644- authenticatedUserId = session . user . id
645- triggerType = 'manual'
646- } else if ( apiKeyHeader ) {
647- const auth = await authenticateApiKeyFromHeader ( apiKeyHeader )
648- if ( ! auth . success || ! auth . userId ) {
649- return createErrorResponse ( 'Unauthorized' , 401 )
650- }
651- authenticatedUserId = auth . userId
652- triggerType = 'api'
653- if ( auth . keyId ) {
654- void updateApiKeyLastUsed ( auth . keyId ) . catch ( ( ) => { } )
655641 // For internal calls (chat deployments), use the workflow owner's ID
656642 if ( finalIsSecureMode ) {
657643 authenticatedUserId = validation . workflow . userId
658644 triggerType = 'manual' // Chat deployments use manual trigger type (no rate limit)
659645 } else {
660646 const session = await getSession ( )
661- if ( session ?. user ?. id ) {
647+ const apiKeyHeader = request . headers . get ( 'X-API-Key' )
648+
649+ if ( session ?. user ?. id && ! apiKeyHeader ) {
662650 authenticatedUserId = session . user . id
663- triggerType = 'manual' // UI session (not rate limited)
664- } else {
665- const apiKeyHeader = request . headers . get ( 'X-API-Key' )
666- if ( apiKeyHeader ) {
667- authenticatedUserId = validation . workflow . userId
668- triggerType = 'api'
669- } else {
670- return createErrorResponse ( 'Authentication required' , 401 )
651+ triggerType = 'manual'
652+ } else if ( apiKeyHeader ) {
653+ const auth = await authenticateApiKeyFromHeader ( apiKeyHeader )
654+ if ( ! auth . success || ! auth . userId ) {
655+ return createErrorResponse ( 'Unauthorized' , 401 )
656+ }
657+ authenticatedUserId = auth . userId
658+ triggerType = 'api'
659+ if ( auth . keyId ) {
660+ void updateApiKeyLastUsed ( auth . keyId ) . catch ( ( ) => { } )
671661 }
662+ } else {
663+ return createErrorResponse ( 'Authentication required' , 401 )
672664 }
673665 }
674666
0 commit comments