> ## 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.

# Quick Start

> Get Threadify running in 5 minutes

## 1.  and Install the SDK

<Tabs>
  <Tab title="JavaScript">
    ```bash theme={null}
    npm install @threadify/sdk
    ```
  </Tab>

  <Tab title="Go">
    ```bash theme={null}
    go get github.com/ThreadifyDev/go-sdk
    ```
  </Tab>

  <Tab title="Python">
    ```bash theme={null}
    pip install threadify-sdk
    ```
  </Tab>
</Tabs>

## 2. Connect to Threadify

<Note>
  Need an API key? Create an [account](https://threadify.dev/signup) and [Generate one here](https://threadify.dev/u/api-keys) to get started.
</Note>

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    import { Threadify } from '@threadify/sdk';

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

  <Tab title="Go">
    ```go theme={null}
    ctx := context.Background()
    conn, err := threadify.Connect(ctx, "your-api-key", 
        threadify.WithServiceName("my-service"),
    )
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from threadify import Threadify

    # Connect with your API key and service name
    connection = await Threadify.connect(
        "your-api-key",
        service_name="my-service",
    )
    ```
  </Tab>
</Tabs>

## 3. Create Your First Thread

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    // 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');
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // 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)
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # 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")
    ```
  </Tab>
</Tabs>

## 4. Add Steps to Your Process

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    // 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();
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // 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)
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # 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()
    )
    ```
  </Tab>
</Tabs>

## 5. Handle Failures

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    // 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'
      });
    }
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // 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)
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # 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"
        })
    ```
  </Tab>
</Tabs>

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

Subscribe to WebSocket events to react to execution graph changes in real-time.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    // 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();
    });
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // 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)
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # 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)
    ```
  </Tab>
</Tabs>

## What's Next?

* [Installation Guide](/installation) - Detailed setup for production
* [API Reference](/api/overview) - Complete API documentation
* [SDK Guide](/sdk/overview) - Advanced SDK features
* [Creating Contracts](/guides/creating-contracts) - Define business rules

## Need Help?

* Check our [troubleshooting guide](/guides/troubleshooting)
* Visit our [GitHub discussions](https://github.com/yourusername/threadify/discussions)
* Contact support at [support@threadify.dev](mailto:support@threadify.dev)
