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

Typically 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

Retrieve all usage logs (supports pagination).

πŸ” Auth Required: βœ… Yes Supports query params: skip, limit

βœ… cURL:


πŸ”Έ GET /usage/user/{user_id} – Get Logs by User

Retrieve usage logs specific to a user.

πŸ” Auth Required: βœ… Yes (Admin or Self)

βœ… cURL:


πŸ”Έ GET /usage/{usage_id} – Get Usage Entry by ID

Returns details for a specific usage record.

βœ… cURL:


πŸ”Έ PUT /usage/{usage_id} – Update Usage Record

Used to mark as refunded or adjust billing values.

πŸ“₯ Request:

βœ… cURL:


πŸ”Έ DELETE /usage/{usage_id} – Delete Usage Record

Deletes a log entry. Recommended for admin use only.

βœ… cURL:


Last updated