
Crazyrouter 调用日志与消费对账:团队如何查看、导出和管理 AI API 消费明细
C
Crazyrouter Team
April 16, 2026
337 views中文Tutorial
Share:
Crazyrouter 调用日志与消费对账:团队如何查看、导出和管理 AI API 消费明细#
你能看到什么#
Crazyrouter 的管理接口提供完整的消费追踪能力。每一次 API 调用都会记录以下信息:
| 字段 | 说明 | 用途 |
|---|---|---|
| 调用时间 | 精确到秒 | 时间范围筛选 |
| API Key 名称 | 哪个 Key 发起的请求 | 按成员/项目归类 |
| 模型名称 | 实际使用的模型 | 按模型统计成本 |
| 输入 Token 数 | prompt_tokens | 成本分析 |
| 输出 Token 数 | completion_tokens | 成本分析 |
| 消费金额(美元) | cost_usd | 直接用于对账 |
| 请求耗时 | 秒 | 性能监控 |
| 调用客户端 | openai-python 等 | 来源追踪 |
| 请求 ID | request_id | 问题排查 |
| 响应状态码 | 200/400/500 等 | 成功率监控 |
四个核心场景#
场景 1:查看某个成员的消费#
给每个团队成员分配独立的 API Key(比如张三用 key-zhangsan,李四用 key-lisi)。
然后按 token_name 筛选,就能看到每个人的消费明细:
python
import requests
headers = {
"Authorization": "Bearer your_access_token",
"New-Api-User": "your_user_id"
}
# 查张三这个月的消费汇总
resp = requests.get(
"https://crazyrouter.com/api/log/self/stat",
params={
"type": 2,
"token_name": "key-zhangsan",
"start_timestamp": 1743465600, # 2026-04-01
"end_timestamp": 1746057600, # 2026-05-01
},
headers=headers
)
quota = resp.json()["data"]["quota"]
# 换算美元
status = requests.get("https://crazyrouter.com/api/status").json()
cost_usd = quota / status["data"]["quota_per_unit"]
print(f"张三 4 月消费: ${cost_usd:.2f}")
场景 2:按模型统计消费分布#
想知道团队的钱主要花在哪个模型上?拉取明细日志,按 model_name 分组统计:
python
import requests
from collections import defaultdict
resp = requests.get(
"https://crazyrouter.com/api/log/self",
params={
"type": 2,
"start_timestamp": 1743465600,
"end_timestamp": 1746057600,
"p": 1,
"page_size": 500
},
headers=headers
)
logs = resp.json()["data"]["items"]
model_costs = defaultdict(float)
for log in logs:
model_costs[log["model_name"]] += log.get("cost_usd", 0)
for model, cost in sorted(model_costs.items(), key=lambda x: -x[1]):
print(f"{model}: ${cost:.4f}")
输出示例:
code
claude-sonnet-4.6: $18.5032
gpt-5-mini: $4.2100
deepseek-chat: $2.1045
gpt-5-nano: $1.8012
场景 3:导出消费明细做经费核算#
把日志数据导出为 CSV,交给财务或用于项目结题报告:
python
import csv
with open("consumption_report.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["时间", "Key", "模型", "输入Token", "输出Token", "消费(USD)", "耗时(秒)"])
for log in logs:
from datetime import datetime
ts = datetime.fromtimestamp(log["created_at"]).strftime("%Y-%m-%d %H:%M:%S")
writer.writerow([
ts,
log["token_name"],
log["model_name"],
log["prompt_tokens"],
log["completion_tokens"],
f'{log.get("cost_usd", 0):.6f}',
log["use_time"]
])
print("已导出 consumption_report.csv")
场景 4:月度消费汇总报告#
python
# 获取当月总消费
stat = requests.get(
"https://crazyrouter.com/api/log/self/stat",
params={
"type": 2,
"start_timestamp": 1743465600,
"end_timestamp": 1746057600,
},
headers=headers
).json()
quota = stat["data"]["quota"]
status = requests.get("https://crazyrouter.com/api/status").json()
qpu = status["data"]["quota_per_unit"]
rate = status["data"]["usd_exchange_rate"]
cost_usd = quota / qpu
cost_cny = cost_usd * rate
print(f"本月总消费: ${cost_usd:.2f} (约 ¥{cost_cny:.2f})")
管理能力一览#
| 能力 | 支持情况 |
|---|---|
| 多 API Key 管理 | ✅ 一个账号下创建多个 Key |
| 按 Key 隔离消费 | ✅ 每个 Key 独立统计 |
| 按模型筛选 | ✅ 查看特定模型的消费 |
| 按时间范围筛选 | ✅ 自定义起止时间 |
| 单次请求花费 | ✅ cost_usd 字段 |
| 汇总统计 | ✅ 总额度和总花费 |
| 模型使用限制 | ✅ 单个 Key 可限制可用模型 |
| 请求链路追踪 | ✅ request_id |
| 成功率监控 | ✅ http_status |
| 美元/人民币换算 | ✅ 系统提供汇率参数 |
适合谁用#
- 技术负责人:监控团队 AI API 总支出,按项目分配预算
- 项目经理:导出消费明细,做项目经费核算
- 财务人员:获取消费报告,用于报销和对账
- 个人开发者:追踪自己的模型使用和花费
开始使用#
- 登录 Crazyrouter 控制台
- 在控制台查看调用日志和消费统计
- 或通过管理 API 自动化拉取数据
- 详细 API 文档:调用日志与花费监控
机构采购咨询:support@crazyrouter.com
Implementation Guides
Usage Logs and Cost MonitoringUse management APIs to query logs, quota, token usage, and dollar cost.AuthenticationCreate and use API keys with the required authorization headers.Quick Start GuideMake the first Crazyrouter API call and validate your setup.List ModelsQuery models available to the current API key through GET /v1/models.
Topics
Tutorial





