Skip to main content

Quickstart

This guide will help you integrate Claude into your application using the Chucky SDK.

Prerequisites

  • A Chucky account with a project created at app.chucky.cloud
  • Your Project ID and HMAC Secret (found in project settings)
  • Node.js 18+, Python 3.10+, Go 1.21+, or PHP 8.1+

Installation

npm install @chucky.cloud/sdk

Step 1: Create a Token (Server-Side)

Tokens authenticate users and set their usage budgets. Always create tokens on your server - never expose your HMAC secret to clients.
import { createToken, createBudget } from '@chucky.cloud/sdk';

// Create a token for a user
const token = await createToken({
  userId: 'user-123',
  projectId: process.env.CHUCKY_PROJECT_ID,  // From portal
  secret: process.env.CHUCKY_HMAC_SECRET,    // From portal
  expiresIn: 3600,                            // 1 hour
  budget: createBudget({
    aiDollars: 1.00,               // $1 AI budget
    computeHours: 1,               // 1 hour compute
    window: 'day',                 // Resets daily
  }),
});

// Return token to client
return { token };

Step 2: Use the SDK (Client-Side)

Once your client has a token, they can use the SDK to interact with Claude.

Simple Prompt

import { ChuckyClient } from '@chucky.cloud/sdk';

const client = new ChuckyClient({ token });

// One-shot prompt
const result = await client.prompt(
  'What is the capital of France?',
  { model: 'claude-sonnet-4-5-20250929' }
);

if (result.subtype === 'success') {
  console.log(result.result); // "The capital of France is Paris."
  console.log(result.total_cost_usd); // 0.0012
}

Multi-Turn Conversation (V2 Interface)

import { ChuckyClient, getAssistantText } from '@chucky.cloud/sdk';

const client = new ChuckyClient({ token });

// Create a session
const session = client.createSession({
  model: 'claude-sonnet-4-5-20250929',
  systemPrompt: 'You are a helpful geography tutor.',
});

// First message
await session.send('What is the capital of France?');
for await (const msg of session.stream()) {
  if (msg.type === 'assistant') {
    console.log(getAssistantText(msg)); // "The capital of France is Paris."
  }
  if (msg.type === 'result') {
    console.log('Cost:', msg.total_cost_usd);
  }
}

// Follow-up (Claude remembers context)
await session.send('What about Germany?');
for await (const msg of session.stream()) {
  if (msg.type === 'assistant') {
    console.log(getAssistantText(msg)); // "The capital of Germany is Berlin."
  }
}

// Close when done
session.close();

Streaming Responses

import { ChuckyClient, getAssistantText } from '@chucky.cloud/sdk';

const client = new ChuckyClient({ token });
const session = client.createSession();

await session.send('Write a haiku about coding');
for await (const msg of session.stream()) {
  if (msg.type === 'assistant') {
    process.stdout.write(getAssistantText(msg) || '');
  }
  if (msg.type === 'result' && msg.subtype === 'success') {
    console.log('\n\nFinal result:', msg.result);
  }
}

session.close();

Step 3: Add Tools (Optional)

Give Claude the ability to take actions in your application.
import { ChuckyClient, tool, getAssistantText } from '@chucky.cloud/sdk';

// Define a tool
const weatherTool = tool(
  'get_weather',
  'Get current weather for a city',
  {
    type: 'object',
    properties: {
      city: { type: 'string', description: 'City name' },
    },
    required: ['city'],
  },
  async ({ city }) => {
    // Your implementation
    const weather = await fetchWeather(city);
    return { content: [{ type: 'text', text: `${city}: ${weather}` }] };
  }
);

// Use tools in a session
const client = new ChuckyClient({ token });
const session = client.createSession({
  tools: [weatherTool],
});

await session.send('What is the weather in Tokyo?');
for await (const msg of session.stream()) {
  if (msg.type === 'assistant') {
    console.log(getAssistantText(msg));
  }
}
// Claude will call get_weather, then respond with the result

session.close();

Next Steps