Skip to main content
err:user:bad_request:invalid_analytics_query_type
Example
{
  "meta": {
    "requestId": "req_4dgzrNP3Je5mU1tD"
  },
  "error": {
    "detail": "Only SELECT queries are allowed",
    "status": 400,
    "title": "Bad Request",
    "type": "https://unkey.com/docs/errors/user/bad_request/invalid_analytics_query_type"
  }
}

What Happened?

You tried to run a query that modifies data or isn’t a SELECT! Analytics queries are read-only - you can only SELECT data, not modify it. Blocked query types:
  • INSERT - Adding new data
  • UPDATE - Modifying existing data
  • DELETE - Removing data
  • DROP - Deleting tables
  • CREATE - Creating tables
  • ALTER - Modifying table structure
  • TRUNCATE - Clearing tables

How to Fix It

1. Use SELECT Instead

Analytics is for querying data, not modifying it:
INSERT INTO key_verifications_v1 VALUES (...)

2. Query Your Data

The analytics endpoint is for analyzing your verification data:
-- ✓ Count verifications by outcome
SELECT outcome, COUNT(*) as total
FROM key_verifications_v1
WHERE time >= now() - INTERVAL 1 DAY
GROUP BY outcome

-- ✓ Get hourly verification rates
SELECT
  toStartOfHour(time) as hour,
  COUNT(*) as verifications
FROM key_verifications_v1
WHERE time >= now() - INTERVAL 24 HOUR
GROUP BY hour
ORDER BY hour

-- ✓ Find most active APIs
SELECT
  api_id,
  COUNT(*) as requests
FROM key_verifications_v1
WHERE time >= now() - INTERVAL 7 DAY
GROUP BY api_id
ORDER BY requests DESC
LIMIT 10

3. Use the Correct API for Data Modification

If you need to modify data, use the appropriate Unkey API endpoints:
What You WantUse This API
Create a keyPOST /v2/keys.createKey
Update a keyPATCH /v2/keys.updateKey
Delete a keyPOST /v2/keys.deleteKey
Modify permissionsPOST /v2/keys.addPermissions

Why Read-Only?

Analytics queries are read-only for several reasons:
  1. Data integrity - Verification history should never be modified
  2. Performance - Read-only queries can be heavily optimized
  3. Security - Prevents accidental or malicious data corruption
  4. Audit trail - Preserves accurate historical records
Analytics is for understanding your data, not changing it. Use the main Unkey API for creating, updating, or deleting resources.
Last modified on March 30, 2026