Skip to content

Commit b0c8bb0

Browse files
committed
compatible balance query with third-party services
1 parent 4dba9d5 commit b0c8bb0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/popup/sections/GeneralPart.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,18 @@ export function GeneralPart({ config, updateConfig }) {
8181
const [balance, setBalance] = useState(null)
8282

8383
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+
}
8796
}
8897

8998
return (

0 commit comments

Comments
 (0)