File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -81,9 +81,18 @@ export function GeneralPart({ config, updateConfig }) {
81
81
const [ balance , setBalance ] = useState ( null )
82
82
83
83
const getBalance = async ( ) => {
84
- const billing = await checkBilling ( config . apiKey , config . customOpenAiApiUrl )
85
- if ( billing && billing . length > 2 && billing [ 2 ] ) setBalance ( `${ billing [ 2 ] . toFixed ( 2 ) } ` )
86
- else openUrl ( 'https://platform.openai.com/account/usage' )
84
+ const response = await fetch ( `${ config . customOpenAiApiUrl } /dashboard/billing/credit_grants` , {
85
+ headers : {
86
+ 'Content-Type' : 'application/json' ,
87
+ Authorization : `Bearer ${ config . apiKey } ` ,
88
+ } ,
89
+ } )
90
+ if ( response . ok ) setBalance ( ( await response . json ( ) ) . total_available . toFixed ( 2 ) )
91
+ else {
92
+ const billing = await checkBilling ( config . apiKey , config . customOpenAiApiUrl )
93
+ if ( billing && billing . length > 2 && billing [ 2 ] ) setBalance ( `${ billing [ 2 ] . toFixed ( 2 ) } ` )
94
+ else openUrl ( 'https://platform.openai.com/account/usage' )
95
+ }
87
96
}
88
97
89
98
return (
You can’t perform that action at this time.
0 commit comments