API Usage Tracking
These endpoints allow you to monitor, analyze, and manage API consumption on a per-user basis. Each request to endpoints like /chat, /audio-chat, or /tts is automatically logged here.
π Most endpoints require user or admin authentication. Some require admin-only access.
πΈ POST /usage β Manually Log Usage
POST /usage β Manually Log UsageTypically handled automatically, but can be used manually (e.g., for testing or internal operations).
π₯ Request Body:
{
"api_name": "llm_query",
"endpoint": "/chat",
"units_used": 346,
"cost_usd": 0.0043,
"api_key_used": "pk_live_abc123"
}π Auth Required: β Yes
π€ Response:
{
"usage_id": "uuid",
"user_id": "uuid",
"api_name": "llm_query",
"endpoint": "/chat",
"units_used": 346,
"cost_usd": 0.0043,
"api_key_used": "pk_live_abc123",
"status_active": true,
"created_at": "2025-07-04T12:00:00Z"
}β cURL Example:
β JavaScript (fetch):
πΈ GET /usage β Get All Usage Logs
GET /usage β Get All Usage LogsRetrieve all usage logs (supports pagination).
π Auth Required: β
Yes
Supports query params: skip, limit
β cURL:
πΈ GET /usage/user/{user_id} β Get Logs by User
GET /usage/user/{user_id} β Get Logs by UserRetrieve usage logs specific to a user.
π Auth Required: β Yes (Admin or Self)
β cURL:
πΈ GET /usage/{usage_id} β Get Usage Entry by ID
GET /usage/{usage_id} β Get Usage Entry by IDReturns details for a specific usage record.
β cURL:
πΈ PUT /usage/{usage_id} β Update Usage Record
PUT /usage/{usage_id} β Update Usage RecordUsed to mark as refunded or adjust billing values.
π₯ Request:
β cURL:
πΈ DELETE /usage/{usage_id} β Delete Usage Record
DELETE /usage/{usage_id} β Delete Usage RecordDeletes a log entry. Recommended for admin use only.
β cURL:
Last updated