Skip to main content

Events API

Track custom events and query them via the API.

Track Event

POST /api/v1/events

Request

curl https://flux.brainzlab.ai/api/v1/events \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "user.signup",
    "timestamp": "2024-01-15T10:30:00Z",
    "user_id": "user_123",
    "value": 29.99,
    "properties": {
      "plan": "pro",
      "source": "google_ads",
      "referrer": "blog-post-123"
    },
    "tags": {
      "environment": "production",
      "region": "us-east"
    }
  }'

Parameters

FieldTypeRequiredDescription
namestringYesEvent name (e.g., user.signup)
timestampstringNoISO8601 timestamp (defaults to now)
user_idstringNoAssociated user identifier
valuenumberNoNumeric value for aggregations
propertiesobjectNoArbitrary event data
tagsobjectNoIndexed metadata for filtering

Response

{
  "data": {
    "id": "evt_abc123",
    "name": "user.signup",
    "timestamp": "2024-01-15T10:30:00Z",
    "user_id": "user_123",
    "value": 29.99
  }
}

Batch Track

Send multiple events in one request:
POST /api/v1/events/batch

Request

curl https://flux.brainzlab.ai/api/v1/events/batch \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "name": "page.viewed",
        "user_id": "user_123",
        "properties": { "page": "/pricing" }
      },
      {
        "name": "button.clicked",
        "user_id": "user_123",
        "properties": { "button": "signup_cta" }
      }
    ]
  }'

Response

{
  "data": {
    "accepted": 2,
    "rejected": 0
  }
}

List Events

Query events with filters:
GET /api/v1/events

Parameters

ParameterTypeDescription
namestringFilter by event name (exact or prefix with *)
fromstringStart timestamp (ISO8601)
tostringEnd timestamp (ISO8601)
user_idstringFilter by user
tags[key]stringFilter by tag value
limitintegerMax results (default: 100, max: 1000)
offsetintegerPagination offset

Request

curl "https://flux.brainzlab.ai/api/v1/events?\
name=user.signup&\
from=2024-01-01T00:00:00Z&\
to=2024-01-31T23:59:59Z&\
tags[plan]=pro&\
limit=50" \
  -H "Authorization: Bearer sk_live_xxx"

Response

{
  "data": [
    {
      "id": "evt_abc123",
      "name": "user.signup",
      "timestamp": "2024-01-15T10:30:00Z",
      "user_id": "user_123",
      "value": 29.99,
      "properties": { "plan": "pro" },
      "tags": { "environment": "production" }
    }
  ],
  "meta": {
    "total": 234,
    "limit": 50,
    "offset": 0
  }
}

Count Events

Get event counts:
GET /api/v1/events/count

Parameters

ParameterTypeDescription
namestringEvent name filter
fromstringStart timestamp
tostringEnd timestamp
intervalstringGroup by interval (1m, 5m, 1h, 1d)
group_bystringGroup by tag key

Request

curl "https://flux.brainzlab.ai/api/v1/events/count?\
name=user.signup&\
from=2024-01-01&\
to=2024-01-31&\
interval=1d" \
  -H "Authorization: Bearer sk_live_xxx"

Response

{
  "data": {
    "total": 1234,
    "series": [
      { "timestamp": "2024-01-01T00:00:00Z", "count": 45 },
      { "timestamp": "2024-01-02T00:00:00Z", "count": 52 },
      { "timestamp": "2024-01-03T00:00:00Z", "count": 38 }
    ]
  }
}

Group By

curl "https://flux.brainzlab.ai/api/v1/events/count?\
name=user.signup&\
group_by=tags.plan" \
  -H "Authorization: Bearer sk_live_xxx"
{
  "data": {
    "total": 1234,
    "groups": {
      "pro": 567,
      "starter": 456,
      "enterprise": 211
    }
  }
}

Event Stats

Get aggregated statistics for events with values:
GET /api/v1/events/stats

Parameters

ParameterTypeDescription
namestringEvent name
fieldstringField to aggregate (default: value)
fromstringStart timestamp
tostringEnd timestamp

Request

curl "https://flux.brainzlab.ai/api/v1/events/stats?\
name=order.placed&\
field=value&\
from=2024-01-01&\
to=2024-01-31" \
  -H "Authorization: Bearer sk_live_xxx"

Response

{
  "data": {
    "count": 1234,
    "sum": 98765.43,
    "avg": 80.03,
    "min": 9.99,
    "max": 499.99,
    "p50": 65.00,
    "p95": 199.99,
    "p99": 349.99
  }
}

Rate Limits

  • Single event: Standard rate limit
  • Batch: 10 requests/minute, up to 500 events per request
  • Query: 60 requests/minute

Errors

CodeDescription
missing_nameEvent name is required
invalid_timestampTimestamp format invalid
batch_too_largeBatch exceeds 500 events
invalid_tagsTags must be string values