aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/analytics.mdx
blob: 34df64b4e7e2f6788d93213a6a7704b556a22fa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
---
title: "Analytics & Monitoring"
description: "Observe usage, errors, and logs to monitor your Supermemory integration"
icon: "chart-line"
---

Monitor your Supermemory usage with detailed analytics on API calls, errors, and performance metrics.

## Overview

The Analytics API provides comprehensive insights into your Supermemory usage:

- **Usage Statistics**: Track API calls by type, hourly trends, and per-API key breakdown
- **Error Monitoring**: Identify top error types and patterns
- **Detailed Logs**: Access complete request/response logs for debugging
- **Performance Metrics**: Monitor average response times and processing duration

<Note>
Analytics data is available for your entire organization and can be filtered by time period.
</Note>

## Usage Statistics

Get comprehensive usage statistics including hourly breakdowns and per-key metrics.

### Endpoint

`GET /v3/analytics/usage`

### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `from` | string (ISO 8601) | Start date/time for the period |
| `to` | string (ISO 8601) | End date/time for the period |
| `period` | string | Alternative to `from`: `1h`, `24h`, `7d`, `30d` |
| `page` | integer | Page number for pagination (default: 1) |
| `limit` | integer | Items per page (default: 20, max: 100) |

### Example Request

<CodeGroup>

```typescript TypeScript
// Get usage for the last 24 hours
const usage = await fetch('https://api.supermemory.ai/v3/analytics/usage?period=24h', {
  headers: {
    'Authorization': `Bearer ${SUPERMEMORY_API_KEY}`
  }
});

const data = await usage.json();
```

```python Python
import requests
from datetime import datetime, timedelta

# Get usage for the last 7 days
response = requests.get(
    'https://api.supermemory.ai/v3/analytics/usage',
    params={'period': '7d'},
    headers={'Authorization': f'Bearer {SUPERMEMORY_API_KEY}'}
)

data = response.json()
```

```bash cURL
# Get usage for a specific date range
curl -X GET "https://api.supermemory.ai/v3/analytics/usage?from=2024-01-01T00:00:00Z&to=2024-01-31T23:59:59Z" \
  -H "Authorization: Bearer $SUPERMEMORY_API_KEY"
```

</CodeGroup>

### Response Schema

```json
{
  "usage": [
    {
      "type": "add",
      "count": 1523,
      "avgDuration": 245.5,
      "lastUsed": "2024-01-15T14:30:00Z"
    },
    {
      "type": "search",
      "count": 3421,
      "avgDuration": 89.2,
      "lastUsed": "2024-01-15T14:35:00Z"
    }
  ],
  "hourly": [
    {
      "hour": "2024-01-15T14:00:00Z",
      "count": 156,
      "avgDuration": 125.3
    }
  ],
  "byKey": [
    {
      "keyId": "key_abc123",
      "keyName": "Production API",
      "count": 2341,
      "avgDuration": 98.7,
      "lastUsed": "2024-01-15T14:35:00Z"
    }
  ],
  "totalMemories": 45678,
  "pagination": {
    "currentPage": 1,
    "limit": 20,
    "totalItems": 150,
    "totalPages": 8
  }
}
```

## Error Monitoring

Track and analyze errors to identify issues and improve reliability.

### Endpoint

`GET /v3/analytics/errors`

### Parameters

Same as usage endpoint - supports `from`, `to`, `period`, `page`, and `limit`.

### Example Request

<CodeGroup>

```typescript TypeScript
// Get errors from the last 24 hours
const errors = await fetch('https://api.supermemory.ai/v3/analytics/errors?period=24h', {
  headers: {
    'Authorization': `Bearer ${SUPERMEMORY_API_KEY}`
  }
});

const data = await errors.json();
```

```python Python
# Monitor errors and alert on spikes
response = requests.get(
    'https://api.supermemory.ai/v3/analytics/errors?period=1h',
    headers={'Authorization': f'Bearer {SUPERMEMORY_API_KEY}'}
)

data = response.json()
```

```bash cURL
# Get errors for the last 7 days
curl -X GET "https://api.supermemory.ai/v3/analytics/errors?period=7d" \
  -H "Authorization: Bearer $SUPERMEMORY_API_KEY"
```

</CodeGroup>

### Response Schema

```json
{
  "totalErrors": 234,
  "errorRate": 0.023,
  "topErrors": [
    {
      "type": "ValidationError",
      "count": 89,
      "statusCodes": [400],
      "lastOccurred": "2024-01-15T14:30:00Z"
    },
    {
      "type": "RateLimitError",
      "count": 45,
      "statusCodes": [429],
      "lastOccurred": "2024-01-15T13:15:00Z"
    }
  ],
  "timeline": [
    {
      "time": "2024-01-15T14:00:00Z",
      "count": 12,
      "types": ["ValidationError", "NotFoundError"]
    }
  ],
  "byStatusCode": {
    "400": 89,
    "404": 34,
    "429": 45,
    "500": 66
  }
}
```

## Detailed Logs

Access complete request/response logs for debugging and auditing.

### Endpoint

`GET /v3/analytics/logs`

### Parameters

Same as usage endpoint, plus optional filters:
- `type`: Filter by request type (add, search, update, delete)
- `statusCode`: Filter by HTTP status code
- `keyId`: Filter by specific API key

### Example Request

<CodeGroup>

```typescript TypeScript
// Get recent failed requests
const logs = await fetch('https://api.supermemory.ai/v3/analytics/logs?period=1h&statusCode=500', {
  headers: {
    'Authorization': `Bearer ${SUPERMEMORY_API_KEY}`
  }
});

const data = await logs.json();
```

```python Python
# Debug specific API key usage
response = requests.get(
    'https://api.supermemory.ai/v3/analytics/logs',
    params={
        'keyId': 'key_abc123',
        'period': '24h'
    },
    headers={'Authorization': f'Bearer {SUPERMEMORY_API_KEY}'}
)

logs = response.json()['logs']

```

```bash cURL
# Get all logs for debugging
curl -X GET "https://api.supermemory.ai/v3/analytics/logs?period=1h&limit=50" \
  -H "Authorization: Bearer $SUPERMEMORY_API_KEY"
```

</CodeGroup>

### Response Schema

```json
{
  "logs": [
    {
      "id": "req_xyz789",
      "createdAt": "2024-01-15T14:30:00Z",
      "type": "search",
      "statusCode": 200,
      "duration": 89,
      "input": {
        "q": "user query",
        "limit": 10
      },
      "output": {
        "results": 10,
        "processingTime": 85
      }
    }
  ],
  "pagination": {
    "currentPage": 1,
    "limit": 20,
    "totalItems": 500,
    "totalPages": 25
  }
}
```

## Rate Limits

Analytics endpoints have the following rate limits:
- 100 requests per minute per organization
- Maximum time range: 90 days
- Maximum page size: 100 items

<Warning>
Analytics data is retained for 90 days. For longer retention, export and store the data in your own systems.
</Warning>