Skip to content

Introduction ​

xsAI is an extra-small TypeScript toolkit for building AI applications and agents. It is a set of small packages, and each package does one job. You install only the packages that you use.

The packages run on any runtime that provides fetch and web streams. This includes Node.js, Deno, Bun, Cloudflare Workers, and browsers.

Why use xsAI? ​

AI services speak a few different HTTP protocols, and each protocol has its own request and response shapes. Code that calls one service directly is hard to move to another.

xsAI hides these differences behind one shape. You create a model, then pass it to an operation:

ts
import { 
generateText
} from '@xsai/text'
const {
text
} = await
generateText
(
model
, {
input
: 'Say hello.' })
  • The model comes first. Every operation takes a model first and the request options second.
  • A model belongs to a protocol, not to a provider. One adapter covers every service that speaks the same protocol, so you can change service without changing your code.
  • Web standards. xsAI uses fetch, Request, Response, ReadableStream, Blob, FormData, and AbortSignal, and its source does not import any Node.js module. Streams are ReadableStreams, you cancel a request with an AbortSignal, and you can replace fetch to add a proxy, a test double, or your own retry logic. Schemas follow Standard Schema, so you can use the validation library that you already have.
  • Small parts. Each package does one job, and the packages work with each other without extra setup. Every package is an ES module that is free of side effects, so a bundler removes the code that you do not use.
  • Typed from end to end. Options, results, events, and tool inputs have TypeScript types.

What is in xsAI? ​

You want toUseRead
Generate or stream text, call tools, and get structured output@xsai/textGenerate text
Talk to OpenAI Responses, Chat Completions, or Anthropic Messages@xsai/text-responses, @xsai/text-chat, @xsai/text-messagesChoose an adapter
Generate speech or transcribe audio@xsai/audioAudio
Get typed answers to yes-or-no, choice, and score questions@xsai/decideDecisions
Embed text@xsai/embedEmbeddings
Generate images@xsai/imageImages
List the models of a service@xsai/modelModels
Convert and validate schemasxsschemaxsschema

Choose packages describes every package, including xsai, the single package that re-exports the others.

Model providers ​

xsAI does not ship one package for each provider. It ships one adapter for each protocol. A service works with xsAI when it implements one of these protocols:

  • OpenAI Responses, with responses().
  • Chat Completions, with chat().
  • Anthropic Messages, with messages().

Many services and gateways accept at least one of them. If yours speaks another protocol, you can write a custom model.

Where to go next ​

Community ​

Ask questions and report bugs in the GitHub repository.

Contributors

Changelog