Headlessly
SDK

SDK Reference

Complete API reference for the @headlessly/* TypeScript SDK.

The @headlessly/* SDK gives you typed access to all 35 entities across 11 product domains. Install the full SDK or pick individual domain packages.

Install

# Full SDK — all 35 entities, $ global, domain namespaces
npm install @headlessly/sdk

# Or install only what you need
npm install @headlessly/crm
npm install @headlessly/billing
npm install @headlessly/projects

Three Import Styles

Universal context ($)

Use $ when your code touches multiple domains in a single operation.

import { $ } from '@headlessly/sdk'

const contact = await $.Contact.create({ name: 'Alice', stage: 'Lead' })
await $.Deal.create({ title: 'Enterprise deal', contact: contact.id, value: 50000 })
await $.Subscription.create({ plan: 'pro', contact: contact.id })

Direct entity imports

Use direct imports when you work within a single domain. This is the most common style.

import { Contact, Deal } from '@headlessly/crm'
import { Subscription } from '@headlessly/billing'

const contact = await Contact.create({ name: 'Alice', stage: 'Lead' })
await Deal.create({ title: 'Enterprise deal', contact: contact.id, value: 50000 })

Domain namespace imports

Use namespaces when you want explicit domain grouping without the full $ graph.

import { crm, billing } from '@headlessly/sdk'

await crm.Contact.create({ name: 'Alice', stage: 'Lead' })
await billing.Subscription.create({ plan: 'pro', contact: 'contact_fX9bL5nRd' })

Package Hierarchy

LayerPackagesPurpose
SDK@headlessly/sdkFull 35-entity graph, exports $ and domain namespaces
Domaincrm, billing, projects, content, support, analytics, marketing, experiments, platform, plus Identity and Communication via sdkEach owns a set of entities
Lifecyclebuild, launch, experiment, grow, sell, market, automate, scaleSame entities, organized by startup phase
Business Modelb2b, b2c, b2d, b2aSame entities, organized by business model
CLI@headlessly/cliCLI entry point (npx @headlessly/cli)

Domain-to-Entity Mapping

DomainPackageEntities
Identity@headlessly/sdkUser, ApiKey
CRM@headlessly/crmOrganization, Contact, Lead, Deal, Activity, Pipeline
Billing@headlessly/billingCustomer, Product, Plan, Price, Subscription, Invoice, Payment
Projects@headlessly/projectsProject, Issue, Comment
Content@headlessly/contentContent, Asset, Site
Support@headlessly/supportTicket
Analytics@headlessly/analyticsEvent, Metric, Funnel, Goal
Marketing@headlessly/marketingCampaign, Segment, Form
Experimentation@headlessly/experimentsExperiment, FeatureFlag
Platform@headlessly/platformWorkflow, Integration, Agent
Communication@headlessly/sdkMessage

Tenant Configuration

Set the HEADLESSLY_TENANT environment variable. The SDK reads it automatically -- never pass it explicitly.

export HEADLESSLY_TENANT=my-startup

Entity IDs

All entity IDs use the format {type}_{sqid} where the suffix is generated by sqids -- short, unique, URL-safe identifiers with a built-in blocklist.

'contact_fX9bL5nRd'   // Contact
'deal_k7TmPvQx'       // Deal
'project_e5JhLzXc'    // Project
'sub_nR4wKpYm'        // Subscription

What This Section Covers

  • Entity Operations -- CRUD operations, custom verbs, and type signatures for all 35 entities
  • Queries and Filters -- MongoDB-style filters, sorting, pagination, and time travel
  • Event Handlers -- BEFORE and AFTER hooks, the $ context, and subscription patterns
  • Business Status -- The $.status() endpoint for full business-state visibility
  • React SDK -- Hooks and providers for React applications
  • Browser SDK -- Lightweight client-side analytics and feature flags
  • Node.js SDK -- Server-side integrations
  • API Client -- Low-level REST client for direct HTTP access

On this page