获取账户和用量

GET /v1/me——密钥背后的工作区、API 密钥和套餐,以及本计费周期的用量。在 CI 中验证密钥,并在代码中监控你的配额。

GET https://api.dcision.io/v1/me

返回 API 密钥的归属——其工作区、密钥本身和套餐——以及当前计费周期已使用的计费决策。用它在 CI 中或启动时验证密钥,并在你自己的代码中显示配额或发出配额告警。

请求

没有参数,也没有请求体。使用与决策相同的 API 密钥进行认证:

curl https://api.dcision.io/v1/me \
  -H "Authorization: Bearer $DCISION_API_KEY"

响应

200 OK
{
  "workspace": { "id": "4c8f2a91-6d3b-4e7a-9f15-2b0c7d8e6a43", "name": "Acme", "external_id": null, "parent": null },
  "workspace_usage": null,
  "api_key": {
    "id": "key_7Hq2Lm9Xc4Rv1Tz8Wn3B",
    "name": "Production",
    "prefix": "dcs_live_9fK2…0Ad2",
    "environment": "live"
  },
  "plan": {
    "id": "growth",
    "name": "Growth",
    "rate_limit_per_minute": 2000,
    "max_decisions": null,
    "log_retention_days": 30,
    "hard_cap": false
  },
  "usage": {
    "used": 1284311,
    "included": 10000000,
    "period_start": "2026-10-01T00:00:00.000Z",
    "period_end": "2026-11-01T00:00:00.000Z"
  }
}
字段类型说明
workspace.idstring工作区的 ID。
workspace.namestring工作区的名称。
workspace.external_idstring | null合作伙伴模式:带 Dcision-Workspace 请求头时,为子工作区的 external_id;否则为 null。
workspace.parentobject | null带 Dcision-Workspace 请求头时:你的工作区的 { "id", "name" },由它为子工作区付费。此时 plan 和 usage 是你的。
workspace_usageobject | null带 Dcision-Workspace 请求头时:{ "used", "limit", "period_start", "period_end" }——子工作区本周期的计费运行次数及其限制(null = 无限制)。
api_key.idstring密钥的 ID(key_…)。
api_key.namestring在 API 密钥中为密钥指定的名称。
api_key.prefixstring遮蔽后的密钥,与应用中显示的一致——从不是完整的密文。
api_key.environmentstringlive 或 test。
plan.idstringgenesis、developer、growth 或 enterprise。
plan.namestring套餐的显示名称。
plan.rate_limit_per_minuteinteger工作区每分钟允许的请求数——参见速率限制。
plan.max_decisionsinteger 或 null工作区可以拥有的决策数;null 表示不限。
plan.log_retention_daysinteger套餐保留执行记录的时长。
plan.hard_capboolean当套餐不能用额度继续时为 true:一旦包含的用量用完,调用会被 402 QUOTA_EXCEEDED 拦截。在 Genesis、Developer 和 Growth 上为 false——超出包含量后它们使用额度。
usage.usedinteger当前周期的计费决策数。
usage.includedinteger当前周期包含的决策数——在按年套餐上为全年的总量。
usage.period_startstring当前计费周期的开始时间,ISO 8601。
usage.period_endstring当前计费周期的结束时间,ISO 8601。

计费周期在付费套餐上是订阅周期,在 Genesis 上是 UTC 自然月——参见套餐、配额与计费。

示例

当密钥错误时,让 CI 任务尽早失败:

dcision_me=$(curl -sf https://api.dcision.io/v1/me -H "Authorization: Bearer $DCISION_API_KEY") \
  || { echo "Invalid Dcision API key" >&2; exit 1; }
echo "$dcision_me" | jq -r '"\(.workspace.name) · \(.api_key.environment) · \(.plan.name)"'

在包含的用量用完之前发出警告——超出之后,决策会使用额度:

const me = await fetch("https://api.dcision.io/v1/me", {
  headers: { Authorization: `Bearer ${process.env.DCISION_API_KEY}` },
}).then((response) => response.json());

const share = me.usage.used / me.usage.included;
if (share >= 0.9) alert(`Dcision: ${Math.round(share * 100)}% of the included volume used`);

错误

状态码代码何时
401INVALID_API_KEY密钥缺失、格式错误、未知或已被撤销。
429RATE_LIMITED当前分钟内的读取请求过多。

读取端点——GET /v1/me 和 GET /v1/executions——共享一个独立的速率限制窗口,使用你套餐的每分钟限制,因此轮询它们永远不会拖慢你的决策。读取不计费。

本页内容