Chuyển đến nội dung chính

Tổng quan

Endpoint này trả về chi tiết mức sử dụng theo API key mà không làm lộ chi tiết thực thi của provider.

Tham số query

Tham sốKiểuMặc định / giới hạnMô tả
pageintegermặc định 1, tối thiểu 1Số trang bắt đầu từ 1
limitintegermặc định 50, tối thiểu 1, tối đa 100Kích thước mỗi trang
modelstringđộ dài tối đa 100Tên model được yêu cầu
modelVendorstringđộ dài tối đa 100Nhà cung cấp model công khai
sceneenum-chat, image, audio, video, embedding, rerank, translation, music, 3d, realtime
accessChannelenum-platform hoặc byok
startDatestring-Cận dưới bao gồm; chấp nhận RFC3339 có múi giờ hoặc YYYY-MM-DD
endDatestring-Cận trên bao gồm; chấp nhận RFC3339 có múi giờ hoặc YYYY-MM-DD
Nếu truyền đồng thời startDateendDate, thì startDate phải nhỏ hơn hoặc bằng endDate.

Lưu ý

  • Phản hồi có phân trang.
  • Phản hồi chỉ bao gồm các trường chi phí và báo cáo công khai.
  • Mỗi dòng usage cũng có thể bao gồm billing_transaction_id sau khi request gốc đã được settlement xong. Hãy dùng giá trị này cùng với request_id để đối soát ở cấp request.
  • Metadata routing nội bộ và kênh vật lý sẽ tiếp tục bị ẩn.

Ví dụ

curl "https://api.tokenlab.sh/v1/management/api-keys/key_abc123def456/usage?page=1&limit=20&scene=video&accessChannel=platform&startDate=2026-03-01&endDate=2026-03-31" \
  -H "Authorization: Bearer mt-your-management-token"

Yêu cầu / Phản hồi

Hãy dùng bảng OpenAPI tương tác phía trên để xem schema chính xác và các trường phản hồi.

Response example

{
  "api_key": {
    "id": "key_abc123def456",
    "name": "Backend Worker",
    "key_prefix": "sk-live...",
    "status": "active",
    "limit_amount": 500,
    "limit_amount_decimal": "500",
    "used_amount": 148.25,
    "used_amount_decimal": "148.25",
    "models": [
      "gpt-5-mini",
      "claude-3-7-sonnet"
    ],
    "expires_at": "2026-12-31T23:59:59.000Z",
    "last_used_at": "2026-07-08T03:12:45.000Z",
    "created_at": "2026-07-01T10:00:00.000Z"
  },
  "items": [
    {
      "request_id": "req_abc123",
      "billing_transaction_id": "billtxn_abc123",
      "model": "gpt-5-mini",
      "logical_model": "gpt-5-mini",
      "model_vendor": "OpenAI",
      "scene": "chat",
      "access_channel": "platform",
      "usage_unit": "per_token",
      "usage_quantity": 1500,
      "usage_quantity_decimal": "1500",
      "prompt_tokens": 1000,
      "completion_tokens": 500,
      "total_tokens": 1500,
      "cache_read_tokens": 0,
      "cache_write_tokens": 0,
      "cache_write_tokens_5m": 0,
      "cache_write_tokens_1h": 0,
      "cost": 0.0012,
      "cost_decimal": "0.0012",
      "created_at": "2026-07-08T03:15:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 1,
    "totalPages": 1
  },
  "summary": {
    "total_requests": 1,
    "total_cost": 0.0012,
    "total_cost_decimal": "0.0012",
    "total_prompt_tokens": 1000,
    "total_completion_tokens": 500,
    "total_tokens": 1500,
    "usage_unit_breakdown": [
      {
        "usage_unit": "per_token",
        "usage_quantity": 1500
      }
    ]
  },
  "breakdowns": {
    "by_model": [
      {
        "model": "gpt-5-mini",
        "logical_model": "gpt-5-mini",
        "model_vendor": "OpenAI",
        "requests": 1,
        "cost": 0.0012,
        "cost_decimal": "0.0012",
        "usage_quantity": 1500,
        "usage_quantity_decimal": "1500"
      }
    ],
    "by_logical_model": [
      {
        "model": "gpt-5-mini",
        "logical_model": "gpt-5-mini",
        "model_vendor": "OpenAI",
        "requests": 1,
        "cost": 0.0012,
        "cost_decimal": "0.0012",
        "usage_quantity": 1500,
        "usage_quantity_decimal": "1500"
      }
    ],
    "by_model_vendor": [
      {
        "model_vendor": "OpenAI",
        "requests": 1,
        "cost": 0.0012
      }
    ],
    "by_scene": [
      {
        "scene": "chat",
        "requests": 1,
        "cost": 0.0012,
        "cost_decimal": "0.0012"
      }
    ],
    "by_access_channel": [
      {
        "access_channel": "platform",
        "requests": 1,
        "cost": 0.0012
      }
    ],
    "daily_cost": [
      {
        "date": "2026-07-08T00:00:00.000Z",
        "cost": 0.0012,
        "cost_decimal": "0.0012"
      }
    ]
  }
}

Important fields

api_key
object
API key summary using the same fields as list/create/update responses.
items
array
Paginated usage rows.
pagination
object
Pagination metadata with page, limit, total, and totalPages.
summary
object
Aggregated totals for the selected filters.
breakdowns
object
Aggregated breakdowns for the selected filters.
items[].request_id
string | null
Public request identifier for support and reconciliation.
items[].billing_transaction_id
string | null
Settled billing transaction id when available.
items[].model
string
Requested public model name.
items[].logical_model
string
Logical public model used for reporting.
items[].model_vendor
string | null
Public model vendor.
items[].scene
string | null
Public request scene.
items[].access_channel
string
platform or byok.
items[].usage_unit
string
Billing usage unit, such as per_token.
items[].usage_quantity
number
Usage quantity as a JSON number for display.
items[].usage_quantity_decimal
string
Exact usage quantity as a decimal string.
items[].prompt_tokens
number
Prompt token count.
items[].completion_tokens
number
Completion token count.
items[].total_tokens
number
Total token count.
items[].cache_read_tokens
number
Cache read token count.
items[].cache_write_tokens
number
Total cache write token count.
items[].cache_write_tokens_5m
number
Five-minute cache write token count.
items[].cache_write_tokens_1h
number
One-hour cache write token count.
items[].cost
number
Cost in USD as a JSON number for display.
items[].cost_decimal
string
Exact cost in USD as a decimal string.
items[].created_at
string
ISO usage row timestamp.
summary.total_requests
number
Total request count.
summary.total_cost
number
Total cost in USD as a JSON number for display.
summary.total_cost_decimal
string
Exact total cost in USD as a decimal string.
summary.total_prompt_tokens
number
Total prompt tokens.
summary.total_completion_tokens
number
Total completion tokens.
summary.total_tokens
number
Total tokens.
summary.usage_unit_breakdown
array
Usage quantity grouped by usage unit.
breakdowns.by_model
array
Breakdown by requested public model.
breakdowns.by_logical_model
array
Breakdown by logical public model.
breakdowns.by_model_vendor
array
Breakdown by public model vendor.
breakdowns.by_scene
array
Breakdown by public request scene.
breakdowns.by_access_channel
array
Breakdown by platform or byok access channel.
breakdowns.daily_cost
array
Daily cost trend.