Commit
·
ac08bfb
1
Parent(s):
d7b2366
Update api_usage.py
Browse files- api_usage.py +15 -12
api_usage.py
CHANGED
|
@@ -17,29 +17,32 @@ def get_subscription(key):
|
|
| 17 |
if check_key_availability():
|
| 18 |
has_payment_method = results["has_payment_method"]
|
| 19 |
# hard_limit = results["hard_limit"]
|
|
|
|
| 20 |
hard_limit_usd = results["hard_limit_usd"]
|
| 21 |
-
|
|
|
|
| 22 |
account_name = results["account_name"]
|
| 23 |
return {"account_name": account_name,
|
| 24 |
"has_payment_method": has_payment_method,
|
|
|
|
| 25 |
"hard_limit_usd": hard_limit_usd,
|
| 26 |
-
"plan":
|
| 27 |
else:
|
| 28 |
return {"account_name": "",
|
| 29 |
"has_payment_method": False,
|
| 30 |
"hard_limit_usd": "",
|
| 31 |
"plan": ""}
|
| 32 |
|
| 33 |
-
def get_usage(key):
|
| 34 |
-
if check_key_availability():
|
| 35 |
-
start_date = datetime.now().strftime('%Y-%m-01')
|
| 36 |
-
end_date = (datetime.now() + relativedelta(months=1)).strftime('%Y-%m-01')
|
| 37 |
-
queryUrl = f'https://api.openai.com/dashboard/billing/usage?start_date={start_date}&end_date={end_date}'
|
| 38 |
-
headers = get_headers(key)
|
| 39 |
-
r = requests.get(queryUrl, headers=headers)
|
| 40 |
-
return r.json()
|
| 41 |
-
else:
|
| 42 |
-
return ""
|
| 43 |
|
| 44 |
def check_gpt4_availability():
|
| 45 |
if check_key_availability():
|
|
|
|
| 17 |
if check_key_availability():
|
| 18 |
has_payment_method = results["has_payment_method"]
|
| 19 |
# hard_limit = results["hard_limit"]
|
| 20 |
+
soft_limit_usd = results["soft_limit_usd"]
|
| 21 |
hard_limit_usd = results["hard_limit_usd"]
|
| 22 |
+
plan_title = results["plan"]["title"]
|
| 23 |
+
plan_id = results["plan"]["id"]
|
| 24 |
account_name = results["account_name"]
|
| 25 |
return {"account_name": account_name,
|
| 26 |
"has_payment_method": has_payment_method,
|
| 27 |
+
"soft_limit_usd": soft_limit_usd,
|
| 28 |
"hard_limit_usd": hard_limit_usd,
|
| 29 |
+
"plan": plan_title + ", " + plan_id}
|
| 30 |
else:
|
| 31 |
return {"account_name": "",
|
| 32 |
"has_payment_method": False,
|
| 33 |
"hard_limit_usd": "",
|
| 34 |
"plan": ""}
|
| 35 |
|
| 36 |
+
#def get_usage(key):
|
| 37 |
+
# if check_key_availability():
|
| 38 |
+
# start_date = datetime.now().strftime('%Y-%m-01')
|
| 39 |
+
# end_date = (datetime.now() + relativedelta(months=1)).strftime('%Y-%m-01')
|
| 40 |
+
# queryUrl = f'https://api.openai.com/dashboard/billing/usage?start_date={start_date}&end_date={end_date}'
|
| 41 |
+
# headers = get_headers(key)
|
| 42 |
+
# r = requests.get(queryUrl, headers=headers)
|
| 43 |
+
# return r.json()
|
| 44 |
+
# else:
|
| 45 |
+
# return ""
|
| 46 |
|
| 47 |
def check_gpt4_availability():
|
| 48 |
if check_key_availability():
|