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