Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io

    Server-Side SDKs (BillDogEng)

    Backend Engagement SDK Fleet

    The BilldogEng server-side SDKs provide unified backend hooks for all engagement services: Analytics, Feature Flags (including local evaluation), Surveys Data API, Outbound Messaging Dispatch, and LLM Observability. One of them, billdogeng-node, also verifies BillDog Auth session tokens — see section 8.

    1. Package Installation

    Install the billdogeng package using your language's package manager. Every server SDK is a prerelease (1.2.0-beta.1), so name the version: pip, Cargo, Hex, Bundler and Composer skip a prerelease unless it is named.

    npm install billdogeng-node@1.2.0-beta.1

    2. Initialization & Configuration

    Initialize the client singleton using your private API Key (starts with bd_secret_live_ or bd_secret_test_):

    import { BilldogEng } from 'billdogeng-node';
    
    const client = new BilldogEng('bd_secret_test_yourApiKey', {
      host: 'https://api.billdog.io/v1',
      flushAt: 20,
      flushInterval: 10000,
      localEvaluation: true, // Enable local flag evaluation
      gzip: true
    });

    3. Analytics (Event Capture & Identity)

    Capture events, update user super-properties, group tenants, and map aliases. Events are batched in the background:

    identify() links a user you have already authenticated elsewhere. It attaches traits to a distinct id you supply; it does not establish who the caller is. If you would rather BillDog signed them in — password, email or SMS code, Google, Apple, passkeys, second factors, organizations — see BillDog Auth. The session it issues carries the user’s entitlements in the token, so this server gates a paid feature with a claim check instead of a round-trip. Section 8 below covers verifying that token.

    // Capture custom events
    client.capture('user_9928', 'checkout_completed', {
      amount: 49.99,
      items_count: 3
    });
    
    // Identify a user and attach traits
    client.identify('user_9928', {
      email: 'user@gmail.com',
      company: 'stripe'
    });
    
    // Group association (e.g. workspace, team)
    client.groupIdentify('workspace', 'space_abc', {
      members: 12,
      plan: 'team'
    });
    
    // Alias mapping: alias(distinctId, alias) — known user id first
    client.alias('user_9928', 'anonymous_id_xyz');
    
    // Force flush queue before exit
    await client.flush();

    4. Feature Flags (Local / Remote)

    Check if a feature is enabled, evaluate multivariate variants, and retrieve payload configs with optional person attributes and B2B group targeting:

    // Boolean flag check with person properties and B2B groups
    const isEnabled = await client.isFeatureEnabled('new_payment_flow', 'user_9928', {
      personProperties: { country: 'US', tier: 'premium' },
      groups: { company: 'acme_corp', workspace: 'ws_alpha' }
    });
    
    if (isEnabled) {
      // Multivariant check
      const variant = await client.getFeatureFlag('new_payment_flow', 'user_9928', {
        groups: { company: 'acme_corp' }
      });
      console.log('Active variant:', variant); // e.g. 'v2' or 'control'
      
      // Retrieve variant JSON payload config
      const payload = await client.getFeatureFlagPayload('new_payment_flow', 'user_9928', {
        groups: { company: 'acme_corp' }
      });
      console.log('Payload configuration:', payload);
    }
    
    // In local mode, definitions are fetched once in the background. 
    // You can force-reload flag configurations from the server:
    await client.reloadFeatureFlagDefinitions();

    The first time a flag is read for a given user and value, the SDK emits a $feature_flag_called event with the flag key and response value for exposure tracking. Turn it off globally or per read with the SDK’s send-feature-flag-events option (sendFeatureFlagEvents in Node, send_feature_flag_events in Python, SendFeatureFlagEvents in Go and .NET).

    5. In-App Surveys (Data API)

    Fetch active surveys and submit responses programmatically (no visual components are rendered):

    // List available surveys
    const surveys = await client.surveys.list('user_9928');
    
    // Fetch survey structure
    const survey = await client.surveys.fetch('nps_feedback');
    
    // Record respondent response flow
    const { respondent_id } = await client.surveys.start('nps_feedback');
    
    // Record partial answers
    await client.surveys.recordPartial('nps_feedback', respondent_id, [
      { question_id: 'q1', answer_number: 9 }
    ]);
    
    // Final submit
    await client.surveys.submit('nps_feedback', [
      { question_id: 'q1', answer_number: 10 },
      { question_id: 'q2', answer_text: 'The billing flow was seamless!' }
    ], { respondentId: respondent_id });
    
    // Or abandon survey
    await client.surveys.abandon('nps_feedback', respondent_id);

    6. Outbound Messaging Dispatch

    Send push, email, SMS, and in-app campaigns to targeted audiences programmatically:

    await client.messaging.dispatch({
      projectId: 'proj_abc123',        // required — project UUID
      channel: 'push',                 // push | email | sms | in-app | live-activity
      content: {
        title: 'Limited Offer!',
        body: 'Get 20% off your yearly subscription upgrade.'
      },
      targeting: {
        conditions: [
          { attribute: 'plan', operator: 'equals', value: 'free' }
        ]
      },
      scheduling: {
        deliveryType: 'immediate'
      },
      accessToken: 'eyJ...supabaseJWT' // required — Supabase session Bearer JWT (not the X-BillDog-API-Key project key)
    });

    7. LLM Observability Tracing

    Trace LLM invocations, cost, duration, and token usage to monitor LLM operations:

    await client.captureTrace({
      traceId: 'trace_7781a',
      spanId: 'span_b9281',
      model: 'gpt-4o',
      inputText: 'Summarize the user invoice data.',
      outputText: 'The invoice contains 3 line items totaling $49.99.',
      promptTokens: 142,
      completionTokens: 88,
      durationMs: 420,
      costUsd: 0.0034
    });

    8. BillDog Auth (Session-Token Verification)

    Verification is a local signature check against a cached JWKS, so it makes no call to BillDog: an outage on our side cannot take your authorization with it, and a hot route pays no network cost. Install is the same package as the rest of this page — npm install billdogeng-node, Node 18 or newer — and nothing needs enabling beyond BillDog Auth being on for the project.

    import { verifyToken, hasEntitlement, BillDogAuthError } from 'billdogeng-node';
    
    app.use(async (req, res, next) => {
      try {
        const claims = await verifyToken(req.headers.authorization!.slice(7), {
          projectId: process.env.BILLDOG_PROJECT_ID!,
          environment: 'production',   // defaults to 'production' — see below
        });
        if (!hasEntitlement(claims, 'pro')) return res.status(403).end();
        req.userId = claims.sub;       // the person who signed in
        req.customerId = claims.cus;   // the record they own, for joining BillDog data
        next();
      } catch (e) {
        if (e instanceof BillDogAuthError) return res.status(401).end();
        throw e;
      }
    });

    The environment option is a security control

    It defaults to 'production', the strict answer. Sandbox and production identities are different people in BillDog, so a backend serving real users must refuse a sandbox token even though it is genuinely signed and in-window. Pass 'sandbox' only on a backend that serves sandbox traffic. Omitting the option means production; a sandbox backend that forgets it fails loudly rather than admitting test identities to real data.

    Never read ent as a complete list

    The token carries entitlements in the ent claim, capped at 64 entries, with ent_truncated set once it is cut. “Not in a truncated list” is not evidence of absence, and treating it as one turns a paying customer into a free one. hasEntitlement() answers only from the visible slice, so check entitlementsComplete() before you trust a false:

    import { hasEntitlement, entitlementsComplete, introspect } from 'billdogeng-node';
    
    if (!hasEntitlement(claims, 'pro') && !entitlementsComplete(claims)) {
      // ent hit the cap and 'pro' was not in the slice we can see.
      // Ask the server for the definitive answer — this one costs a round trip.
      const { active, claims: full } = await introspect(token, {
        apiKey: process.env.BILLDOG_API_KEY!,
      });
    }

    What these SDKs cannot do: sign anyone in. There is no credential handling and no UI here — a server SDK that could sign users in would need their passwords, which is exactly what BillDog Auth exists to keep off your infrastructure. They also cannot complete a password reset (hosted-only) or delete a user’s own account. Users sign in through @billdog.io/auth on the web or the platform SDKs on mobile; the server verifies what they carry. Note the vocabulary in the claims: sub is the user, the person who signed in, and cus is the customer record they own.

    If your backend is not Node, the two honest options are to introspect over HTTP as above, or to verify in a small Node service — an edge function or sidecar — and pass the decided identity inward on a trusted channel. Both are real costs; neither is a workaround we are hiding.

    Next Steps

    • BillDog Auth — sign users in, and gate features on the token
    • Verifying Tokens — the full claim set, JWKS caching, clock skew and key rotation
    • Sessions & Tokens — the 90-second access token, refresh, and revocation
    • Limits — the entitlement cap and the auth rate limits

    Was this page helpful?

    Or rate this page:

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.