web-ai-sdk | TypeScript SDK for the Web AI surface

web-ai-sdk

2 min read Original article ↗

BROWSER-NATIVE AI · 0 RUNTIME DEPS · Open Source OSS

The TypeScript SDK for the Web AI surface.

You can use the browser APIs directly.

web-ai-sdk handles capability checks, session reuse, stream normalization, abort signals, cleanup, and optional result caching.

See package boundaries

Prompt.

Prompt wraps the general LanguageModel API.

  • Prompt / LanguageModel only
  • Text, tools, structured output

Other capabilities.

The other APIs use different options and result types. Each has its own package.

  • Translator (source + target language, pair-cached sessions)
  • Summarizer (type and length)
  • Writer (tone, format, length)
  • Rewriter (relative tone/length shifts)
  • Proofreader (per-issue offsets)
  • Detector (confidence scores, alternates)
  • WebMCP (an agent surface, not a model)

Streaming = AsyncIterable output. Session reuse = sessions cached by config so repeat calls skip model setup (conversation turns, language pairs, task options). Result cache = opt-in memoized results. AbortSignal = cleanup wiring on unmount and abort.

@web-ai-sdk/prompt

Send prompts and manage independent sessions, streams, and abort signals.

  • Session reuse. Compatible calls reuse a cached base session.
  • Streaming first. Sessions yield deltas. ask() exposes cumulative text.
  • Clean lifecycle. Abort signals cancel runs. Leases release prepared sessions.

Each status links to its vendor source. stable = documented as on by default; Canary/Dev = Edge preview channel with the documented flag; Developer trial = Chrome's current status label, not an active public token program; OT = origin trial. Historical Writer/Rewriter (137–148) and Proofreader (141–145) Chrome origin-trial windows have ended.

Agent consumer signal, not browser support. ChatGPT Desktop Site tools are an implemented WebMCP consumer in the built-in browser only. Availability depends on the account, model, current page, and user permission. Tools do not carry after navigation. Closing the page makes them unavailable. This does not establish Chrome support or follow from engine lineage.

SDK responsibilities.

The SDK handles browser API lifecycles. This includes support checks, sessions, streams, abort signals, and cleanup.

  • Feature detection per package
  • Session cache keyed by config
  • AsyncIterable streams plus AbortSignal cleanup
  • Hot-reload and StrictMode safe
  • Zero-runtime fallback when API missing

Application responsibilities.

Application code owns UI, persistence, DOM traversal, fallbacks, and cross-capability workflows.

  • Framework-agnostic core
  • Optional /react subpath
  • No global state, no providers required
  • Tree-shakable per package
  • Pick the layers you need