2023-02-28 10:38:25 +08:00
|
|
|
# OpenAI账号免费额度剩余查询
|
|
|
|
|
import requests
|
|
|
|
|
|
2023-03-15 21:04:55 +08:00
|
|
|
def fetch_credit_data(api_key: str, http_proxy: str) -> dict:
|
2023-02-28 10:38:25 +08:00
|
|
|
"""OpenAI账号免费额度剩余查询"""
|
2023-03-15 21:04:55 +08:00
|
|
|
proxies = {
|
|
|
|
|
"http":http_proxy,
|
|
|
|
|
"https":http_proxy
|
|
|
|
|
} if http_proxy is not None else None
|
|
|
|
|
|
2023-02-28 10:38:25 +08:00
|
|
|
resp = requests.get(
|
|
|
|
|
url="https://api.openai.com/dashboard/billing/credit_grants",
|
|
|
|
|
headers={
|
|
|
|
|
"Authorization": "Bearer {}".format(api_key),
|
2023-03-15 21:04:55 +08:00
|
|
|
},
|
|
|
|
|
proxies=proxies
|
2023-02-28 10:38:25 +08:00
|
|
|
)
|
2023-03-15 21:04:55 +08:00
|
|
|
|
2023-02-28 10:38:25 +08:00
|
|
|
return resp.json()
|