Get API Call Records
API call records (API Usage) provide detailed information about each API call, including the call time, status code, consumed quota, trace ID, etc. Through this interface, you can query historical call records for auditing, debugging, and cost analysis.
This interface requires authentication, for details please refer to Platform Token.
¶ Interface Description
- Request Method: GET
- Request URL:
https://platform.acedata.cloud/api/v1/usage/apis/ - Request Headers:
- accept:
application/json - authorization:
Bearer {token}
- accept:
¶ Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
application_id |
string | No | Filter by application ID |
api_id |
string | No | Filter by API ID, supports multiple: ?api_id=xxx&api_id=yyy |
created_at_from |
string | No | Start time of creation (ISO 8601 format) |
created_at_to |
string | No | End time of creation (ISO 8601 format) |
limit |
integer | No | Number of results per page |
offset |
integer | No | Offset |
¶ CURL Request Example
Query all call records:
curl -X GET \
-H "accept: application/json" \
-H "authorization: Bearer {token}" \
"https://platform.acedata.cloud/api/v1/usage/apis/"
Filter by application and time range:
curl -X GET \
-H "accept: application/json" \
-H "authorization: Bearer {token}" \
"https://platform.acedata.cloud/api/v1/usage/apis/?application_id=107f8d0f-e465-4a7e-a49e-d633d26f7aa2&created_at_from=2024-08-01T00:00:00Z"
¶ Return Result Example
{
"count": 100,
"results": [
{
"id": "usage-uuid",
"user_id": "b87f67c1-b04f-4332-99a1-7a5e651331c6",
"application_id": "107f8d0f-e465-4a7e-a49e-d633d26f7aa2",
"api_id": "api-uuid",
"status_code": 200,
"remaining_amount": 490.0,
"used_amount": 4.95,
"deducted_amount": 4.95,
"trace_id": "abc123def456",
"api": {
"id": "api-uuid",
"name": "Midjourney Imagine",
"path": "/v1/midjourney/imagine"
},
"service": {
"id": "service-uuid",
"alias": "midjourney",
"name": "Midjourney"
},
"metadata": {
"prompt": "a beautiful sunset"
},
"created_at": "2024-08-16T07:51:15.603207Z",
"updated_at": "2024-08-16T07:51:15.603207Z"
}
]
}
¶ Return Field Description
| Field | Type | Description |
|---|---|---|
id |
string | Unique identifier for the record |
user_id |
string | User ID |
application_id |
string | Application ID |
api_id |
string | Called API ID |
status_code |
integer | HTTP response status code |
remaining_amount |
number | Remaining quota after the call |
used_amount |
number | Quota consumed in this call |
deducted_amount |
number | Actual deducted amount (may vary due to discounts) |
trace_id |
string | Trace ID for debugging and issue resolution |
api |
object | API information |
service |
object | Service information |
metadata |
object | Request metadata |
¶ Code Example
Python:
import requests
url = "https://platform.acedata.cloud/api/v1/usage/apis/"
headers = {
"accept": "application/json",
"authorization": "Bearer {token}"
}
params = {
"application_id": "107f8d0f-e465-4a7e-a49e-d633d26f7aa2",
"limit": 20
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
total_cost = 0
for usage in data["results"]:
total_cost += usage["deducted_amount"]
print(f"API: {usage['api']['name']} | Status Code: {usage['status_code']} | Consumed: {usage['deducted_amount']}")
print(f"\nTotal Consumption: {total_cost}")
