ONNX Runtime Web (ORT Web) is a JavaScript library designed to execute ONNX (Open Neural Network Exchange) machine learning models directly within web browsers and Node.js environments. The current stable version is 1.24.3. The project maintains a regular release cadence, with patch releases frequently published between major quarterly releases, ensuring timely bug fixes, security enhancements, and performance updates. Key differentiators include its ability to run models client-side, reducing server-client communication and enhancing user privacy. It leverages WebAssembly (WASM) for efficient CPU execution and provides GPU acceleration through WebGL (in maintenance mode) and the more modern WebGPU (experimental, launched in v1.17). ORT Web supports a broad range of ONNX operators and offers optimizations for performance and memory usage, making it suitable for deploying various AI models like image classification, object detection, and generative AI directly in web applications.
npm install onnxruntime-webVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize an ONNX Runtime Web session, configure execution providers, load a pre-trained ONNX model (MNIST example), create an input Tensor, run inference, and access the output results, including fallback strategies for execution providers.
Upgrade to `onnxruntime-web` v1.24.3 or newer immediately to mitigate known security risks. Regularly check for new patch releases.
Ensure your build environments and target devices for macOS/iOS adhere to the new minimum OS version (14.0+). Consider using pre-built artifacts if custom compilation causes issues.
Configure your web server to send `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` headers for all resources, especially those serving your ONNX model and WASM files. Verify `self.crossOriginIsolated` is true in your browser's console.
Ensure your web server (e.g., Nginx, Apache, or a bundler's dev server) is configured to serve `.wasm` files as `application/wasm` and `.mjs` files as `application/javascript`. For bundlers like Vite/Webpack, ensure the configuration properly handles these assets.
Prioritize `webgpu` in your `executionProviders` array (e.g., `['webgpu', 'wasm']`). Ensure target browsers support WebGPU and consider providing necessary cross-origin isolation headers for optimal performance.
Verify that your web server serves `.wasm` files with the `application/wasm` MIME type and that `ort.env.wasm.wasmPaths` is correctly configured to point to the directory containing the WASM files. Ensure the WASM files are in your `public` folder or a location accessible by the browser.
Use ES module syntax: `import * as ort from 'onnxruntime-web';` and then `ort.InferenceSession.create(...)`. Alternatively, `import { InferenceSession } from 'onnxruntime-web';`. Ensure your build tool (Webpack, Rollup, Vite) is configured for ES modules.Inspect your ONNX model to determine the exact input tensor names. Tools like Netron can visualize the model graph and its input/output names. Ensure the keys in your `feeds` object (`await session.run(feeds)`) precisely match these names.
Review the ONNX model's input signature (using Netron or similar tools) for the expected dimensions and data type. Ensure the `Tensor` you create (e.g., `new ort.Tensor(type, data, dims)`) exactly matches these specifications. Pay close attention to batch size (often the first dimension).
Ensure `ort.InferenceSession.create()` is called only once per model or use a single, shared session instance. If using multiple models, manage their sessions carefully. This error can also stem from underlying WASM loading issues (e.g., incorrect `wasmPaths` or MIME types) which prevented the initial `initWasm()` call from succeeding.
No dependency data recorded yet.