Skip to main content
err:user:bad_request:invalid_analytics_query
Example
{
  "meta": {
    "requestId": "req_4dgzrNP3Je5mU1tD"
  },
  "error": {
    "detail": "Syntax error: Expected identifier, got 'FROM' at position 15",
    "status": 400,
    "title": "Bad Request",
    "type": "https://unkey.com/docs/errors/user/bad_request/invalid_analytics_query"
  }
}

What Happened?

Your SQL query has a syntax error! The query parser found invalid SQL syntax that prevents it from being executed. Common causes include:
  • Missing or extra commas
  • Unclosed quotes or parentheses
  • Typos in SQL keywords
  • Invalid column or table names

How to Fix It

1. Check for Missing Commas

SELECT
  api_id
  COUNT(*) as total
FROM key_verifications_v1

2. Match Quotes and Parentheses

SELECT * FROM key_verifications_v1 WHERE api_id = 'api_123

3. Use Correct SQL Keywords

SELCT * FROM key_verifications_v1

4. Verify Column Names

Make sure you’re using valid column names from your analytics tables:
-- ✓ Valid columns
SELECT time, api_id, outcome, key_id
FROM key_verifications_v1
WHERE time >= now() - INTERVAL 7 DAY

Need Help?

If you’re stuck with a syntax error:
  1. Check the error message - It usually tells you exactly where the problem is
  2. Test incrementally - Start with a simple SELECT * and add complexity step by step
  3. Use a SQL validator - Many online tools can help spot syntax errors