API ReferenceUsage & Reporting

Reporting Access Key

Reporting Access Key 是在控制檯管理的只讀報表密鑰,用于从内部系统查詢 API Key、用量、Token 消耗、任務記錄和費用数据。它适合财务對賬、客戶用量核对、監控和内部 BI 管道,不用于调用模型。

1. 适用场景

当你需要以下能力时,可以使用 Reporting Access Key:

  • 将发票或账单金额与任務级用量記錄做核对
  • 将用量数据同步到内部 BI、FinOps 或監控系统
  • 按 API Key、模型、任務类型、狀態或日期統計 Token 与費用
  • 在不共享控制檯權限的情况下排查单个任務記錄

它不是模型调用密鑰,只能访问本文档中的 /api/open/v1/* 報表接口。

2. 創建与管理

打开控制檯頁面:

/dashboard/apikeys

Reporting Access Key 卡片中:

  1. 点击 Generate 生成密鑰。
  2. 複製密鑰,并保存到安全的密鑰管理系统中。
  3. 需要再次複製完整值时,点击 Copy
  4. 需要停用时,点击 Revoke

安全规则:

  • 頁面默认只展示脫敏后的 key。
  • 完整 key 只会在点击 Copy 时临时獲取。
  • 不要把完整 key 存入 localStorage、analytics、截图、工单或客戶端日誌。
  • 當前每个用户最多只有一个 active Reporting Access Key。
  • revoke 后密鑰会立即失效,但記錄不会被 hard delete。

3. 认证方式

在請求头中携带 Reporting Access Key:

Authorization: Bearer <REPORTING_ACCESS_KEY>
Accept: application/json

所有響應使用统一结构:

{
  "code": 200,
  "msg": "",
  "data": {}
}

4. 接口列表

EndpointPurposeMax date range
GET /api/open/v1/apikeysList visible API keys and their last usage timeNot applicable
GET /api/open/v1/usage/summaryAggregate requests, tokens, credits, and USD amount31 days
GET /api/open/v1/usage/dailyDaily usage breakdown, optionally grouped by API key and model31 days
GET /api/open/v1/usage/tasksPaginated task-level usage records7 days
GET /api/open/v1/usage/tasks/{task_id}Single task detailNot applicable

Base URL:

https://reachapi.ai/api/open/v1

本地開發可使用:

http://localhost:3000/api/open/v1

5. 查詢 API Key 列表

curl -sS "https://reachapi.ai/api/open/v1/apikeys?page=1&page_size=20&status=active" \
  -H "Authorization: Bearer <REPORTING_ACCESS_KEY>"

查詢参数:

FieldTypeRequiredDescription
pageintegerNoPage number. Default: 1
page_sizeintegerNoPage size. Default: 50, maximum: 200
statusstringNoFilter API keys by status, for example active

Example response:

{
  "code": 200,
  "msg": "",
  "data": {
    "total": 3,
    "page": 1,
    "page_size": 20,
    "items": [
      {
        "apikey_id": "ak_123",
        "apikey_name": "Production gateway",
        "status": "active",
        "created_at": "2026-06-27T08:00:00.000Z",
        "last_used_at": "2026-06-27T09:15:00.000Z",
        "hourly_limit_usd": "5.00000000",
        "daily_limit_usd": "20.00000000",
        "total_limit_usd": "100.00000000",
        "quota_timezone": "Asia/Shanghai"
      }
    ]
  }
}

每個條目包含:

欄位說明
apikey_idAPI key ID
apikey_nameAPI key 名稱
statusAPI key 狀態(active / deleted
created_at建立時間
last_used_at最近使用時間(未使用過則為 null
hourly_limit_usd小時消費限額(USD),未設定則為 null
daily_limit_usd每日消費限額(USD),未設定則為 null
total_limit_usd累計消費限額(USD),未設定則為 null
quota_timezone限額視窗時區(預設 Asia/Shanghai

6. 用量彙總

curl -sS "https://reachapi.ai/api/open/v1/usage/summary?start_date=2026-06-01&end_date=2026-06-07&timezone=Asia/Shanghai" \
  -H "Authorization: Bearer <REPORTING_ACCESS_KEY>"

查詢参数:

FieldTypeRequiredDescription
start_datestringYesDate in YYYY-MM-DD format
end_datestringYesDate in YYYY-MM-DD format. Maximum 31-day range
timezonestringNoIANA timezone. Default: UTC
apikey_idstringNoFilter by one visible API key
modelstringNoFilter by model ID
task_typestringNoFilter by task type
statusstringNoFilter by task status
finance_statusstringNoFilter by billing status
provider_job_idstringNoFilter by upstream provider job ID

響應中会包含請求数、成功/失败数、各类 token、actual_credits 和 USD 字符串 total_amount

7. 按日統計

curl -sS "https://reachapi.ai/api/open/v1/usage/daily?start_date=2026-06-01&end_date=2026-06-07&group_by=apikey,model" \
  -H "Authorization: Bearer <REPORTING_ACCESS_KEY>"

group_by 支持:

ValueDescription
noneOne row per day
apikeyGroup by day and API key
modelGroup by day and model
apikey,modelGroup by day, API key, and model

8. 任務列表

curl -sS "https://reachapi.ai/api/open/v1/usage/tasks?start_date=2026-06-01&end_date=2026-06-07&page=1&page_size=50" \
  -H "Authorization: Bearer <REPORTING_ACCESS_KEY>"

任務列表支持与 usage/summary 相同的篩選参数。为了保证查詢稳定,日期範圍限制为 7 天。

每条任務記錄包含:

FieldDescription
task_idInternal task ID
created_at, completed_atTask timestamps
model, task_typeModel and workload type
apikey_id, apikey_nameAPI key attribution
provider_job_idUpstream provider job ID when available
status, finance_statusExecution and billing state
token fieldsInput, output, cache, reasoning, image, audio, and video token usage
total_amount, actual_creditsUSD amount string and internal credit amount

9. 任務详情

curl -sS "https://reachapi.ai/api/open/v1/usage/tasks/task_123" \
  -H "Authorization: Bearer <REPORTING_ACCESS_KEY>"

任務详情接口返回单个任務的金额、Token 和错误信息,适合核对某个客戶工单、provider job 或账单明细。

10. 錯誤碼

HTTP statusmsg exampleScenario
401UnauthorizedMissing, malformed, invalid, or revoked Reporting Access Key
400Invalid paginationpage or page_size is not a positive integer
400Invalid start_date / Invalid end_dateDate format is not YYYY-MM-DD
400Date range is too largeDate range exceeds the endpoint limit
400Invalid group_byUnsupported daily grouping value
403ForbiddenThe requested apikey_id is not visible to this Reporting Access Key
404Task not foundTask does not exist or is not visible

11. 使用日誌

客戶使用 Reporting Access Key 调用 Open API 时,服务端会写入独立的 accesskey 使用日誌。

日誌用于运维排查和用量审计,只記錄脫敏后的請求元信息,例如 event、request ID、key prefix、user ID、method、path、安全 query、status code、duration、IP、user agent 和 error code。

日誌不会記錄完整 access key、Authorization header、cookie、password、key hash、ciphertext 或數據庫连接串。

On this page