III. Logs & Statistics
The APIs in this chapter let you query your call records and consumption.
Conventions:
•Timestamps are second-level Unix timestamps. Pass
0 or omit the parameter to apply no filter on that end.•Quota unit:
1 USD = 500,000 quota by default.•The log type
type is used as the type parameter of the log query APIs:| Value | Meaning | Notes |
|---|---|---|
| 0 | All | No type filter; default |
| 1 | Top-up | Account top-up events |
| 2 | Consumption | API call charges |
| 3 | Management | System adjustments |
| 4 | System | System events |
| 5 | Error | Failed calls |
| 6 | Refund | Automatic refunds in some scenarios |
1. View your usage logs
Query your call details with pagination. You can filter by time range, token, model, and more.
Request
•Method:
GET•Path:
/api/log/selfQuery parameters (all optional):
| Parameter | Type | Default | Notes |
|---|---|---|---|
p |
int | 1 | Page number |
page_size |
int | 20 | Items per page, max 100 |
type |
int | 0 | Log type; 0 means all |
start_timestamp |
int | 0 | Start timestamp (seconds); 0 means no limit |
end_timestamp |
int | 0 | End timestamp (seconds); 0 means no limit |
token_name |
string | — | Exact match on token name |
model_name |
string | — | Filter by model name |
group |
string | — | Filter by group |
request_id |
string | — | Exact match on request ID (for troubleshooting) |
Response
upstream_request_id uses omitempty: if the upstream does not return a request ID, the field is omitted from the JSON; it is returned only when it has a value.{
"success": true,
"message": "",
"data": {
"page": 1,
"page_size": 20,
"total": 528,
"items": [
{
"id": 8890,
"user_id": 12345,
"created_at": 1783656777,
"type": 2,
"content": "",
"username": "example_user",
"token_name": "my-key",
"model_name": "claude-sonnet-4-6",
"quota": 169893,
"prompt_tokens": 3734,
"completion_tokens": 0,
"use_time": 12,
"is_stream": false,
"channel": 12,
"channel_name": "",
"token_id": 1001,
"group": "default",
"ip": "203.0.113.42",
"request_id": "202607290628491263137328268d9d6P1Td6Ml2",
"other": ""
}
]
}
}
Log entry fields:
| Field | Type | Notes |
|---|---|---|
id |
int | Log ID |
user_id |
int | User ID |
created_at |
int | Record time (second-level Unix timestamp) |
type |
int | Log type (see the table above) |
content |
string | Event description; usually empty for consumption logs |
username |
string | Username |
token_name |
string | Name of the token that made the call |
model_name |
string | Name of the model called |
quota |
int | Quota consumed by this request (quota unit); USD equivalent = quota / 500000 (default ratio; see the console for details) |
prompt_tokens |
int | Input tokens |
completion_tokens |
int | Output tokens |
use_time |
int | Request duration (seconds) |
is_stream |
boolean | Whether the response is streamed |
channel |
int | Upstream channel ID |
channel_name |
string | Upstream channel name |
token_id |
int | Token ID |
group |
string | Effective group |
ip |
string | Source IP of the request |
request_id |
string | Unique ID of this request, useful for troubleshooting |
upstream_request_id |
string | Request ID returned by the upstream provider (if any) |
other |
string | Additional information (a JSON string or empty). Common in consumption logs; includes billing details, streaming status, and more. You need to parse it yourself |
Examples
Query all consumption records from the last week:
END=$(date +%s)
START=$((END - 7*86400))
curl -sS "https://ailink.nativex.com/api/log/self?type=2&start_timestamp=$START&end_timestamp=$END&p=1&page_size=50" \
-H "Authorization: Bearer <your-system-access-token>"
Query all calls made with a given token:
curl -sS "https://ailink.nativex.com/api/log/self?token_name=my-key&p=1&page_size=50" \
-H "Authorization: Bearer <your-system-access-token>"
Locate a single call by request_id (common for troubleshooting):
•If you omit
start_timestamp and end_timestamp, all historical logs are returned (subject to pagination limits).•For long-term consumption analysis, we recommend fetching all pages and then aggregating on the client (by model, by token, and so on).
•The maximum
page_size per request is 100; larger values are truncated.curl -sS "https://ailink.nativex.com/api/log/self?request_id=xxxxxxxx-xxxx-xxxx" \
-H "Authorization: Bearer <your-system-access-token>"
Notes
2. Personal log statistics
Aggregates logs that match the given conditions and returns the total consumption and the current RPM/TPM.
Request
•Method:
GET•Path:
/api/log/self/statQuery parameters (all optional):
| Parameter | Type | Default | Notes |
|---|---|---|---|
type |
int | 0 | Log type |
start_timestamp |
int | 0 | Start timestamp (seconds) |
end_timestamp |
int | 0 | End timestamp (seconds) |
token_name |
string | — | Filter by token name |
model_name |
string | — | Filter by model name |
channel |
int | 0 | Filter by channel ID |
group |
string | — | Filter by group |
Response
{
"success": true,
"message": "",
"data": {
"quota": 6535469,
"rpm": 0,
"tpm": 0
}
}
Field descriptions:
| Field | Type | Notes |
|---|---|---|
quota |
int | Total quota consumed in the time range (quota unit); USD equivalent = quota / 500000 (default ratio; see the console for details) |
rpm |
int | Current request rate (requests per minute); a real-time approximation |
tpm |
int | Current token rate (tokens per minute); a real-time approximation |
Examples
Total consumption over all time:
curl -sS "https://ailink.nativex.com/api/log/self/stat?type=0" \
-H "Authorization: Bearer <your-system-access-token>"
Consumption of a given model over the last 30 days:
END=$(date +%s)
START=$((END - 30*86400))
curl -sS "https://ailink.nativex.com/api/log/self/stat?type=2&start_timestamp=$START&end_timestamp=$END&model_name=claude-sonnet-4-6" \
-H "Authorization: Bearer <your-system-access-token>"
Consumption of a given token:
curl -sS "https://ailink.nativex.com/api/log/self/stat?token_name=my-key" \
-H "Authorization: Bearer <your-system-access-token>"
Notes
•This API returns only aggregated values. For a detailed report grouped by model or token, fetch the usage logs API page by page and aggregate on the client.
•
rpm / tpm are real-time estimates over a recent period. They are 0 after a long period without calls and do not represent the average over the whole time range.•Response time increases significantly for large time spans, so set a reasonable time window.