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
go get github.com/ThreadifyDev/go-sdk
pip install threadify-sdk
2. Connect to Threadify
import { Threadify } from '@threadify/sdk';
// Connect with your API key and service name
const connection = await Threadify.connect('your-api-key', 'my-service');
ctx := context.Background()
conn, err := threadify.Connect(ctx, "your-api-key",
threadify.WithServiceName("my-service"),
)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
from threadify import Threadify
# Connect with your API key and service name
connection = await Threadify.connect(
"your-api-key",
service_name="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');
// Start tracking a workflow with a label
thread, err := conn.Start(ctx, "Order-123", "")
if err != nil {
log.Fatal(err)
}
// Or start with a contract and a label
thread, err := conn.Start(ctx, "Order-789", "order_fulfillment")
if err != nil {
log.Fatal(err)
}
# Start tracking a workflow with a label
thread = await connection.start("Order-123")
# Or start with a contract and a label
thread = await connection.start("Order-789", contract_name="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();
// Create step first, then call methods on it
step := thread.Step("validate_input")
_, err := step.AddContext(map[string]any{"userId": "user-123"}).Success(ctx)
if err != nil {
log.Fatal(err)
}
// Or chain directly on the step builder
_, err = thread.Step("process_data").
AddContext(map[string]any{"records": 42}).
Success(ctx)
if err != nil {
log.Fatal(err)
}
# Create step first, then call methods on it
step = thread.step("validate_input")
await step.add_context({"userId": "user-123"}).success()
# Or chain directly on the step builder
await (
thread.step("process_data")
.add_context({"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'
});
}
// Create step first to track execution time
paymentStep := thread.Step("payment_processed")
payment, err := processPayment(orderId)
if err != nil {
_, stepErr := paymentStep.Failed(ctx, map[string]any{
"message": "Payment gateway timeout",
"errorCode": "TIMEOUT",
})
if stepErr != nil {
log.Fatal(stepErr)
}
return
}
_, err = paymentStep.AddContext(payment).Success(ctx)
if err != nil {
log.Fatal(err)
}
# Create step first to track execution time
payment_step = thread.step("payment_processed")
try:
payment = await process_payment(order_id)
await payment_step.add_context(payment).success()
except Exception as error:
await payment_step.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();
});
// Listen for execution events
err := conn.Subscribe(ctx, "step.success", "payment_processed", func(n *threadify.Notification) {
fmt.Println("Payment processed - update UI, send confirmation email")
n.Ack()
})
if err != nil {
log.Fatal(err)
}
// Listen for validation violations
err = conn.Subscribe(ctx, "rule.violated", "inventory_check", func(n *threadify.Notification) {
fmt.Println("Inventory violation detected - escalate to ops")
n.Ack()
})
if err != nil {
log.Fatal(err)
}
// Contract-specific events
err = conn.Subscribe(ctx, "rule.violated", "product_delivery@order_placed", func(n *threadify.Notification) {
fmt.Println("Product delivery rule violated - notify logistics")
n.Ack()
})
if err != nil {
log.Fatal(err)
}
# Listen for execution events
def on_payment_success(event):
print("Payment processed - update UI, send confirmation email")
event.ack()
connection.subscribe("step.success", "payment_processed", on_payment_success)
# Listen for validation violations
def on_inventory_violation(event):
print("Inventory violation detected - escalate to ops")
event.ack()
connection.subscribe("rule.violated", "inventory_check", on_inventory_violation)
# Contract-specific events
def on_contract_violation(event):
print("Product delivery rule violated - notify logistics")
event.ack()
connection.subscribe("rule.violated", "product_delivery@order_placed", on_contract_violation)
What’s Next?
Need Help?