import { RunAnywhere, SDKEnvironment } from '@runanywhere/core'await RunAnywhere.initialize({ environment: SDKEnvironment.Development, // No API key needed})
// Load the model into memory (loadModel takes a file path, not a model ID)const modelInfo = await RunAnywhere.getModelInfo('smollm2-360m')await RunAnywhere.loadModel(modelInfo.localPath)// Load STT model (requires path AND engine name)const sttInfo = await RunAnywhere.getModelInfo('whisper-tiny-en')await RunAnywhere.loadSTTModel(sttInfo.localPath, 'whisper')// Load TTS model (requires path AND engine name)const ttsInfo = await RunAnywhere.getModelInfo('piper-en-lessac')await RunAnywhere.loadTTSModel(ttsInfo.localPath, 'piper')// Simple chatconst response = await RunAnywhere.chat('What is 2+2?')console.log(response) // "4"// Or with full metricsconst result = await RunAnywhere.generate('Write a haiku about coding', { maxTokens: 50 })console.log('Response:', result.text)console.log('Tokens/sec:', result.performanceMetrics.tokensPerSecond)
Unlike LLM loading which takes just a file path, STT and TTS model loading requires both the file
path AND the engine name ('whisper' for STT, 'piper' for TTS). Use getModelInfo() to
retrieve the downloaded model’s local path.
const streamResult = await RunAnywhere.generateStream('Tell me a story about AI', { maxTokens: 200,})// Accumulate and display tokens as they arrivelet fullResponse = ''for await (const token of streamResult.stream) { fullResponse += token setResponse(fullResponse) // Update UI state}// Get final metrics (LLMGenerationResult has tokensPerSecond at top level)const finalResult = await streamResult.resultconsole.log('Speed:', finalResult.tokensPerSecond, 'tok/s')