feat(!usage): 支持查看账户额度剩余

This commit is contained in:
Rock Chin
2023-02-28 10:38:25 +08:00
parent 0c3d911e74
commit cbab824fd0
2 changed files with 20 additions and 0 deletions

13
pkg/utils/credit.py Normal file
View File

@@ -0,0 +1,13 @@
# OpenAI账号免费额度剩余查询
import requests
def fetch_credit_data(api_key: str) -> dict:
"""OpenAI账号免费额度剩余查询"""
resp = requests.get(
url="https://api.openai.com/dashboard/billing/credit_grants",
headers={
"Authorization": "Bearer {}".format(api_key),
}
)
return resp.json()