File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -102,15 +102,18 @@ async function chatReplyProcess(
102
102
103
103
async function fetchBalance ( ) {
104
104
const OPENAI_API_KEY = process . env . OPENAI_API_KEY
105
+ const OPENAI_API_BASE_URL = process . env . OPENAI_API_BASE_URL
106
+
105
107
if ( ! isNotEmptyString ( OPENAI_API_KEY ) )
106
108
return Promise . resolve ( '-' )
107
109
110
+ const API_BASE_URL = isNotEmptyString ( OPENAI_API_BASE_URL )
111
+ ? OPENAI_API_BASE_URL
112
+ : 'https://api.openai.com'
113
+
108
114
try {
109
- const headers = {
110
- 'Content-Type' : 'application/json' ,
111
- 'Authorization' : `Bearer ${ OPENAI_API_KEY } ` ,
112
- }
113
- const response = await axios . get ( 'https://api.openai.com/dashboard/billing/credit_grants' , { headers } )
115
+ const headers = { 'Content-Type' : 'application/json' , 'Authorization' : `Bearer ${ OPENAI_API_KEY } ` }
116
+ const response = await axios . get ( `${ API_BASE_URL } /dashboard/billing/credit_grants` , { headers } )
114
117
const balance = response . data . total_available ?? 0
115
118
return Promise . resolve ( balance . toFixed ( 3 ) )
116
119
}
You can’t perform that action at this time.
0 commit comments