Getting started
This page installs one adapter and sends a first request. For what xsAI is and how its packages fit together, read the Introduction.
Pick the tab for the protocol that your service speaks. Choose an adapter lists the options for each one.
Generate text
sh
pnpm add @xsai/text @xsai/text-chatsh
pnpm add @xsai/text @xsai/text-responsessh
pnpm add @xsai/text @xsai/text-messagests
import { generateText } from '@xsai/text'
import { chat } from '@xsai/text-chat'
const model = chat({
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)ts
import { generateText } 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 { text } = await generateText(model, { input: 'Say hello.' })
console.log(text)ts
import { generateText } from '@xsai/text'
import { messages } from '@xsai/text-messages'
const model = messages({
apiKey: process.env.ANTHROPIC_API_KEY,
baseURL: 'https://api.anthropic.com/v1/',
model: 'claude-haiku-5.5',
})
const { text } = await generateText(model, {
input: 'Say hello.',
maxOutputTokens: 128,
})
console.log(text)The Chat and Responses examples read an OpenAI API key from OPENAI_API_KEY. The Messages example reads an Anthropic API key from ANTHROPIC_API_KEY. Each example works with any service that implements the same protocol.
chat(), responses(), and messages() create a language model that speaks one protocol. generateText sends one request, waits for the complete reply, and returns a result.
Next steps
- Stream text to show output while it arrives.
- Call tools to let the model run your functions.
- Choose packages to install only what you use.

藍+85CD