AI SDK,
extra small.
One shape for every model. Web standards, nothing else.
13.0 KB gzipped with every package included. Install only what you use.
app.ts
import { responses, streamText } from 'xsai'
const model = responses({
apiKey: process.env.OPENAI_API_KEY,
baseURL: 'https://api.openai.com/v1/',
model: 'gpt-6-luna',
})
const { stream } = streamText(model, {
input: 'Write a haiku about small things.',
})
for await (const event of stream)
console.log(event)stream 1 / 19 events
- step.start
text
One shape, three protocols.
A model belongs to a protocol, not to a provider. Pick the adapter that your endpoint speaks. The model you get back has the same shape, so the rest of your code stays the same.
import { streamText } from '@xsai/text'
import { responses } from '@xsai/text-responses'
const model = responses({
apiKey: process.env.OPENAI_API_KEY,
baseURL: 'https://api.openai.com/v1/',
model: 'gpt-6-luna',
})
const { stream } = streamText(model, { input: 'Hello.' })
Only the marked lines change. streamText and every event after it stay the same.
Small parts.
Each package does one job and has no side effects, so your bundler drops what you do not import. Select a package to see what it brings with it. Sizes are minified and gzipped from source on every docs build.
@xsai/text-responses2.8 KBwith @xsai/shared and @xsai/text:6.1 KB
Runs on fetch and streams.
xsAI uses fetch, ReadableStream, and AbortSignal, and never imports a Node.js module. Replace fetch to add a proxy, a test double, or your own retries.
- Node.js
- Deno
- Bun
- Workers
- Browsers
Typed from end to end.
Tool inputs, results, and events are typed from your schema. The type below is real compiler output, rendered when these docs were built.
import { tool } from '@xsai/text'
import * as z from 'zod'
const weather = tool({
description: 'Get the current temperature for a city.',
execute: ({ city, unit }) => `It is 21 degrees ${unit} in ${city}.`,
inputSchema: z.object({
city: z.string(),
unit: z.enum(['celsius', 'fahrenheit']),
}),
name: 'get_weather',
})Start with one package.
Add more when you need them. Every package takes a model first, so they fit together without setup.
