SDK Reference

Use tinycrab programmatically in your TypeScript/JavaScript projects.

Installation

npm install tinycrab

Basic Usage

import { Tinycrab } from 'tinycrab';

// Initialize with API key
const tc = new Tinycrab({
  apiKey: process.env.OPENAI_API_KEY,
  dataDir: './agents', // Optional: where to store agent data
});

// Spawn an agent
const agent = await tc.agent('my-worker');

// Chat with the agent
const response = await agent.chat('Hello!');
console.log(response.content);

// Continue conversation with session
const followUp = await agent.chat('What did I just say?', {
  sessionId: response.sessionId,
});

// Clean up when done
await agent.destroy({ cleanup: true });

Tinycrab Class

new Tinycrab(options: {
  apiKey: string;      // LLM provider API key
  dataDir?: string;    // Default: './.tinycrab'
  provider?: string;   // Default: 'openai'
  model?: string;      // Default: provider's default
})

Agent Methods

// Spawn or get existing agent
const agent = await tc.agent(id: string);

// Chat with agent
const response = await agent.chat(message: string, options?: {
  sessionId?: string;  // Continue existing session
});

// Clean up
await agent.destroy(options?: {
  cleanup?: boolean;   // Delete all files (default: false)
});