Skip to content

Introduction

rxjs-ai is a stream-first AI SDK built on RxJS for building AI-native applications. It gives you reusable, type-safe primitives that treat streaming as a first-class concept — not an afterthought.

import { createChatController, createViewModel } from 'rxjs-ai';
const chat = createChatController(model);
// Every piece of state is an Observable
chat.messages$.subscribe(console.log);
chat.status$.subscribe(console.log);
// Send a message — streaming happens automatically
chat.send('Explain quantum computing');
// Cancel mid-stream — one call, zero cleanup
chat.cancel();

AI applications are streaming-first by nature. Tokens arrive one at a time, tool calls execute mid-stream, and users expect real-time feedback. Yet most AI SDKs bolt streaming onto a Promise-based foundation:

  • Cancellation requires manually wiring AbortController signals through every layer.
  • Retry logic means writing your own loops with exponential backoff.
  • Combining streams (race two models, merge tool calls) is either unsupported or ad-hoc.
  • UI updates flood the renderer with every single token, with no built-in throttling.
  • Common patterns like reactive state and event routing require manual BehaviorSubject/Subject wiring every time.

The result is boilerplate-heavy code that fights the underlying streaming reality of AI.

rxjs-ai embraces the fact that AI is streaming and provides a small set of composable primitives:

PrimitivePurpose
createStoreReactive state container with Observable selectors
createCommandBusType-safe event bus for decoupled command handling
createAsyncControllerManages any async Observable lifecycle (loading, error, cancel, retry)
createChatControllerFull chat lifecycle — messages, status, streaming, tool calls
createViewModelDerives read-only view state from one or more stores

Each primitive is an Observable. That means the entire RxJS operator library — retry, throttleTime, race, switchMap, combineLatest, and hundreds more — works out of the box.

Capabilityrxjs-aiVercel AI SDK
Stream typeObservable<T>AsyncIterable<T>
Cancellationunsubscribe()AbortController
Retryretry(3)Manual implementation
Throttle UIthrottleTime(50)experimental_throttle
Race modelsrace(gpt$, claude$)Not supported
Reactive primitivesBuilt-in (createStore, createCommandBus, createViewModel)Bring your own
Framework supportFramework-agnosticReact-first