BazaarLinkBazaarLink
登入
文件API 參考SDK 參考Agent 應用AI Skills
帳戶

取得用量洞察

一次回傳 /insights 頁面需要的所有資料:三種指標(token/花費/請求數)的趨勢、各指標前三名模型、快取命中統計、token 用量分解、年度熱力圖(含連續天數)、餘額與免費模型用量、篩選面板選項。依 (使用者, period, heatmap_metric, 篩選條件) 組合快取 5 分鐘。

GET/api/v1/insights

驗證

Authorization必填
string · header

在 Authorization 標頭以 Bearer token 傳入 API 金鑰。

查詢參數

period
string

驅動整頁的統計區間,預設 7d。無效值回 400。

7d30dytdall
Example: "30d"
heatmap_metric
string

年度熱力圖顯示的指標(熱力圖固定為整年,不受 period 影響),預設 spend。無效值回 400。

spendtokensrequests
Example: "tokens"
model
string

頁面全域篩選——只計入此模型的用量。省略時不篩選。

api_key_id
string

頁面全域篩選——只計入此 API 金鑰的用量。省略時不篩選。

app
string

頁面全域篩選——只計入此應用程式名稱(x-title / HTTP-Referer)的用量。省略時不篩選。

GET /api/v1/insights
curl "https://bazaarlink.ai/api/v1/insights?period=30d&heatmap_metric=tokens" \
  -H "Authorization: Bearer $BAZAARLINK_API_KEY"
回應範例

成功。trend/topModels/heatmap 固定回傳三個指標的完整資料(tokens、spend、requests),前端切換不必重新請求;caching 與 breakdown 依 period 分桶(≤120 天日粒度、≤730 週粒度,否則月粒度)。以下為節錄範例,實際 buckets/heatmap.days 陣列會依區間長度含多筆。

{
  "period": "30d",
  "bucketUnit": "day",
  "trend": {
    "tokens": {
      "total": 152000,
      "prevTotal": 98000,
      "changePct": 55.1,
      "buckets": [
        {
          "date": "2026-07-01",
          "segs": [
            {
              "model": "openai/gpt-4.1",
              "value": 5200
            }
          ]
        }
      ]
    },
    "spend": {
      "total": 4.82,
      "prevTotal": 3.1,
      "changePct": 55.5,
      "buckets": [
        {
          "date": "2026-07-01",
          "segs": [
            {
              "model": "openai/gpt-4.1",
              "value": 0.16
            }
          ]
        }
      ]
    },
    "requests": {
      "total": 340,
      "prevTotal": 210,
      "changePct": 61.9,
      "buckets": [
        {
          "date": "2026-07-01",
          "segs": [
            {
              "model": "openai/gpt-4.1",
              "value": 12
            }
          ]
        }
      ]
    }
  },
  "topModels": {
    "tokens": [
      {
        "model": "openai/gpt-4.1",
        "provider": "openai",
        "value": 152000,
        "unit": "tokens"
      }
    ],
    "spend": [
      {
        "model": "openai/gpt-4.1",
        "provider": "openai",
        "value": 4.82,
        "unit": "spend"
      }
    ],
    "requests": [
      {
        "model": "openai/gpt-4.1",
        "provider": "openai",
        "value": 340,
        "unit": "requests"
      }
    ]
  },
  "caching": {
    "buckets": [
      {
        "date": "2026-07-01",
        "hit": 3200,
        "write": 800
      }
    ],
    "totalHit": 96000,
    "totalWrite": 24000
  },
  "breakdown": {
    "buckets": [
      {
        "date": "2026-07-01",
        "prompt": 4000,
        "completion": 1200,
        "reasoning": 0,
        "cached": 3200
      }
    ],
    "totals": {
      "prompt": 120000,
      "completion": 32000,
      "reasoning": 0,
      "cached": 96000
    }
  },
  "heatmap": {
    "spend": {
      "days": [
        {
          "date": "2026-01-01",
          "value": 0.02
        }
      ],
      "streak": {
        "current": 5,
        "longest": 21
      },
      "avgDay": 0.16,
      "avgWeek": 1.12,
      "total": 58.4
    },
    "tokens": {
      "days": [
        {
          "date": "2026-01-01",
          "value": 640
        }
      ],
      "streak": {
        "current": 5,
        "longest": 21
      },
      "avgDay": 5066,
      "avgWeek": 35462,
      "total": 1850000
    },
    "requests": {
      "days": [
        {
          "date": "2026-01-01",
          "value": 4
        }
      ],
      "streak": {
        "current": 5,
        "longest": 21
      },
      "avgDay": 11.3,
      "avgWeek": 79,
      "total": 4130
    }
  },
  "credit": {
    "today": 0.16,
    "thisWeek": 1.12,
    "thisMonth": 4.82
  },
  "freeModel": {
    "today": 0,
    "thisWeek": 0,
    "thisMonth": 0
  },
  "facets": {
    "models": [
      "openai/gpt-4.1"
    ],
    "apiKeys": [
      {
        "id": "key_abc123",
        "name": "default"
      }
    ],
    "apps": [
      "my-app"
    ]
  }
}
客服
客服
您好!有什麼可以協助?
請留下訊息,我們會盡快回覆。
取得用量洞察 — BazaarLink API