Usage Tracking API

Track LLM usage with automatic cost calculation based on current model pricing.

About Usage Tracking

Track LLM usage with automatic cost calculation based on current model pricing. Usage can be tied to customer transactions or tracked as internal system usage.

POST/v1/usage/record
Record LLM usage for a specific account or system usage. Include accountId for customer usage or set context to 'system'.

Record account usage

curl -X POST "https://api.credits.dev/v1/usage/record" \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "accountId": "acc_123", "transactionId": "txn_xyz789", "modelId": "gpt-4o", "usageType": "text", "inputTokens": 1500, "outputTokens": 500, "cachedTokens": 200 }'

Request Body

{
  "accountId": "acc_123",
  "transactionId": "txn_xyz789",
  "modelId": "gpt-4o",
  "usageType": "text",
  "inputTokens": 1500,
  "outputTokens": 500,
  "cachedTokens": 200
}

Response

{
  "success": true,
  "usageRecord": {
    "id": "usage_abc123",
    "accountId": "acc_123",
    "modelId": "gpt-4o",
    "estimatedCostUsd": 0.0425
  }
}
GET/v1/usage
Get usage records with optional filters by accountId, modelId, or context.

Get usage records

curl -X GET "https://api.credits.dev/v1/usage?accountId=acc_123&modelId=gpt-4o" \ -H "X-API-Key: YOUR_API_KEY"

Response

{
  "success": true,
  "usageRecords": [
    {
      "id": "usage_abc123",
      "context": "customer",
      "accountId": "acc_123",
      "modelId": "gpt-4o",
      "inputTokens": 1500,
      "outputTokens": 500,
      "estimatedCostUsd": 0.0425,
      "createdAt": "2024-01-15T10:00:00Z"
    }
  ]
}
GET/v1/usage?summary=true
Get aggregated usage summary by model and context.

Get usage summary

curl -X GET "https://api.credits.dev/v1/usage?summary=true&context=customer" \ -H "X-API-Key: YOUR_API_KEY"

Response

{
  "success": true,
  "summary": {
    "totalCostUsd": 12.45,
    "totalInputTokens": 1250000,
    "totalOutputTokens": 450000,
    "byContext": {
      "customer": 11.20,
      "system": 1.25
    },
    "byModel": {
      "gpt-4o": { "costUsd": 8.50, "count": 120 },
      "gpt-4o-mini": { "costUsd": 3.95, "count": 850 }
    }
  }
}