Integrate animated AI avatars into your applications with our TypeScript SDK. Built-in caching, rate limiting, and full type definitions.
npm install @varie-ai/avatar-sdkDiscover characters, download models, and render with Spine in just a few lines:
Browse available characters
Fetch the model (cached)
Load into Spine runtime
import { VarieAvatarSDK } from '@varie-ai/avatar-sdk';
const sdk = new VarieAvatarSDK();
// 1. Discover available characters
const { characters } = await sdk.discover({
genre: 'fantasy',
limit: 10
});
// 2. Get character details
const character = await sdk.getCharacter(characters[0].id);
console.log(character.name, character.tagline);
// 3. Download the Spine model (cached automatically)
const model = await sdk.downloadModel(character.id, {
type: 'full',
onProgress: (p) => console.log(`${p.percent}%`)
});
// Ready for Spine runtime
const { skeleton, atlas, texture } = model.files;sdk.discover()discover(options?: DiscoverOptions): Promise<DiscoverResponse>List available characters with optional filters. Results are cached for 1 hour.
// Discover with filters
const { characters, pagination } = await sdk.discover({
genre: 'fantasy', // Filter by genre
limit: 20, // Max results (1-50)
cursor: nextCursor // Pagination
});
// Each character includes:
// - id, name, tagline, story
// - genre, personalityTags
// - avatarUrl (thumbnail)
// - publicModel.status ('full_ready' | 'base_ready')sdk.getCharacter()getCharacter(id: string, skipCache?: boolean): Promise<Character>Get full details for a specific character. Cached for 1 week.
// Get full character details
const character = await sdk.getCharacter('soren_cb3333dd3e3f');
console.log(character.name); // "Soren"
console.log(character.tagline); // "A mysterious wanderer..."
console.log(character.personalityTags); // ["mysterious", "wise", "calm"]
console.log(character.quotes); // Character-voice quotes
console.log(character.story); // Full backstorysdk.downloadModel()downloadModel(characterId: string, options?: DownloadOptions): Promise<UnpackedModel>Download and unpack a character's Spine model. Automatically cached in IndexedDB.
// Download and unpack model
const model = await sdk.downloadModel(characterId, {
type: 'full', // 'full' (~6-10MB) or 'base' (~3-5MB)
cache: true, // Cache in IndexedDB (default: true)
onProgress: (p) => console.log(`${p.percent}%`)
});
// Unpacked files ready for Spine runtime
const { skeleton, atlas, texture } = model.files;
// skeleton: parsed JSON
// atlas: atlas text
// texture: PNG BlobModels are Spine 4.x format. All characters include idle animations, emotional expressions, talking animations with lip sync, and eye tracking support.
// Using with Spine runtime
const model = await sdk.downloadModel(characterId);
// Create texture from blob
const textureUrl = URL.createObjectURL(model.files.texture);
const image = new Image();
image.src = textureUrl;
await new Promise(resolve => image.onload = resolve);
// Load into Spine
const atlas = new spine.TextureAtlas(model.files.atlas);
const skeletonJson = new spine.SkeletonJson(
new spine.AtlasAttachmentLoader(atlas)
);
const skeletonData = skeletonJson.readSkeletonData(model.files.skeleton);
const skeleton = new spine.Skeleton(skeletonData);
// Play animations
animationState.setAnimation(0, 'idle', true);
animationState.setAnimation(1, 'happy', false); // Layer expressionThe SDK handles caching and rate limiting automatically. Customize the behavior with options:
// SDK Configuration
const sdk = new VarieAvatarSDK({
cacheEnabled: true, // Enable IndexedDB caching
rateLimitPerSecond: 5, // Client-side rate limiting
discoverCacheTTL: 3600000, // 1 hour for character lists
characterCacheTTL: 604800000 // 1 week for character details
});
// Cache management
const stats = await sdk.getCacheStats();
console.log(stats.modelCount, stats.totalSize);
await sdk.clearCache(); // Clear all cached dataThe SDK throws typed errors with specific codes for easy handling:
import { SDKError, SDKErrorCode } from '@varie-ai/avatar-sdk';
try {
const model = await sdk.downloadModel(characterId);
} catch (err) {
if (err instanceof SDKError) {
switch (err.code) {
case SDKErrorCode.NOT_FOUND:
console.log('Character not found');
break;
case SDKErrorCode.MODEL_NOT_AVAILABLE:
console.log('Model not ready yet');
break;
case SDKErrorCode.RATE_LIMITED:
console.log('Too many requests');
break;
}
}
}Models cached in IndexedDB (browser) or memory (Node.js). Character lists cached 1 hour, details cached 1 week.
Built-in request throttling ensures smooth operation and prevents accidental request bursts.
Full type definitions for all methods, options, and responses. Works with any TypeScript project.
.varie bundles are automatically unpacked into skeleton, atlas, and texture files ready for Spine.
Install the SDK and browse 100+ characters ready to use.