Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md
Moeru AI logo

xsAI

AI SDK, extra small.

One shape for every model. Web standards, nothing else.

npm version npm downloads install size license

Documentation | Getting started | Choose packages

Quick start

pnpm add xsai
import { generateText, responses } from 'xsai'

const model = responses({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: 'https://api.openai.com/v1/',
  model: 'gpt-6-luna',
})

const { text } = await generateText(model, { input: 'Say hello.' })
console.log(text)

Streaming uses the same model. Each event is a typed TextEvent in a standard ReadableStream:

import { streamText } from 'xsai'

const stream = streamText(model, { input: 'Describe a quiet forest.' })

for await (const event of stream) {
  if (event.type === 'text.delta')
    process.stdout.write(event.delta)
  if (event.type === 'step.end' && event.status === 'failed')
    throw event.error
}

Why xsAI

  • Small parts. Each package does one job. Every package is an ES module with no side effects, so your bundler removes the code that you do not use.
  • A model belongs to a protocol, not to a provider. One adapter covers every service that speaks the same protocol. Change the service, keep your code.
  • Web standards. fetch, ReadableStream, AbortSignal, and FormData. The source imports no Node.js module. Replace fetch to add a proxy, a test double, or your own retries.
  • Typed from end to end. Options, results, events, and tool inputs have TypeScript types. Schemas follow Standard Schema, so you can keep the validation library that you already use.

One adapter per protocol

xsAI does not ship a package for each provider. It ships an adapter for each protocol, and many services and gateways speak at least one of them.

ProtocolPackageFactory
OpenAI Responses@xsai/text-responsesresponses()
Chat Completions@xsai/text-chatchat()
Anthropic Messages@xsai/text-messagesmessages()

Every factory returns a LanguageModel, so generateText, streamText, and tool calls work the same with all three. If your service speaks another protocol, you can write a custom model.

Packages

Install xsai for everything, or only the packages that you use.

PackageProvides
@xsai/textgenerateText, streamText, collect, and tool
@xsai/audioSpeech generation and transcription
@xsai/decideTyped answers to yes-or-no, choice, and score questions
@xsai/embedText embeddings
@xsai/imageImage generation
@xsai/modelModel lists from a service
@xsai/sharedHTTP options, sendRequest, and error types
xsschemaSchema conversion and validation, as a separate package
xsaiOne package that re-exports everything above except xsschema

Runs anywhere

xsAI runs on any runtime with fetch and web streams: Node.js, Deno, Bun, Cloudflare Workers, and browsers.

Community projects

xsAI is used in community and in-house projects, including:

Contributing

See CONTRIBUTING.md. To edit or build the docs, see documentation maintenance.

License

MIT

Sponsors

sponsors

关于 About

🤖💬 AI SDK, extra small.
aiollamaopenaitypescriptxsai

语言 Languages

TypeScript98.2%
Shell1.8%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
189
Total Commits
峰值: 19次/周
Less
More

核心贡献者 Contributors