A TypeScript SDK for interacting with the Nano Creatures API programmatically. Create, manage, and interact with your AI creatures through a simple and intuitive interface.
npm install @nano-creatures/sdk
import { NanoCreaturesSDK } from '@nano-creatures/sdk';
// Initialize the SDK
const sdk = new NanoCreaturesSDK();
// Sign up a new user
const signUpResponse = await sdk.signUp({
email: 'user@example.com',
password: 'password123',
name: 'John Doe' // Optional
});
// Sign in
const signInResponse = await sdk.signIn({
email: 'user@example.com',
password: 'password123'
});
// Use the token for authenticated requests
const { token } = signInResponse;
// Create a new creature
const creature = await sdk.createCreature(token, {
name: 'My First Creature',
description: 'A friendly AI companion'
});
// Add a memory source to your creature (required for chat)
await sdk.createMemorySource(token, creature.id, {
name: 'Basic Knowledge',
type: 'STATIC_TEXT',
content: 'This creature is friendly and helpful. It likes to assist users with their tasks.'
});
// Now you can chat with your creature
const chatResponse = await sdk.chat(token, creature.id, {
message: 'Hello! How are you today?'
});
- Memory Source Requirement: A creature must have at least one memory source before you can chat with it. Memory sources provide the context and knowledge base that allows the creature to engage in meaningful conversations.
- Memory sources can be either static text or documents, allowing you to shape your creature's knowledge and behavior.
new NanoCreaturesSDK(config?: NanoCreaturesSDKConfig)
baseUrl
: (Optional) The base URL of the Nano Creatures API. Defaults to 'http://localhost:3000'apiKey
: (Optional) API key for authentication
async signUp(options: SignUpOptions): Promise<SignInResponse>
Creates a new user account.
options.email
: User's email addressoptions.password
: User's passwordoptions.name
: (Optional) User's name
token
: Authentication tokenuser
: User information object
async signIn(options: SignInOptions): Promise<SignInResponse>
Signs in an existing user.
options.email
: User's email addressoptions.password
: User's password
token
: Authentication tokenuser
: User information object
async getCreatures(token: string): Promise<GetCreaturesResponse>
Retrieves all creatures for the authenticated user.
async createCreature(token: string, params: CreateCreatureParams): Promise<Creature>
Creates a new creature.
token
: Authentication tokenparams.name
: Name of the creatureparams.description
: Description of the creature
async editCreature(token: string, id: string, params: UpdateCreatureParams): Promise<Creature>
Updates an existing creature.
token
: Authentication tokenid
: Creature IDparams.name
: (Optional) New name for the creatureparams.description
: (Optional) New description for the creature
async deleteCreature(token: string, id: string): Promise<void>
Deletes a creature.
async createMemorySource(
token: string,
creatureId: string,
params: CreateMemorySourceParams
): Promise<MemorySource>
Adds a new memory source to a creature. At least one memory source is required before you can start chatting with a creature.
token
: Authentication tokencreatureId
: ID of the creatureparams.name
: Name of the memory sourceparams.type
: Type of memory source ('STATIC_TEXT' | 'DOCUMENT')params.content
: (Optional) Content for STATIC_TEXT typeparams.fileUrl
: (Optional) URL for DOCUMENT typeparams.fileName
: (Optional) File name for DOCUMENT typeparams.fileSize
: (Optional) File size for DOCUMENT type
// Adding a static text memory source
await sdk.createMemorySource(token, creatureId, {
name: 'Personality',
type: 'STATIC_TEXT',
content: 'This creature is an expert in JavaScript and helps developers write better code.'
});
// Adding a document memory source
await sdk.createMemorySource(token, creatureId, {
name: 'Documentation',
type: 'DOCUMENT',
fileUrl: 'https://example.com/docs.pdf',
fileName: 'documentation.pdf',
fileSize: 1024000
});
async getMemorySources(token: string, creatureId: string): Promise<MemorySource[]>
Retrieves all memory sources for a specific creature.
token
: Authentication tokencreatureId
: ID of the creature
- Array of
MemorySource
objects
async editMemorySource(
token: string,
creatureId: string,
memorySourceId: string,
params: UpdateMemorySourceParams
): Promise<MemorySource>
Updates an existing memory source for a creature.
token
: Authentication tokencreatureId
: ID of the creaturememorySourceId
: ID of the memory source to updateparams
: Update parameters:name
: (Optional) New name for the memory sourcetype
: (Optional) New type ('STATIC_TEXT' | 'DOCUMENT')content
: (Optional) New content for STATIC_TEXT typefileUrl
: (Optional) New URL for DOCUMENT typefileName
: (Optional) New file name for DOCUMENT typefileSize
: (Optional) New file size for DOCUMENT type
async deleteMemorySource(
token: string,
creatureId: string,
memorySourceId: string
): Promise<void>
Deletes a memory source from a creature.
token
: Authentication tokencreatureId
: ID of the creaturememorySourceId
: ID of the memory source to delete
async chat(
token: string,
creatureId: string,
params: ChatParams | string
): Promise<ChatResponse>
Send a message to chat with a creature.
token
: Authentication token or API key (starting with 'sk-')creatureId
: ID of the creature to chat withparams
: Either a string message or a ChatParams object:message
: The message to sendmaxResults
: (Optional) Maximum number of results to returnsessionId
: (Optional) Session ID for continuing a conversationtemplateId
: (Optional) Template ID for specific chat behaviors
message
: The creature's responseresults
: (Optional) Additional results datasession_id
: Session ID for the conversationtimestamp
: Timestamp of the responsequery_type
: (Optional) Information about the query type
The SDK throws errors with descriptive messages when operations fail. It's recommended to wrap API calls in try-catch blocks:
try {
const creature = await sdk.createCreature(token, {
name: 'My Creature',
description: 'A helpful AI friend'
});
} catch (error) {
console.error('Failed to create creature:', error.message);
}
This SDK is written in TypeScript and includes full type definitions for all methods and responses. Import types directly from the package:
import {
NanoCreaturesSDKConfig,
SignInOptions,
SignUpOptions,
CreateCreatureParams,
Creature,
ChatParams,
ChatResponse
} from '@nano-creatures/sdk';