Quickstart
Get Claude working in your application with a single TypeScript file.
Prerequisites
1. Create Your Project
Create a new directory and install the SDK:
mkdir my-chucky-app && cd my-chucky-app
npm init -y
npm install @chucky.cloud/sdk
npm install -D tsx typescript @types/node
2. Set Your Credentials
export CHUCKY_PROJECT_ID="your-project-id"
export CHUCKY_HMAC_SECRET="your-hmac-secret"
3. Create quickstart.ts
Create a file called quickstart.ts:
import {
ChuckyClient,
createToken,
createBudget,
getResultText,
} from '@chucky.cloud/sdk';
// Verify environment variables
const PROJECT_ID = process.env.CHUCKY_PROJECT_ID;
const HMAC_SECRET = process.env.CHUCKY_HMAC_SECRET;
if (!PROJECT_ID || !HMAC_SECRET) {
console.error('Error: Missing required environment variables.');
console.error('Please set CHUCKY_PROJECT_ID and CHUCKY_HMAC_SECRET');
console.error('Get these from: https://app.chucky.cloud/project/settings');
process.exit(1);
}
async function main() {
console.log('Connecting to Chucky...');
// Create a token (in production, do this server-side)
const token = await createToken({
userId: 'quickstart-user',
projectId: PROJECT_ID,
secret: HMAC_SECRET,
expiresIn: 3600, // 1 hour
budget: createBudget({
aiDollars: 1.0, // $1 budget
computeHours: 1,
window: 'day',
}),
});
// Create the Chucky client
const client = new ChuckyClient({ token });
try {
// Send a prompt and get the result
const result = await client.prompt(
'What is 2 + 2? Answer with just the number.',
{ model: 'claude-sonnet-4-5-20250929' }
);
// Extract and print the result
const text = getResultText(result);
console.log('Claude:', text);
console.log('Done! Session completed.');
} catch (error) {
console.error('Error:', error);
throw error;
} finally {
// Always close the client to release resources
client.close();
}
}
main().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});
4. Run It
Expected Output
Output below is representative. Actual Claude responses and timing will vary based on the model’s response.
Connecting to Chucky...
Claude: 4
Done! Session completed.
What Just Happened?
- Token creation - The
createToken() function generates a JWT that authenticates your user and sets their budget limits
- Client connection -
ChuckyClient connects to Chucky’s secure WebSocket endpoint
- Prompt execution -
client.prompt() sends your message to Claude and returns the complete response
- Result extraction -
getResultText() extracts the text response from the result object
- Clean shutdown -
client.close() properly closes the connection
Next Steps
Multi-turn Conversations
Build interactive chat experiences with session memory
Add Custom Tools
Let Claude interact with your APIs and services
Authentication Deep Dive
Understand tokens, budgets, and security
Other Languages
Python, Go, and PHP SDK documentation