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:
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, andAbortSignal, and its source does not import any Node.js module. Streams areReadableStreams, you cancel a request with anAbortSignal, and you can replacefetchto 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 to | Use | Read |
|---|---|---|
| Generate or stream text, call tools, and get structured output | @xsai/text | Generate text |
| Talk to OpenAI Responses, Chat Completions, or Anthropic Messages | @xsai/text-responses, @xsai/text-chat, @xsai/text-messages | Choose an adapter |
| Generate speech or transcribe audio | @xsai/audio | Audio |
| Get typed answers to yes-or-no, choice, and score questions | @xsai/decide | Decisions |
| Embed text | @xsai/embed | Embeddings |
| Generate images | @xsai/image | Images |
| List the models of a service | @xsai/model | Models |
| Convert and validate schemas | xsschema | xsschema |
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
- Getting started installs a package and sends your first request.
- Choose packages lists every package and what it provides.
- Working with AI explains the agent skills and
llms.txtthat help AI tools write xsAI code.
Community
Ask questions and report bugs in the GitHub repository.

藍+85CD