Skip to content

WebAssembly: share the API, respect the platform ​

Ambi has WASM-specific async adapters for browser deployments using OpenAI-compatible APIs or custom engines. llama-cpp is compile-time rejected on wasm32.

Minimal dependencies ​

toml
[dependencies]
ambi = { version = "0.4.1", default-features = false, features = ["openai-api"] }
tokio = { version = "1", features = ["sync", "macros"] }

Build a crate for wasm32-unknown-unknown with its usual WASM toolchain and any UI/build dependencies your application needs. The repository's examples/webAssembly contains an application-level integration example.

What changes from native? ​

CapabilityNativeBrowser WASM
OpenAI-compatible HTTPYesVia browser fetch APIs
StreamingYesVia ReadableStream adapter
Local llama.cppYesNo
Native GPU backendsFeature-dependentNo
Custom enginesSupportedSupported, subject to WASM execution constraints
Async spawningTokioWASM-local adapters

The browser's network and security model still applies: CORS and exposed API secrets are application concerns. Do not embed privileged cloud API keys in public client bundles.

Portable public APIs do not imply identical resource or thread semantics on both targets. See Architecture and Configuration.

Released under the Apache-2.0 License.