SegOps AIDocs

Quickstart (5 min)

This guide walks you from zero to your first computed segment in about five minutes.

Tip
Prefer curl? Skip ahead to the curl-based quickstart.

Step 1 — Create your account and workspace

Sign up at app.segops.ai. During onboarding you will be prompted to choose a tenant slug — a short lowercase identifier like acme that scopes all your data. You can invite team members immediately from Settings → Team.

Step 2 — Get your API key

Navigate to Settings → API Keys and click + New Key. Copy the key immediately — it is shown only once. Keys start with sk_.

bash
# Keep this secret — treat it like a password
export SEGOPS_API_KEY="sk_live_xxxxxxxxxxxxxxxx"

Step 3 — Install the SDK

The TypeScript/JavaScript SDK works in Node.js and modern browsers:

bash
npm install @segops/sdk

Initialize the client once (e.g., in a lib/segops.ts file):

typescript
import { SegOpsClient } from '@segops/sdk';

export const segops = new SegOpsClient({
  apiUrl: 'https://api.segops.ai',
  apiKey: process.env.SEGOPS_API_KEY!,
});

Step 4 — Send your first event

typescript
// Track a page view
segops.track({
  userId: 'user-123',
  eventType: 'page_viewed',
  payload: { path: '/pricing' },
});

// Identify a user (sets traits for user_property conditions)
segops.identify({
  userId: 'user-123',
  traits: { email: '[email protected]', plan: 'starter' },
});

// On Node.js server shutdown, flush any buffered events
process.on('SIGTERM', async () => {
  await segops.shutdown();
  process.exit(0);
});
Note
Events are buffered in memory and flushed in batches every 5 seconds or when the buffer reaches 20 events. Call segops.flush() to force an immediate flush.

Step 5 — Define a segment

In the UI go to Segments → New Segment. Give it a name like “Pricing Page Visitors”, add a condition of type event_count with event_type page_viewed, operator gte, value 1.

Or do it via the API:

bash
# 1. Create the segment
curl -X POST https://api.segops.ai/api/segments/ \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pricing Page Visitors",
    "tenant": 1,
    "segment_type": "rule"
  }'

# Response: { "id": 42, "name": "Pricing Page Visitors", ... }

# 2. Set the definition
curl -X PATCH https://api.segops.ai/api/segments/42/ \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "definition": {
      "logic": "AND",
      "conditions": [
        {
          "type": "event_count",
          "event_type": "page_viewed",
          "operator": "gte",
          "value": 1
        }
      ]
    }
  }'

Step 6 — Compute membership

Trigger the async membership computation. A background worker evaluates every user against your segment definition and writes results to the analytics warehouse.

bash
curl -X POST https://api.segops.ai/api/segments/42/compute/ \
  -H "Authorization: Bearer $JWT_TOKEN"

# Response: { "status": "queued" }

You can also click the Recompute button in the segment detail UI. Computation typically takes seconds to minutes depending on event volume.

Step 7 — Check membership

bash
curl "https://api.segops.ai/api/segments/membership/?user_id=user-123" \
  -H "Authorization: ApiKey $SEGOPS_API_KEY"

# Response:
# {
#   "user_id": "user-123",
#   "segment_ids": [42],
#   "cached": false
# }
Tip
Results are Redis-cached for 5 minutes. For real-time personalization, this endpoint returns in under 10 ms on a warm cache.

curl-based quickstart (no SDK)

Everything above can be done with plain HTTP requests. Here is the full flow in curl:

bash
# 1. Obtain a JWT token
curl -X POST https://api.segops.ai/api/auth/token/ \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "password": "yourpassword"}'

# 2. Set your token
export JWT="<access_token_from_above>"
export API_KEY="sk_live_..."  # from Settings → API Keys

# 3. Send an event
curl -X POST https://api.segops.ai/api/ingestion/track/ \
  -H "Authorization: ApiKey $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "user-123",
    "event_type": "page_viewed",
    "payload": { "path": "/pricing" }
  }'

# 4. Create + define a segment
curl -X POST https://api.segops.ai/api/segments/ \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  -d '{"name": "Pricing Visitors", "tenant": 1, "segment_type": "rule"}'

# 5. Trigger compute (replace 1 with your segment id)
curl -X POST https://api.segops.ai/api/segments/1/compute/ \
  -H "Authorization: Bearer $JWT"

# 6. Check membership
curl "https://api.segops.ai/api/segments/membership/?user_id=user-123" \
  -H "Authorization: ApiKey $API_KEY"