Admin SDK (`@segops/admin`)
A **server-side** SDK for driving SegOps programmatically — the same operations the dashboard performs: create segments, import products, run recomputes, manage schemas/activations/queries, and export pages.
This is not the ingestion SDK (@segops/sdk). The Admin SDK uses secret
keys only (sk_…) and can mutate/delete resources. Never ship it to a
browser or embed a secret key client-side.
Install#
Requires Node 18+ (uses the global fetch). Pass a fetch implementation for
older runtimes.
Quick start#
new SegOpsAdmin() throws SegOpsConfigError if the key isn't an sk_ key
(public pk_ and MCP mk_ keys are rejected).
Resources#
Every resource shares the CRUD surface (list, iterate, get, create,
update, delete) plus resource-specific actions.
| Namespace | Highlights |
|---|---|
segments | recompute(id), members(id), membership(userId), export(id, { format }), preview(definition) |
productSegments | CRUD + recompute(id) |
products | bulkUpsert(rows), importCsv(blob), score(id), scoreAll(), facets(), schema() |
schemas | infer(events), validate(eventType, payload) |
activations | sync(id) |
users | search(), get(id), events(id), segments(id), explain(id, segmentId) |
queries | run(id), results(id), simulate(body), dashboard(), winRate() |
pages | bulkGenerate(), regenerate(id), build(id, body), publish(id), export(id, { format }), query(q) |
analytics | overview(), usage(), segments(), overlap(), activations() |
Examples#
Pagination#
List endpoints are page-number paginated. list() returns the
{ count, next, previous, results } envelope; iterate() walks every page:
Errors, retries, idempotency#
- Non-2xx responses throw
SegOpsApiErrorwith.statusand.body. 429and5xxare retried (honoringRetry-After, exponential backoff; configurable viamaxRetries).- Mutations send an
Idempotency-Keyheader automatically (forward-compatible with server-side idempotency).
Webhook verification#
Verify SegOps outbound webhooks (X-SegOps-Signature: sha256=…):
CLI#
The package ships a CLI for quick ops and scripting:
Run npx @segops/admin help for the full command list.
Escape hatch#
For endpoints not yet wrapped, use the low-level client: