Skip to content

Commit 08b5772

Browse files
committed
feat: 查询余额使用 API_BASE_URL 参数
1 parent 8fad91a commit 08b5772

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

service/src/chatgpt/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ async function chatReplyProcess(
102102

103103
async function fetchBalance() {
104104
const OPENAI_API_KEY = process.env.OPENAI_API_KEY
105+
const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL
106+
105107
if (!isNotEmptyString(OPENAI_API_KEY))
106108
return Promise.resolve('-')
107109

110+
const API_BASE_URL = isNotEmptyString(OPENAI_API_BASE_URL)
111+
? OPENAI_API_BASE_URL
112+
: 'https://api.openai.com'
113+
108114
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 })
114117
const balance = response.data.total_available ?? 0
115118
return Promise.resolve(balance.toFixed(3))
116119
}

0 commit comments

Comments
 (0)