Skip to main content

TypeScript support

The SDK is written in TypeScript and ships full type definitions. Most apps only need classes, but you can also import types for stronger guarantees.

Publicly exported classes

import {
  IllaSDK,
  Chat,
  Prompt,
  ContextManager,
  CoreApiProvider,
  InMemoryCache,
  AsyncToolChecker,
  ChatNotFound,
  UserContextMissing,
} from '@illalabs/sdk'

Publicly exported types

import type {
  // SDK configuration
  illaSDKConfig,
  SendMessageContext,

  // Context management
  ChatContextSnapshot,
  ContextManagerOptions,
  IContextManager,

  // Caching
  CacheEntryOptions,
  ICache,
} from '@illalabs/sdk'
Note: Additional types are available from @illalabs/interfaces package for tool execution, message history, and user context.

Usage Examples

Using the ILLA SDK with types

import { IllaSDK } from '@illalabs/sdk'
import type { illaSDKConfig, SendMessageContext } from '@illalabs/sdk'

const config: illaSDKConfig = {
  apiKey: process.env.ILLA_API_KEY!,
}

const sdk = new IllaSDK(config)

// Type-safe message context
const context: SendMessageContext = {
  userContext: { address: '0x1234...' }
}

const result = await sdk.sendMessage('Hello', context)

Customize context manager

import type { ContextManagerOptions } from '@illalabs/sdk'

const options: ContextManagerOptions = {
  cacheKeyPrefix: 'illa:sdk:ctx',
  defaultToolsConfig: {
    autoRouter: { swapOrBridge: 'lifi' }
  }
}

const ctx = new ContextManager(new InMemoryCache(), options)

TTL with CacheEntryOptions

import type { CacheEntryOptions } from '@illalabs/sdk'

const options: CacheEntryOptions = { ttl: 60_000 }
await cache.set('key', value, options)

Using interfaces from @illalabs/interfaces

import type {
  MessageHistoryType,
  PendingToolCallType,
  IllaToolOutcomeJSON,
  UserContext,
} from '@illalabs/interfaces'

const userContext: UserContext = { address: '0x1234...' }
const messages: MessageHistoryType = await sdk.getMessages(chatId)

Simulation and signing types

import type {
  SimulationResult,
  AssetChange,
  GasEstimate,
  ActionMetadata,
  ContractInteraction,
  SimulationActionType,
  SignatureRequest,
  EIP712TypedData,
} from '@illalabs/interfaces'

Supported constants and values

import {
  SUPPORTED_ACTIONS,
  SUPPORTED_CHAINS,
  SUPPORTED_CHAIN_IDS,
  SUPPORTED_OPENAI_MODELS,
  SUPPORTED_OPENROUTER_MODELS,
  type SupportedAction,
  type SupportedChain,
  type SupportedChainId,
  type SupportedOpenAIModel,
  type SupportedOpenRouterModel,
} from '@illalabs/interfaces'