System Requests
Get Models
curl
curl -L -X GET 'https://api.juheai.top/v1/models' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer sk-xxx'
python
python
import requests
url = "https://api.juheai.top/v1/models"
payload = {}
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer sk-xxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
# Convert response content to dictionary
response_dict = response.json()
# Extract model IDs
model_ids = [model.get("id") for model in response_dict.get("data", [])]
# Write model IDs to file
with open("model_ids.txt", "w") as file:
for model_id in model_ids:
file.write(model_id + "\n")
print("Model IDs have been saved to model_ids.txt file.")
Token Balance Query
python
import requests
def get_total_usage(api_key):
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
# Get subscription information
response_subscription = requests.get("https://api.juheai.top/v1/dashboard/billing/subscription", headers=headers)
if response_subscription.status_code != 200:
return f"Error getting subscription data: {response_subscription.text}"
try:
subscription_data = response_subscription.json()
total_limit = subscription_data.get("hard_limit_usd")
except ValueError:
return "Error parsing subscription data"
# Get used quota
response_usage = requests.get("https://api.juheai.top/v1/dashboard/billing/usage", headers=headers)
if response_usage.status_code != 200:
return f"Error getting usage data: {response_usage.text}"
try:
billing_data = response_usage.json()
total_usage_usd = billing_data.get("total_usage", 0) / 100 # Use default value 0 to prevent missing data
except ValueError:
return "Error parsing usage data"
print(f"\nTotal Quota: ${total_limit:.2f} \nUsed Quota: ${total_usage_usd:.2f} \nRemaining Quota: ${total_limit - total_usage_usd:.2f} \n")
if __name__ == '__main__':
api_key = "sk-xxx"
get_total_usage(api_key)
You will receive a response like this (example):
Total Quota: $292.31
Used Quota: $202.30
Remaining Quota: $90.01
Admin Backend Balance Query
python
import requests
def get_user_self():
# API endpoint
url = "https://api.juheai.top/api/user/self"
# Request headers
headers = {
"New-Api-User": "Enter your backend ID",
"Authorization": "Bearer Enter your system token"
}
try:
# Send GET request
response = requests.get(url, headers=headers)
# Check response status code
if response.status_code == 200:
data = response.json()
if data["success"]:
# Get quota, used_quota, and request_count values
quota = data["data"]["quota"]
used_quota = data["data"]["used_quota"]
request_count = data["data"]["request_count"]
# Convert values to dollars (value/500000 = $xx.xx)
quota_dollars = quota / 500000
used_quota_dollars = used_quota / 500000
# Output results in the required format
print(f"Remaining Quota: ${quota_dollars:.2f}")
print(f"Used Quota: ${used_quota_dollars:.2f}")
print(f"Request Count: {request_count}")
else:
print(f"Request successful but returned error: {data['message']}")
else:
print(f"Request failed, status code: {response.status_code}")
print("Response content:", response.text)
except Exception as e:
print(f"An error occurred: {e}")
# Execute request
if __name__ == "__main__":
get_user_self()
- Go to
Personal Settings
- Find and clickGenerate System Access Token
- Find the
ID
in the upper right corner - Put these two pieces of information into the request example to get the response body.
Response content:
Remaining Quota: $xx.xx
Used Quota: $xx.xx
Request Count: xxx
TIP
If you need to obtain example code for various technology stacks, please check here>>