Skip to content

Usage Log Query

Query usage logs for a specific Token using the API Key directly — no login required. Useful for usage analysis, cost accounting, and reconciliation.

Endpoint

http
GET /api/log/token

Request Parameters

ParameterTypeRequiredDescription
keystringYesAPI Key, e.g. sk-xxx
pintYesPage number, starting from 1
page_sizeintYesItems per page, max 100
start_timestampint64YesStart time (Unix seconds)
end_timestampint64YesEnd time (Unix seconds)
typeintNoLog type: 0 all, 1 topup, 2 consume, 5 error, 6 refund
model_namestringNoModel name (fuzzy match)

Example

bash
# Query consumption logs from the last 7 days, page 1, 20 items per page
curl "https://api.ezmodel.cloud/api/log/token?\
key=sk-your-api-key&\
p=1&\
page_size=20&\
type=2&\
start_timestamp=1710000000&\
end_timestamp=1710604800"
python
import requests
import time

base_url = "https://api.ezmodel.cloud/"
now = int(time.time())
week_ago = now - 7 * 86400

resp = requests.get(f"{base_url}/api/log/token", params={
    "key": "sk-your-api-key",
    "p": 1,
    "page_size": 20,
    "type": 2,  # consumption logs
    "start_timestamp": week_ago,
    "end_timestamp": now,
})
data = resp.json()
print(f"Total: {data['data']['total']} logs")
for log in data["data"]["items"]:
    print(f"  {log['model_name']}: {log['prompt_tokens']}+{log['completion_tokens']} tokens")

Response Format

json
{
  "success": true,
  "message": "",
  "data": {
    "page": 1,
    "page_size": 20,
    "total": 156,
    "items": [
      {
        "id": 42,
        "created_at": 1710500000,
        "type": 2,
        "username": "your_username",
        "token_name": "my-token",
        "model_name": "gpt-4o",
        "quota": 5000,
        "prompt_tokens": 1200,
        "completion_tokens": 800,
        "use_time": 3,
        "is_stream": true,
        "group": "default",
        "other": "{\"model_ratio\":1.5,\"request_path\":\"/v1/chat/completions\"}"
      }
    ]
  }
}

Response Fields

FieldTypeDescription
idintLog ID
created_atint64Creation time (Unix seconds)
typeintLog type
token_namestringToken name
model_namestringModel name
quotaintQuota consumed
prompt_tokensintInput token count
completion_tokensintOutput token count
use_timeintRequest duration (seconds)
is_streamboolWhether streaming was used
groupstringUser group
otherstringExtended info (JSON string with pricing ratios, cache details, etc.)

Error Handling

Error MessageCauseSolution
key is requiredAPI Key not providedPass the full API Key in the key parameter
record not foundInvalid or non-existent API KeyVerify the Key is correct
start_timestamp and end_timestamp are requiredMissing time rangeAdd both timestamp parameters
p and page_size are requiredMissing pagination parametersAdd p and page_size parameters

Best Practices

Performance Tips

  1. Use a reasonable time range — narrower ranges yield faster queries
  2. Use reasonable page sizes — 20-50 recommended, max 100
  3. Filter by model if you only need usage for specific models
  4. Paginate through all data — increment p until items is empty or page * page_size >= total

Next Steps

企业合作联系:service@ezmodel.cloud