feat: 查询余额使用 API_BASE_URL 参数

main
ChenZhaoYu 2 years ago
parent 8fad91ade7
commit 08b5772420

@ -102,15 +102,18 @@ async function chatReplyProcess(
async function fetchBalance() { async function fetchBalance() {
const OPENAI_API_KEY = process.env.OPENAI_API_KEY const OPENAI_API_KEY = process.env.OPENAI_API_KEY
const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL
if (!isNotEmptyString(OPENAI_API_KEY)) if (!isNotEmptyString(OPENAI_API_KEY))
return Promise.resolve('-') return Promise.resolve('-')
const API_BASE_URL = isNotEmptyString(OPENAI_API_BASE_URL)
? OPENAI_API_BASE_URL
: 'https://api.openai.com'
try { try {
const headers = { const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_API_KEY}` }
'Content-Type': 'application/json', const response = await axios.get(`${API_BASE_URL}/dashboard/billing/credit_grants`, { headers })
'Authorization': `Bearer ${OPENAI_API_KEY}`,
}
const response = await axios.get('https://api.openai.com/dashboard/billing/credit_grants', { headers })
const balance = response.data.total_available ?? 0 const balance = response.data.total_available ?? 0
return Promise.resolve(balance.toFixed(3)) return Promise.resolve(balance.toFixed(3))
} }

Loading…
Cancel
Save