BazaarLinkBazaarLink
登入
文件API 参考SDK 参考Agent 应用AI Skills
账户

获取用量摘要

返回指定区间的花费/请求数/token 统计,并依模型、依 API 密钥、依应用程序(app_name)三种维度拆分,外加逐日时间序列。与 /v1/insights 不同,这条没有前三名模型、缓存统计或年度热力图——是较轻量的加总端点,支持自定义日期区间(period=custom)。

GET/api/v1/usage

验证

Authorization必填
string · header

在 Authorization 标头以 Bearer token 传入 API 密钥。

查询参数

period
string

统计区间,默认 month。三种形式:旧制日历词(day/week/month/year)、以现在为终点的滚动窗口(15m…1y)、对齐日历的区间(today…prev_year),或 custom(需搭配 from/to)。无效值返回 400。

dayweekmonthyear15m30m1h3h1d2d1w1mo1ytodayyesterdaythis_weekprev_weekthis_monthprev_monththis_yearprev_yearcustom
Example: "month"
from
string

自定义区间的起点(ISO 8601)。只在 period=custom 时使用。

ISO 8601, required with period=custom
Example: "2026-07-01T00:00:00.000Z"
to
string

自定义区间的终点(ISO 8601)。只在 period=custom 时使用。

ISO 8601, required with period=custom
Example: "2026-07-27T00:00:00.000Z"
GET /api/v1/usage
curl "https://bazaarlink.ai/api/v1/usage?period=month" \
  -H "Authorization: Bearer $BAZAARLINK_API_KEY"
响应示例

成功。totals 为区间总计;byModel/byKey/byApp 是三种各自独立的拆分维度(不是嵌套关系);timeSeries 是逐日(依 model 分段)的花费/token/请求数。以下为节选范例。

{
  "period": "month",
  "since": "2026-07-01T00:00:00.000Z",
  "until": "2026-07-27T12:00:00.000Z",
  "credits": 42.5,
  "totals": {
    "spend": 4.82,
    "requests": 340,
    "tokens": 152000,
    "promptTokens": 120000,
    "completionTokens": 32000
  },
  "byModel": [
    {
      "model": "openai/gpt-4.1",
      "spend": 4.82,
      "tokens": 152000,
      "requests": 340
    }
  ],
  "byKey": [
    {
      "keyId": "key_abc123",
      "keyName": "default",
      "spend": 4.82,
      "tokens": 152000,
      "requests": 340,
      "spendLimitUsd": null,
      "spendLimitPeriod": null
    }
  ],
  "byApp": [
    {
      "appName": "my-app",
      "spend": 4.82,
      "tokens": 152000,
      "requests": 340
    }
  ],
  "timeSeries": [
    {
      "date": "2026-07-01",
      "model": "openai/gpt-4.1",
      "cost": 0.16,
      "tokens": 5200,
      "requests": 12
    }
  ]
}
客服
客服
您好!有什么可以协助?
请留下消息,我们会尽快回复。
获取用量摘要 — BazaarLink API