API Reference
Error Handling

Error Handling

All methods can throw errors that should be handled.

try {
  await browserAI.loadModel('smollm2-135m-instruct');
} catch (error) {
  console.error('Error:', error.message);
}

Common Error Types

Error TypeDescription
ModelLoadErrorFailed to load model
GenerationErrorText generation failed
AudioErrorAudio processing failed
TranscriptionErrorSpeech recognition failed

Best Practices

It's recommended to wrap all BrowserAI operations in try-catch blocks to handle potential errors gracefully. You can also use the onError callback in configuration options for specific error handling:

await browserAI.loadModel('smollm2-135m-instruct', {
  onError: (error) => {
    console.error('Model loading failed:', error.message);
    // Handle error appropriately
  }
});