Start here
Your first integration
Collect telemetry in the browser, verify on your server, and enforce the result before completing checkout.
On this page
1. Create your site
- Sign in to the tenant dashboard and create a site in Settings.
- Open Integration and copy the public site key and server secret.
- Allowlist each frontend origin, including the exact scheme and port. Development http://localhost:3000 and production https://shop.example.com are different origins.
- Start in monitor mode while reviewing your traffic, then choose block or challenge when you are ready to enforce.
2. Install the SDK
Node.js 20+
npm install git+https://github.com/bastionsecurityio/bastionsecurity-sdk-js.gitUse these Git installs while registry publication is pending. Pin a reviewed commit or the resolved lockfile in production. The JavaScript import name is @bastionsecurity/sdk; Python imports bastion. Run composer install after adding the PHP repository. Go retains the github.com/bastionsecurityio/sdk-go module path for compatibility.
3. Collect in your frontend
checkout.ts
import Bastion from '@bastionsecurity/sdk';
const bastion = new Bastion({
siteKey: 'YOUR_PUBLIC_SITE_KEY',
endpoint: 'https://api.bastionsecurity.io/api/antibot',
});
// Run after the customer has interacted with the page.
const verification = await bastion.buildRequest({
event_type: 'checkout',
account_id: 'customer_123',
});
// Your backend authenticates the customer and loads the order.
const response = await fetch('/api/checkout/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(verification),
});
if (!response.ok) throw new Error('Checkout could not be approved');
const result = await response.json();
// Show the next step returned by your backend. Fulfill on the server.Initialize once per page or application shell so interaction metrics accumulate before checkout. buildRequest returns the token and the fingerprint, behavior, environment, and idempotency key. Preserve all of them when sending to your own backend.
4. Verify authoritative context
verify-checkout.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 };
}5. Confirm the end-to-end flow
- Send one test request and find its request_id in the dashboard event stream.
- Retry the identical request with the same idempotency key. It should return the same decision without a second recorded event.
- Verify your fulfillment path stops for review, challenge, block, and API errors.
- Enable a webhook, send a dashboard test after an event exists, and confirm your receiver rejects a changed body.
- Switch enforcement mode after reviewing scores and legitimate customer outcomes.