Get token usage
Endpoint
GET
/v1/usageReturns aggregated token usage for the authenticated API key over a time range.
Request
Authenticate with Authorization: Bearer sk-moyiapi-xxxxxx.
Parameters
| Parameter | In | Type | Required | Notes |
|---|---|---|---|---|
start_time |
query | integer | Yes | Start time (Unix seconds), inclusive |
end_time |
query | integer | Yes | End time (Unix seconds), exclusive |
The range may span at most 90 days; longer ranges return 400 invalid_request.
Response
{
"start_time": 1784044800,
"end_time": 1784131200,
"usage": {
"input_tokens": 120000,
"output_tokens": 30000,
"cached_write_tokens": 10000,
"cached_read_tokens": 80000,
"total_tokens": 240000
},
"requests": 86
}
| Field | Notes |
|---|---|
usage.input_tokens |
Input tokens that missed the cache |
usage.output_tokens |
Output tokens generated |
usage.cached_write_tokens |
Tokens written to the prompt cache |
usage.cached_read_tokens |
Tokens read from the prompt cache |
usage.total_tokens |
Sum of the above |
requests |
Number of requests in the range |
When reconciling, use the same start_time and end_time as Get cost summary.
Examples
curl "https://moyiapi.com/v1/usage?start_time=1784044800&end_time=1784131200" \
-H "Authorization: Bearer sk-moyiapi-xxxxxx"
Errors
| HTTP status | error.code |
When it happens |
|---|---|---|
| 400 | invalid_request |
Invalid parameters, such as end_time not after start_time or a range over 90 days |