@@ -260,7 +260,7 @@ export async function postChatCompletions(params: {
260260 return NextResponse . json (
261261 {
262262 error : 'account_suspended' ,
263- message : `Your account has been suspended due to billing issues . Please contact ${ env . NEXT_PUBLIC_SUPPORT_EMAIL } to resolve this.` ,
263+ message : `Your account has been suspended. Please contact ${ env . NEXT_PUBLIC_SUPPORT_EMAIL } if you did not expect this.` ,
264264 } ,
265265 { status : 403 } ,
266266 )
@@ -468,19 +468,19 @@ export async function postChatCompletions(params: {
468468 if ( ensureSubscriberBlockGrant ) {
469469 try {
470470 const blockGrantResult = await ensureSubscriberBlockGrant ( { userId, logger } )
471-
471+
472472 // Check if user hit subscription limit and should be rate-limited
473473 if ( blockGrantResult && ( isWeeklyLimitError ( blockGrantResult ) || isBlockExhaustedError ( blockGrantResult ) ) ) {
474474 // Fetch user's preference for falling back to a-la-carte credits
475475 const preferences = getUserPreferences
476476 ? await getUserPreferences ( { userId, logger } )
477477 : { fallbackToALaCarte : true } // Default to allowing a-la-carte if no preference function
478-
478+
479479 if ( ! preferences . fallbackToALaCarte && ! isFreeModeRequest ) {
480480 const resetTime = blockGrantResult . resetsAt
481481 const resetCountdown = formatQuotaResetCountdown ( resetTime . toISOString ( ) )
482482 const limitType = isWeeklyLimitError ( blockGrantResult ) ? 'weekly' : '5-hour session'
483-
483+
484484 trackEvent ( {
485485 event : AnalyticsEvent . CHAT_COMPLETIONS_INSUFFICIENT_CREDITS ,
486486 userId,
@@ -491,7 +491,7 @@ export async function postChatCompletions(params: {
491491 } ,
492492 logger,
493493 } )
494-
494+
495495 return NextResponse . json (
496496 {
497497 error : 'rate_limit_exceeded' ,
@@ -553,54 +553,54 @@ export async function postChatCompletions(params: {
553553 const useOpenAIDirect = ! useFireworks && isOpenAIDirectModel ( typedBody . model )
554554 const stream = useSiliconFlow
555555 ? await handleSiliconFlowStream ( {
556- body : typedBody ,
557- userId,
558- stripeCustomerId,
559- agentId,
560- fetch,
561- logger,
562- insertMessageBigquery,
563- } )
556+ body : typedBody ,
557+ userId,
558+ stripeCustomerId,
559+ agentId,
560+ fetch,
561+ logger,
562+ insertMessageBigquery,
563+ } )
564564 : useCanopyWave
565- ? await handleCanopyWaveStream ( {
566- body : typedBody ,
567- userId,
568- stripeCustomerId,
569- agentId,
570- fetch,
571- logger,
572- insertMessageBigquery,
573- } )
574- : useFireworks
575- ? await handleFireworksStream ( {
576- body : typedBody ,
577- userId,
578- stripeCustomerId,
579- agentId,
580- fetch,
581- logger,
582- insertMessageBigquery,
583- } )
584- : useOpenAIDirect
585- ? await handleOpenAIStream ( {
586- body : typedBody ,
587- userId,
588- stripeCustomerId,
589- agentId,
590- fetch,
591- logger,
592- insertMessageBigquery,
593- } )
594- : await handleOpenRouterStream ( {
565+ ? await handleCanopyWaveStream ( {
595566 body : typedBody ,
596567 userId,
597568 stripeCustomerId,
598569 agentId,
599- openrouterApiKey,
600570 fetch,
601571 logger,
602572 insertMessageBigquery,
603573 } )
574+ : useFireworks
575+ ? await handleFireworksStream ( {
576+ body : typedBody ,
577+ userId,
578+ stripeCustomerId,
579+ agentId,
580+ fetch,
581+ logger,
582+ insertMessageBigquery,
583+ } )
584+ : useOpenAIDirect
585+ ? await handleOpenAIStream ( {
586+ body : typedBody ,
587+ userId,
588+ stripeCustomerId,
589+ agentId,
590+ fetch,
591+ logger,
592+ insertMessageBigquery,
593+ } )
594+ : await handleOpenRouterStream ( {
595+ body : typedBody ,
596+ userId,
597+ stripeCustomerId,
598+ agentId,
599+ openrouterApiKey,
600+ fetch,
601+ logger,
602+ insertMessageBigquery,
603+ } )
604604
605605 trackEvent ( {
606606 event : AnalyticsEvent . CHAT_COMPLETIONS_STREAM_STARTED ,
@@ -631,26 +631,16 @@ export async function postChatCompletions(params: {
631631
632632 const nonStreamRequest = useSiliconFlow
633633 ? handleSiliconFlowNonStream ( {
634- body : typedBody ,
635- userId,
636- stripeCustomerId,
637- agentId,
638- fetch,
639- logger,
640- insertMessageBigquery,
641- } )
634+ body : typedBody ,
635+ userId,
636+ stripeCustomerId,
637+ agentId,
638+ fetch,
639+ logger,
640+ insertMessageBigquery,
641+ } )
642642 : useCanopyWave
643- ? handleCanopyWaveNonStream ( {
644- body : typedBody ,
645- userId,
646- stripeCustomerId,
647- agentId,
648- fetch,
649- logger,
650- insertMessageBigquery,
651- } )
652- : useFireworks
653- ? handleFireworksNonStream ( {
643+ ? handleCanopyWaveNonStream ( {
654644 body : typedBody ,
655645 userId,
656646 stripeCustomerId,
@@ -659,26 +649,36 @@ export async function postChatCompletions(params: {
659649 logger,
660650 insertMessageBigquery,
661651 } )
662- : shouldUseOpenAIEndpoint
663- ? handleOpenAINonStream ( {
664- body : typedBody ,
665- userId,
666- stripeCustomerId,
667- agentId,
668- fetch,
669- logger,
670- insertMessageBigquery,
671- } )
672- : handleOpenRouterNonStream ( {
652+ : useFireworks
653+ ? handleFireworksNonStream ( {
673654 body : typedBody ,
674655 userId,
675656 stripeCustomerId,
676657 agentId,
677- openrouterApiKey,
678658 fetch,
679659 logger,
680660 insertMessageBigquery,
681661 } )
662+ : shouldUseOpenAIEndpoint
663+ ? handleOpenAINonStream ( {
664+ body : typedBody ,
665+ userId,
666+ stripeCustomerId,
667+ agentId,
668+ fetch,
669+ logger,
670+ insertMessageBigquery,
671+ } )
672+ : handleOpenRouterNonStream ( {
673+ body : typedBody ,
674+ userId,
675+ stripeCustomerId,
676+ agentId,
677+ openrouterApiKey,
678+ fetch,
679+ logger,
680+ insertMessageBigquery,
681+ } )
682682 const result = await nonStreamRequest
683683
684684 trackEvent ( {
0 commit comments