系统请求

获取模型 ​

curl

curl -L -X GET 'https://api.moka-ai.com/v1/models' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer sk-xxx'

python

python

import requests url = "https://api.moka-ai.com/v1/models" payload = {} headers = { 'Accept': 'application/json', 'Authorization': 'Bearer sk-xxx' } response = requests.request("GET", url, headers=headers, data=payload) # 将响应内容转换为字典 response_dict = response.json() # 提取模型 ID model_ids = [model.get("id") for model in response_dict.get("data", [])] # 将模型 ID 写入到文件 with open("model_ids.txt", "w") as file: for model_id in model_ids: file.write(model_id + "\n") print("模型 ID 已保存到 model_ids.txt 文件中。")

令牌余额查询 ​

python

import requests def get_total_usage(api_key): headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } # 获取订阅信息 response_subscription = requests.get("https://api.moka-ai.com/v1/dashboard/billing/subscription", headers=headers) if response_subscription.status_code != 200: return f"获取订阅数据出错: {response_subscription.text}" try: subscription_data = response_subscription.json() total_limit = subscription_data.get("hard_limit_usd") except ValueError: return "解析订阅数据时出错" # 获取已用额度 response_usage = requests.get("https://api.moka-ai.com/v1/dashboard/billing/usage", headers=headers) if response_usage.status_code != 200: return f"获取使用数据时出错:{response_usage.text}" try: billing_data = response_usage.json() total_usage_usd = billing_data.get("total_usage", 0) / 100 # 使用默认值0以防止缺失 except ValueError: return "解析使用数据时出错" print(f"\n总额度: ${total_limit:.2f} \n已用额度: ${total_usage_usd:.2f} \n剩余额度:${total_limit - total_usage_usd:.2f} \n") if __name__ == '__main__': api_key = "sk-xxx" get_total_usage(api_key)

你将会收到如下回复(举例):

总额度: $292.31 已用额度: $202.30 剩余额度:$90.01

后台余额查询 ​

python

import requests def get_user_self():     # API端点     url = "https://api.moka-ai.com/api/user/self"         # 请求头     headers = {         "New-Api-User": "输入你的后台ID",         "Authorization": "Bearer 输入你的系统令牌"     }         try:         # 发送GET请求         response = requests.get(url, headers=headers)                 # 检查响应状态码         if response.status_code == 200:             data = response.json()                         if data["success"]:                 # 获取quota、used_quota和request_count数值                 quota = data["data"]["quota"]                 used_quota = data["data"]["used_quota"]                 request_count = data["data"]["request_count"]                                 # 将数值转换为美元显示 (数值/500000 = $xx.xx)                 quota_dollars = quota / 500000                 used_quota_dollars = used_quota / 500000                                 # 按要求格式输出结果                 print(f"剩余额度:${quota_dollars:.2f}")                 print(f"已用额度:${used_quota_dollars:.2f}")                 print(f"请求次数:{request_count}")             else:                 print(f"请求成功但返回错误: {data['message']}")                         else:             print(f"请求失败,状态码: {response.status_code}")             print("响应内容:", response.text)                 except Exception as e:         print(f"发生错误: {e}") # 执行请求 if __name__ == "__main__":     get_user_self()
  1. 进入个人设置 - 找到并点击生成系统访问令牌
  2. 找到右上角的ID
  3. 将以上两个信息放入请求示例,获取响应体。

返回内容:

剩余额度:$xx.xx 已用额度:$xx.xx 请求次数:xxx

TIP

如果您需要获取各个技术栈的调用示例代码,请查阅此处>>