pub async fn api<L: Loadable>(config: L) -> Result<OrtApi>Expand description
Loads an ort-compatible ONNX Runtime API from config.
Returns an error if:
- The requested feature set is not supported by
ort-web. - The JavaScript/WASM modules fail to load.
config can be a feature set, in which case the default pyke-hosted builds will be used:
use ort::session::Session;
use ort_web::{FEATURE_WEBGL, FEATURE_WEBGPU};
async fn init_model() -> anyhow::Result<Session> {
// This must be called at least once before using any `ort` API.
ort::set_api(ort_web::api(FEATURE_WEBGL | FEATURE_WEBGPU).await?);
let session = Session::builder()?.commit_from_url("https://...").await?;
Ok(session)
}You can also use Dist to self-host the build:
use ort::session::Session;
use ort_web::Dist;
async fn init_model() -> anyhow::Result<Session> {
let dist = Dist::new("https://cdn.jsdelivr.net/npm/onnxruntime-web@1.23.0/dist/")
// load the WebGPU build
.with_script_name("ort.webgpu.min.js");
ort::set_api(ort_web::api(dist).await?);
}