@@ -14,6 +14,7 @@ import type { VisibilityType } from './visibility-selector';
14
14
import { useArtifactSelector } from '@/hooks/use-artifact' ;
15
15
import { unstable_serialize } from 'swr/infinite' ;
16
16
import { getChatHistoryPaginationKey } from './sidebar-history' ;
17
+ import { toast } from './toast' ;
17
18
import type { Session } from 'next-auth' ;
18
19
import { useSearchParams } from 'next/navigation' ;
19
20
import { useChatVisibility } from '@/hooks/use-chat-visibility' ;
@@ -62,8 +63,7 @@ export function Chat({
62
63
63
64
const [ input , setInput ] = useState < string > ( '' ) ;
64
65
const [ usage , setUsage ] = useState < AppUsage | undefined > ( initialLastContext ) ;
65
- const [ showErrorAlert , setShowErrorAlert ] = useState ( false ) ;
66
- const [ errorMessage , setErrorMessage ] = useState ( '' ) ;
66
+ const [ showCreditCardAlert , setShowCreditCardAlert ] = useState ( false ) ;
67
67
const [ currentModelId , setCurrentModelId ] = useState ( initialChatModel ) ;
68
68
const currentModelIdRef = useRef ( currentModelId ) ;
69
69
@@ -108,8 +108,17 @@ export function Chat({
108
108
} ,
109
109
onError : ( error ) => {
110
110
if ( error instanceof ChatSDKError ) {
111
- setErrorMessage ( error . message ) ;
112
- setShowErrorAlert ( true ) ;
111
+ // Check if it's a credit card error
112
+ if (
113
+ error . message ?. includes ( 'AI Gateway requires a valid credit card' )
114
+ ) {
115
+ setShowCreditCardAlert ( true ) ;
116
+ } else {
117
+ toast ( {
118
+ type : 'error' ,
119
+ description : error . message ,
120
+ } ) ;
121
+ }
113
122
}
114
123
} ,
115
124
} ) ;
@@ -209,8 +218,8 @@ export function Chat({
209
218
/>
210
219
211
220
< AlertDialog
212
- open = { showErrorAlert }
213
- onOpenChange = { setShowErrorAlert }
221
+ open = { showCreditCardAlert }
222
+ onOpenChange = { setShowCreditCardAlert }
214
223
>
215
224
< AlertDialogContent >
216
225
< AlertDialogHeader >
0 commit comments