Skip to main content
Activity logs provide detailed usage statistics and analytics for your LLM Gateway usage. Query by date range, project, or API key.

Get Activity Data

Retrieve aggregated activity statistics grouped by day.
days
number
Number of days to retrieve (overridden if from and to are specified)
from
string
Start date in YYYY-MM-DD format (inclusive)
to
string
End date in YYYY-MM-DD format (inclusive)
projectId
string
Filter by specific project ID
apiKeyId
string
Filter by specific API key ID
activity
array
Array of daily activity objects
curl "https://api.llmgateway.io/activity?days=7" \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"
{
  "activity": [
    {
      "date": "2024-01-15",
      "requestCount": 1250,
      "inputTokens": 125000,
      "outputTokens": 75000,
      "cachedTokens": 25000,
      "totalTokens": 200000,
      "cost": 4.85,
      "inputCost": 1.25,
      "outputCost": 3.50,
      "requestCost": 0.05,
      "dataStorageCost": 0.05,
      "imageInputCost": 0,
      "imageOutputCost": 0,
      "cachedInputCost": 0,
      "errorCount": 12,
      "errorRate": 0.96,
      "cacheCount": 50,
      "cacheRate": 4.0,
      "discountSavings": 0.50,
      "creditsRequestCount": 500,
      "apiKeysRequestCount": 750,
      "creditsCost": 2.00,
      "apiKeysCost": 2.85,
      "creditsDataStorageCost": 0.02,
      "apiKeysDataStorageCost": 0.03,
      "modelBreakdown": [
        {
          "id": "gpt-4o",
          "provider": "openai",
          "requestCount": 500,
          "inputTokens": 50000,
          "outputTokens": 30000,
          "totalTokens": 80000,
          "cost": 2.00
        },
        {
          "id": "claude-3-5-sonnet-20241022",
          "provider": "anthropic",
          "requestCount": 400,
          "inputTokens": 40000,
          "outputTokens": 25000,
          "totalTokens": 65000,
          "cost": 1.95
        },
        {
          "id": "gpt-4o-mini",
          "provider": "openai",
          "requestCount": 350,
          "inputTokens": 35000,
          "outputTokens": 20000,
          "totalTokens": 55000,
          "cost": 0.90
        }
      ]
    },
    {
      "date": "2024-01-14",
      "requestCount": 1100,
      "inputTokens": 110000,
      "outputTokens": 66000,
      "cachedTokens": 22000,
      "totalTokens": 176000,
      "cost": 4.25,
      "inputCost": 1.10,
      "outputCost": 3.08,
      "requestCost": 0.04,
      "dataStorageCost": 0.03,
      "imageInputCost": 0,
      "imageOutputCost": 0,
      "cachedInputCost": 0,
      "errorCount": 8,
      "errorRate": 0.73,
      "cacheCount": 45,
      "cacheRate": 4.09,
      "discountSavings": 0.45,
      "creditsRequestCount": 440,
      "apiKeysRequestCount": 660,
      "creditsCost": 1.70,
      "apiKeysCost": 2.55,
      "creditsDataStorageCost": 0.01,
      "apiKeysDataStorageCost": 0.02,
      "modelBreakdown": [
        {
          "id": "gpt-4o",
          "provider": "openai",
          "requestCount": 450,
          "inputTokens": 45000,
          "outputTokens": 27000,
          "totalTokens": 72000,
          "cost": 1.80
        },
        {
          "id": "claude-3-5-sonnet-20241022",
          "provider": "anthropic",
          "requestCount": 380,
          "inputTokens": 38000,
          "outputTokens": 23000,
          "totalTokens": 61000,
          "cost": 1.83
        },
        {
          "id": "gpt-4o-mini",
          "provider": "openai",
          "requestCount": 270,
          "inputTokens": 27000,
          "outputTokens": 16000,
          "totalTokens": 43000,
          "cost": 0.62
        }
      ]
    }
  ]
}

Understanding Costs

Cost Breakdown

Total cost includes:
  1. Input Cost: Tokens sent to the model
  2. Output Cost: Tokens generated by the model
  3. Request Cost: Per-request fees (some providers)
  4. Data Storage Cost: Log retention charges
  5. Image Costs: Vision model image processing
  6. Cached Input Cost: Cached prompt tokens (some providers)

Credits vs Provider Keys

The API tracks costs separately based on how requests were processed:
  • Credits Cost: Requests routed through Gateway-managed providers
  • API Keys Cost: Requests using your configured provider keys
This helps you understand:
  • How much you’re spending on credits
  • How much you’re saving by using your own keys
  • Which mode (hybrid, credits, api-keys) is most cost-effective

Discounts

Discounts can be applied at the:
  • Global level: All users for a specific provider/model
  • Organization level: Your organization for specific providers/models
The discountSavings field shows how much you saved from applied discounts.

Model Breakdown

The modelBreakdown array provides per-model statistics:
{
  "id": "gpt-4o",
  "provider": "openai",
  "requestCount": 500,
  "inputTokens": 50000,
  "outputTokens": 30000,
  "totalTokens": 80000,
  "cost": 2.00
}
Use this to:
  • Identify your most-used models
  • Compare costs across providers
  • Optimize model selection for cost
  • Track usage patterns

Performance Metrics

Error Rate

errorRate = (errorCount / requestCount) * 100
A high error rate may indicate:
  • Provider API issues
  • Invalid requests
  • Rate limiting
  • Authentication problems

Cache Hit Rate

cacheRate = (cacheCount / requestCount) * 100
A higher cache rate means:
  • Lower costs (cached responses are free)
  • Faster response times
  • Reduced provider API load
Enable caching on your projects to improve cache hit rates and reduce costs.

Filtering Examples

By Project

Track usage for a specific project:
curl "https://api.llmgateway.io/activity?projectId=proj_xyz789&days=30" \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"

By API Key

Monitor a specific API key’s usage:
curl "https://api.llmgateway.io/activity?apiKeyId=key_xyz789&from=2024-01-01&to=2024-01-31" \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"

Custom Date Range

Query activity for a specific time period:
curl "https://api.llmgateway.io/activity?from=2024-01-01&to=2024-01-15" \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"

Data Retention

Activity data is retained based on your organization’s plan:
PlanRetention Period
Free3 days
Pro90 days
EnterpriseCustom (up to 1 year)
Upgrade to Pro or Enterprise for extended data retention and historical analytics.

Error Responses

{
  "message": "Unauthorized"
}

Best Practices

Monitor Regularly
  • Check activity daily to catch anomalies
  • Set up alerts for unusual spending
  • Review error rates weekly
Optimize Costs
  • Analyze model breakdown to find expensive models
  • Enable caching for repetitive requests
  • Use cheaper models where appropriate
  • Leverage discounts when available
Track Performance
  • Monitor error rates over time
  • Compare cache hit rates across projects
  • Identify slow or unreliable providers

Build docs developers (and LLMs) love