Skip to main content

ResponseCX Quickstart

Get from zero to a working ResponseCX agent using the SDK.

Prerequisites

  • StateSet account with ResponseCX enabled
  • API key from your dashboard
  • Node.js 16+
Set your key in the environment:
export STATESET_API_KEY=sk_test_your_actual_key_here

1. Install the SDK

npm install stateset-node dotenv winston

2. Initialize a client

import { StateSetClient } from 'stateset-node';
import dotenv from 'dotenv';
import winston from 'winston';

dotenv.config();

const logger = winston.createLogger({
  level: process.env.LOG_LEVEL || 'info',
  transports: [new winston.transports.Console()]
});

const client = new StateSetClient({
  apiKey: process.env.STATESET_API_KEY
});

3. Create an agent

async function createAgent() {
  try {
    const agent = await client.agents.create({
      name: 'My Agent',
      description: 'My first ResponseCX agent'
    });

    logger.info('Agent created', { agentId: agent.id });
    return agent;
  } catch (error) {
    logger.error('Agent creation failed', {
      message: error.message,
      requestId: error.request_id
    });
    throw error;
  }
}

4. Add a rule (optional)

async function createRule(agentId) {
  try {
    const rule = await client.rules.create({
      name: 'Always Respond Politely',
      description: 'Be friendly and concise',
      agent_id: agentId
    });

    logger.info('Rule created', { ruleId: rule.id });
    return rule;
  } catch (error) {
    logger.error('Rule creation failed', { message: error.message });
    throw error;
  }
}

5. Add an attribute (optional)

async function createAttribute(agentId) {
  return client.attributes.create({
    name: 'Confident',
    description: 'Authoritative but approachable',
    value: 15,
    agent_id: agentId
  });
}

6. Create your first response

async function createResponse() {
  const response = await client.response.create({
    ticket_url: 'https://yourapp.com/tickets/123',
    channel: 'Email',
    customer_message: 'Explain the importance of fast language models',
    agent_response: 'Fast models reduce latency, enable real-time UX, and lower costs.'
  });

  logger.info('Response created', { responseId: response.id });
  return response;
}

Next steps