Skip to content

Errors

All errors thrown by the SDK are instances of WebLLMError, which extends the native Error class with a typed error code.

WebLLMError

class WebLLMError extends Error {
code: WebLLMErrorCode;
cause?: unknown;
constructor(code: WebLLMErrorCode, message: string, cause?: unknown);
}

Properties

PropertyTypeDescription
codeWebLLMErrorCodeMachine-readable error category
messagestringHuman-readable error description
causeunknownOriginal error that caused this error (if any)
namestringAlways 'WebLLMError'

Error Codes

type WebLLMErrorCode =
| 'WEBGPU_NOT_AVAILABLE'
| 'MODEL_LOAD_FAILED'
| 'INFERENCE_FAILED'
| 'CLOUD_REQUEST_FAILED'
| 'NO_PROVIDER_AVAILABLE'
| 'ABORTED'
| 'TIMEOUT'
| 'QUEUE_FULL';

Reference

CodeWhenRecoverable?
WEBGPU_NOT_AVAILABLEBrowser does not support WebGPU or no adapter foundUse cloud fallback
MODEL_LOAD_FAILEDModel download, compilation, or initialization failedRetry or use cloud
INFERENCE_FAILEDLocal inference produced an error during generationSDK auto-falls back to cloud if configured
CLOUD_REQUEST_FAILEDCloud API returned an error or network failureCheck API key, URL, connectivity
NO_PROVIDER_AVAILABLENeither local nor cloud backend is configured or usableConfigure at least one provider
ABORTEDRequest was cancelled via AbortSignalIntentional — no fallback attempted
TIMEOUTCloud request exceeded the configured timeoutIncrease timeout or retry
QUEUE_FULLLocal inference queue is at capacityWait and retry

Error Handling

Basic

import { WebLLMError } from '@webllm-io/sdk';
try {
const res = await client.chat.completions.create({
messages: [{ role: 'user', content: 'Hello' }],
});
} catch (err) {
if (err instanceof WebLLMError) {
switch (err.code) {
case 'ABORTED':
// User cancelled — ignore
break;
case 'NO_PROVIDER_AVAILABLE':
showSetupInstructions();
break;
default:
showErrorToast(err.message);
}
}
}

Checking the Cause

The cause property preserves the original error for debugging:

try {
await client.chat.completions.create({ ... });
} catch (err) {
if (err instanceof WebLLMError && err.code === 'CLOUD_REQUEST_FAILED') {
console.error('Cloud error:', err.message);
console.error('Original error:', err.cause);
}
}

Automatic Fallback

The SDK automatically handles some error scenarios:

  • Local inference fails → falls back to cloud (if configured)
  • Cloud fails → falls back to local (if loaded and ready)
  • Request aborted → no fallback (intentional cancellation)

This means many errors are handled transparently. You only see errors when all fallback options are exhausted.