Skip to content

Why web-ai-sdk

web-ai-sdk is a TypeScript SDK for the Web AI surface: the browser-native LanguageModel (Prompt), Writer, Rewriter, Proofreader, Translator, Summarizer, LanguageDetector, and document.modelContext (WebMCP) surfaces.

It is not a provider SDK for OpenAI, Anthropic, Google AI Studio, or other server-side models. Where a tool like Vercel’s AI SDK focuses on building AI apps across model providers and frameworks (usually with a server in the loop), web-ai-sdk focuses on making the browser’s own, on-device AI APIs easier to use directly from TypeScript.

If your code calls a hosted model behind an API key, reach for a provider SDK. If your code wants to run on the model the browser ships, on-device, with no key and no server, that is what web-ai-sdk wraps.

A single text-generation model abstraction can only express one of these surfaces, LanguageModel (Prompt). The other seven cannot be funneled through it, because each carries options a text-out contract has no room for.

  • 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.

That breadth is the point, not an accident. The model abstraction is one surface among eight, so web-ai-sdk is per-capability by design, a thin layer over each, built to get thinner as the platform matures.

The Web AI surface is young and shifting. Every app that touches it re-implements the same lifecycle, so web-ai-sdk owns it once:

  • Feature detection and availability checks, with a no-op fallback when an API is missing
  • Session creation, reuse, and cleanup
  • Streaming with chunk smoothing and AbortSignal wiring
  • Opt-in result caching

You build against one stable, typed surface instead of coupling your whole app to today’s experimental API shape. See Architecture for how the packages are organized and Browser support for where each one runs today.