AI integration

Using Analas as an AI agent

Everything a human can do in the Analas dashboard — query event counts, read insight results, browse session recordings, and build dashboards — is also reachable with a scoped API key, with no browser session involved. This page is written for an agent (or the person configuring one) to read directly.

1. Get a scoped API key

In Workspace Settings → API Keys, create a key with a descriptive name (e.g. "Claude Ingest Agent" or "CI Verification Worker") and select only the scopes it needs. Scopes are additive and immutable after creation — revoke and recreate a key to change its scopes.

events:write        # capture events (default scope)
events:read         # list top event names
insights:read       # read saved insights, run ad-hoc queries
insights:write      # create insights
dashboards:read     # list/read dashboards
dashboards:write    # create dashboards
recordings:read     # list and stream session recordings

Structured Key Format & Workspace Identification

Keys are structured as analas_sk_<workspace_prefix>_<random_token>. Each key also displays a safe non-secret hint (e.g. analas_sk_a1b2c3_••••8d2c) and tracks its last usage time (lastUsedAt) so you can easily identify which workspace and agent a key belongs to without exposing the secret.

Every request authenticates the same way: an Authorization: Bearer analas_sk_... header (legacy analas_pk_... keys continue to be fully supported). A key can only act on the workspace it was created in, and only within the scopes it was granted — a read-only key can never create or delete anything.

2. Endpoint reference

GET/api/v1/eventsevents:read

List the most frequent event names captured for your workspace.

Response
{ "events": ["page_view", "checkout_completed", "signup"] }
POST/api/v1/insights/queryinsights:read

Run an ad-hoc query with no saved Insight — the core "did metric X change" primitive.

{ "type": "trend", "queryConfig": { "eventName": "checkout_completed", "timeFrame": 14 } }
Response
{ "total": 842, "rows": [{ "day": "2026-07-21", "count": 61 }] }
GET/api/v1/insights/:insightIdinsights:read

Fetch a saved insight's metadata (name, type, queryConfig).

Response
{ "insight": { "id": "...", "name": "...", "type": "trend", "queryConfig": {...} } }
GET/api/v1/insights/:insightId/datainsights:read

Run a saved insight and return its current data.

Response
{ "total": 842, "rows": [...] }
POST/api/v1/insightsinsights:write

Create a new insight. Omit dashboardId to use (or auto-create) the workspace's first dashboard.

{ "name": "Signups / day", "type": "trend", "queryConfig": { "eventName": "signup", "timeFrame": 30 }, "dashboardId": "optional" }
Response
{ "insight": { "id": "...", "name": "...", "type": "trend" } }
GET/api/v1/dashboardsdashboards:read

List dashboards in your workspace, each with its insights.

Response
{ "dashboards": [{ "id": "...", "name": "...", "insights": [...] }] }
GET/api/v1/dashboards/:dashboardIddashboards:read

Fetch a single dashboard with its insights, ordered by position.

Response
{ "dashboard": { "id": "...", "name": "...", "insights": [...] } }
POST/api/v1/dashboardsdashboards:write

Create a new dashboard.

{ "name": "Agent-built dashboard" }
Response
{ "dashboard": { "id": "...", "name": "..." } }
GET/api/v1/recordingsrecordings:read

Cursor-paginated list of session recordings. Filter with ?pagePath= or ?distinctId=.

Response
{ "total": 120, "rows": [...], "nextCursor": "..." }
GET/api/v1/recordings/:sessionId/streamrecordings:read

Stream a single recording's raw NDJSON event log.

Response
application/x-ndjson body

Insight type values: count, trend, breakdown, multi_trend, funnel, metric, retention, session_recording — see insight types docs for each type's queryConfig fields. Insight types beyond count and trend require a plan that includes that feature — a 403 response means an upgrade is needed, not a bug.

breakdown and trend also accept an optional filters array in queryConfig to narrow by other properties: "filters": [{ "property": "city", "value": "Tehran" }] (up to 5, each an exact-match equality check). For trend, this is how you plot two segments as separate lines on one chart — run the query twice with different filter values and combine the two rows arrays client-side. Requires a plan with the advanced_filters feature — on plans without it, filters are silently ignored and the query runs unfiltered rather than erroring.

3. Worked examples

Sensor — poll a metric on a schedule

curl https://your-domain.com/api/v1/insights/query \
  -H "Authorization: Bearer $ANALAS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"count","queryConfig":{"eventName":"error_boundary_triggered"}}'

Verification — did a deploy actually change a metric?

# Compare a saved insight's data before/after a deploy
curl https://your-domain.com/api/v1/insights/ins_abc123/data \
  -H "Authorization: Bearer $ANALAS_KEY"

Breakdown — narrow a property split with filters

curl https://your-domain.com/api/v1/insights/query \
  -H "Authorization: Bearer $ANALAS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"breakdown","queryConfig":{"eventName":"reservation_completed","property":"city","filters":[{"property":"flow","value":"customer"}]}}'

Trend — compare two segments as separate lines

# Run twice with different filter values, plot both "rows" arrays on one chart
curl https://your-domain.com/api/v1/insights/query \
  -H "Authorization: Bearer $ANALAS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"trend","queryConfig":{"eventName":"page_view","timeFrame":14,"filters":[{"property":"entry_flow","value":"map_search"}]}}'

curl https://your-domain.com/api/v1/insights/query \
  -H "Authorization: Bearer $ANALAS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"trend","queryConfig":{"eventName":"page_view","timeFrame":14,"filters":[{"property":"entry_flow","value":"home"}]}}'

Analytics in its own right — build a dashboard

curl -X POST https://your-domain.com/api/v1/dashboards \
  -H "Authorization: Bearer $ANALAS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Agent-built: onboarding health"}'

curl -X POST https://your-domain.com/api/v1/insights \
  -H "Authorization: Bearer $ANALAS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Signups / day","type":"trend","queryConfig":{"eventName":"signup","timeFrame":30},"dashboardId":"<id from above>"}'

4. Limits

  • Requests are rate-limited per key; a 429 response means back off and retry later.
  • Read endpoints respect your plan's data retention window — a time range beyond that window is clamped, not rejected.
  • Insight types gated by plan (funnels, retention, session recordings, advanced filters) return 403 if your workspace's plan doesn't include them.