BRX Quickstart Guide

This guide will help you get started with BRX quickly. You’ll learn how to set up your environment, create your first BRK, and execute it.

Prerequisites

Before you begin, make sure you have:

  • A BRX account (sign up at app.brx.ai if you don’t have one)
  • Node.js 14+ installed (for using the Node.js SDK)
  • Basic understanding of JavaScript/TypeScript (for the examples in this guide)

Installation

Install the BRX Node.js SDK

# Using npm
npm install brx-node --save

# Using yarn
yarn add brx-node

# Using pnpm
pnpm add brx-node

Get Your API Key

  1. Log in to the BRX Dashboard
  2. Navigate to Settings > API Keys
  3. Click “Generate New API Key”
  4. Copy your API key for use in your application

Your First BRK

Let’s create a simple BRK that generates a product description based on some input parameters.

1. Initialize the BRX Client

Create a new file called index.js (or index.ts for TypeScript) and add the following code:

import BRX, { BRK } from 'brx-node';

// Initialize the BRX client with your API key
const brx = new BRX('your-api-key');

async function main() {
  // We'll add more code here
}

main().catch(console.error);

2. Create a BRK

Now, let’s create a BRK for generating product descriptions:

async function main() {
  // Define the BRK
  const createRequest = {
    modifyBrxMode: 'CREATE',
    brx: {
      brxId: 'product-description-generator',
      brxName: 'Product Description Generator',
      description: 'Generates compelling product descriptions',
      prompt: {
        prompt: new Map([
          ['main', `
            Generate a compelling product description for the following product:
            
            Product Name: {{product_name}}
            Product Category: {{product_category}}
            Key Features: {{key_features}}
            Target Audience: {{target_audience}}
            
            The description should be engaging, highlight the key features, and appeal to the target audience.
            Keep it between 100-150 words.
          `]
        ])
      },
      processParams: {
        processType: 0 // Standard processing
      },
      dependantBrxIds: new Map([
        ['main_brx_entry_schema', 'product-description-generator']
      ])
    },
    schema: {
      schemaFields: new Map([
        ['product_name', {
          fieldValueDataType: 'string',
          fieldValue: ''
        }],
        ['product_category', {
          fieldValueDataType: 'string',
          fieldValue: ''
        }],
        ['key_features', {
          fieldValueDataType: 'string',
          fieldValue: ''
        }],
        ['target_audience', {
          fieldValueDataType: 'string',
          fieldValue: ''
        }]
      ]),
      brxName: 'Product Description Generator',
      brxId: 'product-description-generator'
    }
  };

  // Send the create request
  const result = await brx.create(createRequest);
  console.log('BRK created:', result);
}

3. Use the BRK

Now that we’ve created a BRK, let’s use it to generate a product description:

async function main() {
  // ... previous code ...

  // Fetch the BRK Schema
  const productDescriptionSchema = await brx.get('product-description-generator');

  // Initialize the BRK using the schema
  const productDescription = new BRK(productDescriptionSchema);

  // Add inputs
  productDescription.input['product_name'] = 'Ultra Comfort Ergonomic Chair';
  productDescription.input['product_category'] = 'Office Furniture';
  productDescription.input['key_features'] = 'Adjustable height, lumbar support, breathable mesh, 360-degree swivel';
  productDescription.input['target_audience'] = 'Office workers, remote professionals, people who sit for long periods';

  // Run the BRK
  const descriptionResult = await brx.run(productDescription);
  
  // Print the result
  console.log('Generated Description:');
  console.log(descriptionResult[0].brxRes.output);
}

4. Run Your Code

Save your file and run it:

node index.js  # or ts-node index.ts for TypeScript

You should see a generated product description in the console output.

Next Steps

Now that you’ve created and used your first BRK, here are some next steps to explore:

Troubleshooting

Common Issues

Getting Help

If you’re still having issues, you can: