跳转到主要内容
GET
/
billing
/
usage-analytics
/api/v1/billing/usage-analytics
curl --request GET \
  --url https://api.venice.ai/api/v1/billing/usage-analytics \
  --header 'Authorization: Bearer <token>'
{
  "lookback": "7d",
  "byDate": [
    {
      "date": "2024-01-15T00:00:00.000Z",
      "USD": 0.5,
      "DIEM": 10.25
    },
    {
      "date": "2024-01-14T00:00:00.000Z",
      "USD": 0.3,
      "DIEM": 8.75
    }
  ],
  "byModel": [
    {
      "modelName": "GLM 5.1",
      "unitType": "tokens",
      "modelType": "LLM",
      "totalUsd": 0.4,
      "totalDiem": 12.5,
      "totalUnits": 50000,
      "breakdown": [
        {
          "type": "Output",
          "usd": 0.3,
          "diem": 10,
          "units": 35000
        },
        {
          "type": "Input",
          "usd": 0.1,
          "diem": 2.5,
          "units": 15000
        }
      ]
    }
  ],
  "byModelDaily": [
    {
      "date": 1705276800000,
      "GLM 5.1": 5.5,
      "Kimi K2.6": 3.2
    }
  ],
  "topModels": [
    "GLM 5.1",
    "Kimi K2.6"
  ],
  "byKey": [
    {
      "apiKeyId": "key_abc123",
      "description": "Production Key",
      "totalUsd": 0.8,
      "totalDiem": 15,
      "totalUnits": 75000
    },
    {
      "apiKeyId": null,
      "description": "Web App",
      "totalUsd": 0,
      "totalDiem": 4,
      "totalUnits": 25000
    }
  ],
  "byKeyDaily": [
    {
      "date": 1705276800000,
      "Production Key": 8.5,
      "Web App": 2
    }
  ],
  "topKeyNames": [
    "Production Key",
    "Web App"
  ]
}
这是一个 beta 端点,可能不稳定或在无通知的情况下变更。
获取已认证用户的汇总用量分析,按日期、模型和 API 密钥进行细分。此端点提供 API 用量数据的汇总视图,可用于构建仪表板和监控消耗。数据缓存 10 分钟。

查询参数

您可以使用以下任一方式指定分析的时间段:
  • lookback:相对时间段,例如 “7d”(7 天)、“30d”(30 天),最长 “90d”(90 天)
  • startDateendDate:以 YYYY-MM-DD 格式自定义日期范围。如果提供其中之一,则两者都必填。
如果未指定参数,默认 lookback 时间段为 7 天。

响应字段

lookback

查询所使用的 lookback 时间段。以 “Nd” 格式(如 “7d”)或 “startDate:endDate” 格式返回。

byDate

所请求时间段内的每日用量合计。
  • date:以 YYYY-MM-DD 格式的日期
  • USD:当天以 USD 计的总用量
  • DIEM:当天以 DIEM 计的总用量

byModel

按模型划分的用量细分,按总支出降序排序。
  • modelName:模型的显示名称(例如 “GLM 5”)
  • unitType:消耗的单位类型(tokens、images、chars、minutes、seconds)
  • modelType:模型类型(LLM、IMAGE、TTS、ASR、VIDEO),或 null
  • totalUsd:此模型上花费的总 USD
  • totalDiem:此模型上花费的总 DIEM
  • totalUnits:此模型消耗的总单位数
  • breakdown:按类型划分的用量细分数组(仅在存在多种类型时出现)。每个条目包含:
    • type:Token 类型(例如 “Input”、“Output”、“Cache Read”、“Cache Write”)
    • usd:此细分的 USD 金额
    • diem:此细分的 DIEM 金额
    • units:此细分的单位数量

byModelDaily

前 8 个模型的每日图表数据。每个条目包含 “date”(时间戳)以及以模型名称为键、DIEM 用量为值的数据。

topModels

按用量排序的前 8 个模型名称数组,用于图表图例。

byKey

按 API 密钥划分的用量细分,按总支出降序排序。
  • apiKeyId:API 密钥 ID,如果用量来自 Web 应用则为 null
  • description:API 密钥描述或 “Web App”
  • totalUsd:通过此密钥花费的总 USD
  • totalDiem:通过此密钥花费的总 DIEM
  • totalUnits:通过此密钥消耗的总单位数

byKeyDaily

前 8 个 API 密钥的每日图表数据。每个条目包含 “date”(时间戳)以及以密钥描述为键、DIEM 用量为值的数据。

topKeyNames

按用量排序的前 8 个 API 密钥描述数组,用于图表图例。

使用示例

# 获取过去 7 天的用量分析(默认)
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics" \
  -H "Authorization: Bearer YOUR_API_KEY"

# 获取过去 30 天的用量分析
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics?lookback=30d" \
  -H "Authorization: Bearer YOUR_API_KEY"

# 获取特定日期范围的用量分析
curl -X GET "https://api.venice.ai/api/v1/billing/usage-analytics?startDate=2024-01-01&endDate=2024-01-31" \
  -H "Authorization: Bearer YOUR_API_KEY"

授权

Authorization
string
header
必填

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

查询参数

lookback
string
默认值:7d

Lookback period for usage data. Format: number followed by "d" (e.g., "7d", "30d"). Maximum: 90d

Pattern: ^[1-9]\d*d$
示例:

"7d"

startDate
string

Start date for filtering records (YYYY-MM-DD). If provided, endDate is also required.

Pattern: ^\d{4}-\d{2}-\d{2}$
示例:

"2024-01-01T00:00:00.000Z"

endDate
string

End date for filtering records (YYYY-MM-DD). If provided, startDate is also required.

Pattern: ^\d{4}-\d{2}-\d{2}$
示例:

"2024-01-31T00:00:00.000Z"

响应

Successful response with aggregated usage analytics

Aggregated usage analytics response with breakdowns by date, model, and API key

lookback
string
必填

The lookback period used for the query. Either "Nd" format or "startDate:endDate" format.

示例:

"7d"

byDate
object[]
必填

Daily usage totals for the requested period

byModel
object[]
必填

Usage breakdown by model, sorted by total spend (highest first)

byModelDaily
object[]
必填

Daily chart data for top 8 models. Each entry has "date" (timestamp) plus model names as keys.

topModels
string[]
必填

Names of the top 8 models by usage (for chart legends)

byKey
object[]
必填

Usage breakdown by API key, sorted by total spend (highest first)

byKeyDaily
object[]
必填

Daily chart data for top 8 API keys. Each entry has "date" (timestamp) plus key descriptions as keys.

topKeyNames
string[]
必填

Descriptions of the top 8 API keys by usage (for chart legends)