账户管理

账户余额与用量

查询 API Key 维度的剩余额度,以及 OpenAI 兼容的订阅和用量信息。

账户余额与用量

这部分接口同时提供平台自定义包装和 OpenAI 兼容结构。

API Key 用量

GET /api/usage/token/
curl https://duoyuanx.com/api/usage/token/ \
  -H "Authorization: Bearer YOUR_API_KEY"
import requests

resp = requests.get(
    "https://duoyuanx.com/api/usage/token/",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    timeout=30,
)
print(resp.json())
const response = await fetch("https://duoyuanx.com/api/usage/token/", {
  headers: { Authorization: "Bearer YOUR_API_KEY" },
});

console.log(await response.json());

成功响应:

{
  "code": true,
  "message": "ok",
  "data": {
    "object": "token_usage",
    "name": "default-token",
    "total_granted": 1000000,
    "total_used": 250000,
    "total_available": 750000,
    "unlimited_quota": false,
    "model_limits": {
      "gpt-4o": 10000
    },
    "model_limits_enabled": true,
    "expires_at": 1767225600
  }
}

OpenAI 兼容订阅信息

两个路径等价:

  • GET /dashboard/billing/subscription
  • GET /v1/dashboard/billing/subscription

响应示例:

{
  "object": "billing_subscription",
  "has_payment_method": true,
  "soft_limit_usd": 100.0,
  "hard_limit_usd": 100.0,
  "system_hard_limit_usd": 100.0,
  "access_until": 1767225600
}

OpenAI 兼容用量

两个路径等价:

  • GET /dashboard/billing/usage
  • GET /v1/dashboard/billing/usage

响应示例:

{
  "object": "list",
  "total_usage": 2500
}

soft_limit_usd、hard_limit_usd 和 total_usage 最终显示单位受站点配额展示配置影响,不一定始终是美元。

常见错误

/api/usage/token/ 缺少 Authorization

{
  "success": false,
  "message": "No Authorization header"
}

/api/usage/token/ Bearer 格式错误

{
  "success": false,
  "message": "Invalid Bearer token"
}

OpenAI 兼容余额接口错误

{
  "error": {
    "message": "query quota failed",
    "type": "upstream_error",
    "param": "",
    "code": null
  }
}

相关页面