Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(analytics): stop auth/timeout errors landing in 'Other' on the error chart (#1308)

tashdroidb5d8333177cb
diff --git a/server/src/__tests__/routes/analytics.test.ts b/server/src/__tests__/routes/analytics.test.ts
index fe6c1446..42e24db6 100644
--- a/server/src/__tests__/routes/analytics.test.ts
+++ b/server/src/__tests__/routes/analytics.test.ts
@@ -769,6 +769,30 @@ describe('Analytics API', () => {
expect(body.byCategory.find((c: any) => c.category === 'Rate Limited (429)').count).toBe(2);
});
+ it('classifies capitalized upstream auth and timeout messages out of Other', async () => {
+ // The messages upstream providers actually send. LIKE is case-sensitive
+ // in SQLite and the old '%invalid.*key%' pattern was regex syntax inside
+ // a LIKE (where '.' and '*' are literals), so "Invalid API key" and
+ // "Timeout" both fell into 'Other' and the dashboard hid auth failures.
+ insertRaw({ status: 'error', error: 'Invalid API key: sk-broken', createdAt: '2026-05-29 11:00:00' });
+ insertRaw({ status: 'error', error: 'Unauthorized: token expired', createdAt: '2026-05-29 11:01:00' });
+ insertRaw({ status: 'error', error: 'Too Many Requests', createdAt: '2026-05-29 11:02:00' });
+ insertRaw({ status: 'error', error: 'Timeout awaiting response headers', createdAt: '2026-05-29 11:03:00' });
+ insertRaw({ status: 'error', error: 'ETIMEDOUT after 30000ms', createdAt: '2026-05-29 11:04:00' });
+ // "timed out" is how our own abort paths word it; the '%500%' rule used to
+ // claim this one via the "5000ms" in the message.
+ insertRaw({ status: 'error', error: 'fusion tool call timed out after 5000ms', createdAt: '2026-05-29 11:05:00' });
+
+ const { status, body } = await request(app, '/api/analytics/error-distribution?range=24h');
+ expect(status).toBe(200);
+
+ const cat = (name: string) => body.byCategory.find((c: any) => c.category === name)?.count ?? 0;
+ expect(cat('Auth Error (401)')).toBe(2);
+ expect(cat('Rate Limited (429)')).toBe(1);
+ expect(cat('Timeout/Connection')).toBe(3);
+ expect(cat('Other')).toBe(0);
+ });
+
it('filters recent calls by the bare "custom" id to the orphaned rows only', async () => {
// The bare id is what /by-platform emits for rows whose endpoint is
// unknown. Selecting it must return exactly the rows that row counted —
diff --git a/server/src/routes/analytics.ts b/server/src/routes/analytics.ts
index 63753c48..52be54a0 100644
--- a/server/src/routes/analytics.ts
+++ b/server/src/routes/analytics.ts
@@ -483,19 +483,24 @@ analyticsRouter.get('/error-distribution', (req: Request, res: Response) => {
const since = getSinceTimestamp(range);
const db = getDb();
- // Group errors by category (extract the key part of the error message)
+ // Group errors by category (extract the key part of the error message).
+ // LOWER() first: LIKE is case-sensitive in SQLite, and the error strings we
+ // persist are dominated by capitalized upstream messages ("Invalid API key",
+ // "Too Many Requests", "Timeout"), which all landed in 'Other' before. The
+ // old '%invalid.*key%' pattern was regex syntax pasted into LIKE, where '.'
+ // and '*' are literal characters, so it matched nothing real.
const rows = db.prepare(`
SELECT
platform,
model_id,
CASE
- WHEN error LIKE '%429%' OR error LIKE '%rate limit%' OR error LIKE '%too many%' OR error LIKE '%quota%' THEN 'Rate Limited (429)'
- WHEN error LIKE '%401%' OR error LIKE '%unauthorized%' OR error LIKE '%invalid.*key%' THEN 'Auth Error (401)'
- WHEN error LIKE '%403%' OR error LIKE '%forbidden%' THEN 'Forbidden (403)'
- WHEN error LIKE '%404%' OR error LIKE '%not found%' THEN 'Not Found (404)'
- WHEN error LIKE '%timeout%' OR error LIKE '%ETIMEDOUT%' OR error LIKE '%ECONNREFUSED%' THEN 'Timeout/Connection'
- WHEN error LIKE '%500%' OR error LIKE '%internal server%' THEN 'Server Error (500)'
- WHEN error LIKE '%503%' OR error LIKE '%unavailable%' THEN 'Unavailable (503)'
+ WHEN lower(error) LIKE '%429%' OR lower(error) LIKE '%rate limit%' OR lower(error) LIKE '%too many%' OR lower(error) LIKE '%quota%' THEN 'Rate Limited (429)'
+ WHEN lower(error) LIKE '%401%' OR lower(error) LIKE '%unauthorized%' OR lower(error) LIKE '%invalid api key%' OR lower(error) LIKE '%invalid_api_key%' OR lower(error) LIKE '%incorrect api key%' THEN 'Auth Error (401)'
+ WHEN lower(error) LIKE '%403%' OR lower(error) LIKE '%forbidden%' THEN 'Forbidden (403)'
+ WHEN lower(error) LIKE '%404%' OR lower(error) LIKE '%not found%' THEN 'Not Found (404)'
+ WHEN lower(error) LIKE '%timeout%' OR lower(error) LIKE '%timed out%' OR lower(error) LIKE '%etimedout%' OR lower(error) LIKE '%econnrefused%' THEN 'Timeout/Connection'
+ WHEN lower(error) LIKE '%500%' OR lower(error) LIKE '%internal server%' THEN 'Server Error (500)'
+ WHEN lower(error) LIKE '%503%' OR lower(error) LIKE '%unavailable%' THEN 'Unavailable (503)'
ELSE 'Other'
END as error_category,
COUNT(*) as count
@@ -509,13 +514,13 @@ analyticsRouter.get('/error-distribution', (req: Request, res: Response) => {
const byCategory = db.prepare(`
SELECT
CASE
- WHEN error LIKE '%429%' OR error LIKE '%rate limit%' OR error LIKE '%too many%' OR error LIKE '%quota%' THEN 'Rate Limited (429)'
- WHEN error LIKE '%401%' OR error LIKE '%unauthorized%' OR error LIKE '%invalid.*key%' THEN 'Auth Error (401)'
- WHEN error LIKE '%403%' OR error LIKE '%forbidden%' THEN 'Forbidden (403)'
- WHEN error LIKE '%404%' OR error LIKE '%not found%' THEN 'Not Found (404)'
- WHEN error LIKE '%timeout%' OR error LIKE '%ETIMEDOUT%' OR error LIKE '%ECONNREFUSED%' THEN 'Timeout/Connection'
- WHEN error LIKE '%500%' OR error LIKE '%internal server%' THEN 'Server Error (500)'
- WHEN error LIKE '%503%' OR error LIKE '%unavailable%' THEN 'Unavailable (503)'
+ WHEN lower(error) LIKE '%429%' OR lower(error) LIKE '%rate limit%' OR lower(error) LIKE '%too many%' OR lower(error) LIKE '%quota%' THEN 'Rate Limited (429)'
+ WHEN lower(error) LIKE '%401%' OR lower(error) LIKE '%unauthorized%' OR lower(error) LIKE '%invalid api key%' OR lower(error) LIKE '%invalid_api_key%' OR lower(error) LIKE '%incorrect api key%' THEN 'Auth Error (401)'
+ WHEN lower(error) LIKE '%403%' OR lower(error) LIKE '%forbidden%' THEN 'Forbidden (403)'
+ WHEN lower(error) LIKE '%404%' OR lower(error) LIKE '%not found%' THEN 'Not Found (404)'
+ WHEN lower(error) LIKE '%timeout%' OR lower(error) LIKE '%timed out%' OR lower(error) LIKE '%etimedout%' OR lower(error) LIKE '%econnrefused%' THEN 'Timeout/Connection'
+ WHEN lower(error) LIKE '%500%' OR lower(error) LIKE '%internal server%' THEN 'Server Error (500)'
+ WHEN lower(error) LIKE '%503%' OR lower(error) LIKE '%unavailable%' THEN 'Unavailable (503)'
ELSE 'Other'
END as category,
COUNT(*) as count