checkCapability()
Standalone function to detect device capabilities without creating a client. Returns comprehensive information about WebGPU availability, GPU hardware, estimated VRAM, device performance grade, network connection, battery status, and system memory.
Signature
function checkCapability(): Promise<CapabilityReport>;Return Value
CapabilityReport
interface CapabilityReport { webgpu: boolean; gpu: GpuInfo | null; grade: DeviceGrade; connection: ConnectionInfo; battery: BatteryInfo | null; memory: number;}webgpu
Whether WebGPU is available in the current browser.
- Type:
boolean true- WebGPU is supported and accessiblefalse- WebGPU is not available (unsupported browser or disabled)
gpu
GPU hardware information, or null if WebGPU is not available.
- Type:
GpuInfo | null
interface GpuInfo { vendor: string; name: string; vram: number;}Fields:
vendor- GPU vendor (e.g.,'Apple','NVIDIA','AMD','Intel')name- GPU model name (e.g.,'Apple M3 Pro','NVIDIA GeForce RTX 4090')vram- Estimated VRAM in megabytes, derived frommaxStorageBufferBindingSize
grade
Device performance grade based on VRAM estimation.
- Type:
DeviceGrade
type DeviceGrade = 'S' | 'A' | 'B' | 'C';Grades:
'S'- High-end (≥8GB VRAM) - Uses high tier: Llama-3.1-8B'A'- Mid-high (≥4GB VRAM) - Uses high tier: Llama-3.1-8B'B'- Mid-low (≥2GB VRAM) - Uses medium tier: Phi-3.5-mini-instruct'C'- Low-end (<2GB VRAM) - Uses low tier: Qwen2.5-1.5B
Note: All grades support local inference. Grade C uses optimized lightweight models.
connection
Network connection information from the Network Information API.
- Type:
ConnectionInfo
interface ConnectionInfo { effectiveType: '4g' | '3g' | '2g' | 'slow-2g' | 'unknown'; downlink?: number; rtt?: number; saveData?: boolean;}Fields:
effectiveType- Connection quality estimatedownlink- Downlink speed in Mbps (optional)rtt- Round-trip time in ms (optional)saveData- Whether data saver mode is enabled (optional)
battery
Battery status from the Battery Status API, or null if unavailable.
- Type:
BatteryInfo | null
interface BatteryInfo { charging: boolean; level: number;}Fields:
charging- Whether the device is charginglevel- Battery level from 0.0 to 1.0
memory
System memory (RAM) in gigabytes, estimated from navigator.deviceMemory.
- Type:
number - Falls back to
4if unavailable
Examples
Basic usage
import { checkCapability } from '@webllm-io/sdk';
const report = await checkCapability();
console.log('WebGPU:', report.webgpu);console.log('Device grade:', report.grade);
if (report.gpu) { console.log(`GPU: ${report.gpu.vendor} ${report.gpu.name}`); console.log(`VRAM: ${report.gpu.vram}MB`);}Conditional feature enablement
const cap = await checkCapability();
if (!cap.webgpu) { alert('WebGPU not supported. Local inference unavailable.'); // Use cloud-only mode}
// All grades support local inference when WebGPU is availableenableLocalInference();Display device info in UI
import { checkCapability } from '@webllm-io/sdk';import { useEffect, useState } from 'react';
function DeviceInfo() { const [cap, setCap] = useState(null);
useEffect(() => { checkCapability().then(setCap); }, []);
if (!cap) return <div>Detecting capabilities...</div>;
return ( <div> <h3>Device Information</h3> <p>WebGPU: {cap.webgpu ? '✓ Available' : '✗ Not available'}</p> <p>Grade: {cap.grade}</p> {cap.gpu && ( <> <p>GPU: {cap.gpu.vendor} {cap.gpu.name}</p> <p>VRAM: {cap.gpu.vram}MB</p> </> )} <p>RAM: {cap.memory}GB</p> <p>Network: {cap.connection.effectiveType}</p> {cap.battery && ( <p>Battery: {Math.round(cap.battery.level * 100)}% {cap.battery.charging && ' (charging)'} </p> )} </div> );}Select model based on device grade
const cap = await checkCapability();
let model: string;switch (cap.grade) { case 'S': model = 'Llama-3.1-8B-Instruct-q4f16_1-MLC'; break; case 'A': model = 'Llama-3.1-8B-Instruct-q4f16_1-MLC'; break; case 'B': model = 'Phi-3.5-mini-instruct-q4f16_1-MLC'; break; case 'C': model = 'Qwen2.5-1.5B-Instruct-q4f16_1-MLC'; break;}
const client = createClient({ local: { model }});Adaptive loading strategy
const cap = await checkCapability();
// Use cloud fallback on slow networkconst useCloud = cap.connection.effectiveType === 'slow-2g' || cap.connection.effectiveType === '2g';
// Disable cache on low storageconst useCache = cap.grade !== 'C';
// Use WebWorker unless battery is lowconst useWebWorker = !cap.battery || cap.battery.level > 0.2;
const client = createClient({ local: useCloud ? false : { model: 'auto', useCache, useWebWorker }, cloud: useCloud ? process.env.OPENAI_API_KEY : undefined});Check before showing UI
async function initializeApp() { const cap = await checkCapability();
if (!cap.webgpu && !cloudAPIKey) { showErrorScreen('WebGPU not supported and no cloud API key configured'); return; }
if (cap.grade === 'C' && cap.connection.effectiveType === 'slow-2g') { showWarning('Slow network detected. Performance may be degraded.'); }
// Proceed with initialization const client = createClient({ local: cap.webgpu ? 'auto' : false, cloud: cloudAPIKey });}Debug logging
const cap = await checkCapability();
console.table({ 'WebGPU': cap.webgpu, 'Grade': cap.grade, 'Vendor': cap.gpu?.vendor || 'N/A', 'GPU': cap.gpu?.name || 'N/A', 'VRAM': cap.gpu ? `${cap.gpu.vram}MB` : 'N/A', 'RAM': `${cap.memory}GB`, 'Network': cap.connection.effectiveType, 'Battery': cap.battery ? `${Math.round(cap.battery.level * 100)}%` : 'N/A', 'Charging': cap.battery?.charging || false});Browser Compatibility
- WebGPU detection: All browsers (returns
falseif unsupported) - GPU info: Chrome 113+, Edge 113+, Safari 18+ (requires WebGPU)
- Network info: Chrome, Edge, Opera (partial support)
- Battery info: Chrome, Edge, Opera (deprecated in some browsers)
- Memory info: Chrome 63+, Edge 79+, Opera 50+
Unsupported features gracefully degrade with fallback values.
See Also
- createClient() - Client creation
- WebLLMClient - Client interface (has
capability()method) - Config Types - Configuration options