> ## Documentation Index
> Fetch the complete documentation index at: https://docs.grantex.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage Metering

> Track and monitor API usage across your Grantex deployment

## Overview

Grantex tracks API usage in real-time using Redis counters with periodic PostgreSQL rollup. Monitor token exchanges, authorizations, and verifications per developer.

## Enabling Usage Metering

Set the environment variable:

```bash theme={null}
USAGE_METERING_ENABLED=true
```

## API Endpoints

### Current Period Usage

```bash theme={null}
curl https://api.grantex.dev/v1/usage \
  -H "Authorization: Bearer $GRANTEX_KEY"
```

Response:

```json theme={null}
{
  "developerId": "dev_...",
  "period": "2026-03-02",
  "tokenExchanges": 42,
  "authorizations": 18,
  "verifications": 7,
  "totalRequests": 67
}
```

### Usage History

```bash theme={null}
curl "https://api.grantex.dev/v1/usage/history?days=30" \
  -H "Authorization: Bearer $GRANTEX_KEY"
```

## SDK Usage

```typescript theme={null}
// TypeScript
const usage = await grantex.usage.current();
console.log(`Today: ${usage.totalRequests} requests`);

const history = await grantex.usage.history({ days: 7 });
for (const day of history.entries) {
  console.log(`${day.date}: ${day.totalRequests}`);
}
```

```python theme={null}
# Python
usage = grantex.usage.current()
print(f"Today: {usage.total_requests} requests")

history = grantex.usage.history(days=7)
for day in history.entries:
    print(f"{day.date}: {day.total_requests}")
```

## Plan Limits

| Metric                | Free   | Pro       | Enterprise |
| --------------------- | ------ | --------- | ---------- |
| Agents                | 500    | 5,000     | Unlimited  |
| Grants                | 1,000  | 50,000    | Unlimited  |
| Policies              | 50     | 500       | Unlimited  |
| Audit entries         | 20,000 | 1,000,000 | Unlimited  |
| Token exchanges/month | 50,000 | 5,000,000 | Unlimited  |
| Authorizations/month  | 50,000 | 5,000,000 | Unlimited  |
| Webhooks              | 30     | 200       | Unlimited  |
