SDKs

Server SDKs

Authenticated verification and webhook signatures in Node.js, Python, Go, Ruby, and PHP.

On this page

Install from source

Node.js 20+
npm install git+https://github.com/bastionsecurityio/bastionsecurity-sdk-js.git

The SDK source release is 0.2.0. Package registry releases are pending, so use Git installation and pin the resolved revision. PHP requires composer install; Ruby requires bundle install. Go keeps the legacy sdk-go module import path even though the repository display name is bastionsecurity-sdk-go.

Verify a request

verify.ts
import { ServerBastion } from '@bastionsecurity/sdk';
import type { VerificationRequest } from '@bastionsecurity/sdk';

const bastion = new ServerBastion({
  siteKey: process.env.BASTION_SITE_KEY!,
  secret: process.env.BASTION_SECRET_KEY!,
  endpoint: process.env.BASTION_ENDPOINT || 'https://api.bastionsecurity.io/api/antibot',
});

// Call from your authenticated checkout handler. These values must
// come from your session, database, and payment provider.
export async function verifyCheckout(
  telemetry: VerificationRequest,
  order: { customerId: string; amount: number; paymentId: string },
) {
  const decision = await bastion.verify({
    token: telemetry.token,
    fingerprint: telemetry.fingerprint,
    behavior: telemetry.behavior,
    environment: telemetry.environment,
    idempotency_key: telemetry.idempotency_key,
    context: {
      event_type: 'checkout',
      account_id: order.customerId,
      order_amount: order.amount,
      payment_hash: order.paymentId,
    },
  });

  // Persist request_id with the order for audit and reconciliation.
  // Only 'allow' permits the fulfillment path. The caller must also
  // make payment and order fulfillment independently idempotent.
  return { allowed: decision.action === 'allow', decision };
}

Method reference

CapabilityJavaScript / PHPPython / RubyGo
Complete verificationverify(request)verify(request)Verify(ctx, request)
Token + contextclassify(token, context)classify(token, context)Classify(token, context)
Event trackingtrack(event, data, token?)track(event, data, token=…) / token:…Track(ctx, event, data, token)
Fingerprint registrationfingerprint(fingerprint, behavior?)fingerprint(fingerprint, behavior=…) / behavior:…Fingerprint(ctx, fingerprint, behavior)
Batch verificationbatch(events)batch(events)Batch(ctx, events)
Challenge creationcreateChallenge(difficulty?)create_challenge(difficulty=…) / difficulty:…CreateChallenge(ctx, difficulty)
Challenge verificationverifyChallenge(id, nonce)verify_challenge(id, nonce)VerifyChallenge(ctx, id, nonce)

Use verify for the full browser payload. Token-only classify is a convenience and does not carry all browser telemetry. Ruby fingerprint requires a positional fingerprint hash. All SDKs return the complete decision, including action, signals, identity when available, and request_id.

Transport & error handling

LanguageError interface
JavaScriptBastionError: status and response. flush waits; destroy aborts.
PythonBastionError: status and response. Context manager closes the session.
Go*bastion.Error: Status, Response, Cause; use errors.As. Context cancellation is honored.
RubyBastion::Error: status and response.
PHPBastion\BastionError: status and response.

Defaults are a 15-second timeout and two retries, bounded to 30 seconds and three retries. Retries reuse the serialized body and idempotency key. Validation and authentication failures are not retried. In Go, Retries: 0 selects the default; use -1 to disable retries. Endpoint redirects do not forward credentials. HTTPS is required except for localhost development.