SDKs
Server SDKs
Authenticated verification and webhook signatures in Node.js, Python, Go, Ruby, and PHP.
On this page
Install from source
npm install git+https://github.com/bastionsecurityio/bastionsecurity-sdk-js.gitThe 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
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
| Capability | JavaScript / PHP | Python / Ruby | Go |
|---|---|---|---|
| Complete verification | verify(request) | verify(request) | Verify(ctx, request) |
| Token + context | classify(token, context) | classify(token, context) | Classify(token, context) |
| Event tracking | track(event, data, token?) | track(event, data, token=…) / token:… | Track(ctx, event, data, token) |
| Fingerprint registration | fingerprint(fingerprint, behavior?) | fingerprint(fingerprint, behavior=…) / behavior:… | Fingerprint(ctx, fingerprint, behavior) |
| Batch verification | batch(events) | batch(events) | Batch(ctx, events) |
| Challenge creation | createChallenge(difficulty?) | create_challenge(difficulty=…) / difficulty:… | CreateChallenge(ctx, difficulty) |
| Challenge verification | verifyChallenge(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
| Language | Error interface |
|---|---|
| JavaScript | BastionError: status and response. flush waits; destroy aborts. |
| Python | BastionError: status and response. Context manager closes the session. |
| Go | *bastion.Error: Status, Response, Cause; use errors.As. Context cancellation is honored. |
| Ruby | Bastion::Error: status and response. |
| PHP | Bastion\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.