Why web-ai-sdk
web-ai-sdk wraps browser-native AI APIs and WebMCP. It does not connect to hosted model providers.
Not a provider SDK
Section titled “Not a provider SDK”Provider SDKs connect applications to hosted models. They often support several providers and frameworks through a server.
Use a provider SDK when your application calls a hosted model with an API key. Use web-ai-sdk for supported browser APIs.
Separate browser capabilities
Section titled “Separate browser capabilities”Prompt uses the general LanguageModel API. The other browser APIs use different inputs and return different results.
- Translator takes a source and target language and caches a session per language pair.
- Summarizer is shaped by type (key-points, TL;DR, headlines) and length.
- Writer is parameterized by tone, format, and length.
- Rewriter applies relative shifts (shorter, longer, more formal) to existing text.
- Proofreader returns per-issue corrections with offsets into the original input.
- Detector returns a confidence-scored, sorted list of language alternates.
- WebMCP (
document.modelContext) is an agent surface, not a model surface. Tools call into the page, and it does not generate text.
For this reason, the SDK uses one package per capability.
What the SDK owns
Section titled “What the SDK owns”The SDK handles lifecycle code for each native API:
- feature detection and availability checks;
- session creation, reuse, and cleanup;
- stream normalization and
AbortSignalwiring; - opt-in result caching.
See Architecture for package boundaries. See Browser support for current availability.