Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.threadify.dev/llms.txt

Use this file to discover all available pages before exploring further.

1. and Install the SDK

npm install @threadify/sdk

2. Connect to Threadify

Need an API key? Create an account and Generate one here to get started.
import { Threadify } from '@threadify/sdk';

// Connect with your API key and service name
const connection = await Threadify.connect('your-api-key', 'my-service');

3. Create Your First Thread

// Start tracking a workflow with a label
const thread = await connection.start('Order-123');

// Or start with a contract and a label
const thread = await connection.start('Order-789', 'order_fulfillment');

4. Add Steps to Your Process

// Create step first, then call methods on it
const step = thread.step('validate_input');
await step.addContext({ userId: 'user-123' }).success();

// Or chain directly on the step builder
await thread.step('process_data')
  .addContext({ records: 42 })
  .success();

5. Handle Failures

// Create step first to track execution time
const paymentStep = thread.step('payment_processed');
try {
  const payment = await processPayment(orderId);
  await paymentStep.addContext(payment).success();
} catch (error) {
  await paymentStep.failed({ 
    message: 'Payment gateway timeout',
    errorCode: 'TIMEOUT'
  });
}

6. Set Up Real-time Event Listeners (Optional)

Subscribe to WebSocket events to react to execution graph changes in real-time.
// Listen for execution events
connection.on('step.success', 'payment_processed', (event) => {
  console.log('Payment processed - update UI, send confirmation email');
  event.ack();
});

// Listen for validation violations
connection.on('rule.violated', 'inventory_check', (event) => {
  console.error('Inventory violation detected - escalate to ops');
  event.ack();
});

// Contract-specific events
connection.on('rule.violated', 'product_delivery@order_placed', (event) => {
  console.log('Product delivery rule violated - notify logistics');
  event.ack();
});

What’s Next?

Need Help?