Skip to content
Back to skills

Xsai Sdk

ASecurity

xsAI SDK v0.4.x API reference - extra-small AI SDK with OpenAI-compatible API

  • 57 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added May 31, 2026
ai-agentstypescriptapidocumentation

Works with

  • api

Security analysis

A100/100

Scanned May 31, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill xsai-sdk --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Xsai Sdk?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Xsai Sdk
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-xsai-sdk/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-xsai-sdk)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: xsai-sdk
description: xsAI SDK v0.4.x API reference - extra-small AI SDK with OpenAI-compatible API
globs:
  - "utils/ai-service.ts"
  - "hooks/useStreamProcessor.ts"
  - "hooks/useAiSummary.ts"
  - "hooks/useAiSettings.ts"
---

# xsAI SDK v0.4.x Quick Reference

xsAI is an extra-small AI SDK with OpenAI-compatible API interface, similar to Vercel AI SDK but much smaller.

**Project packages**: `@xsai/generate-text`, `@xsai/stream-text`, `@xsai/model`

## Core APIs

### streamText (sync call, returns StreamTextResult)

```typescript
import { streamText } from "@xsai/stream-text"

// NOTE: streamText is SYNCHRONOUS (not async) in 0.4.x
const { textStream } = streamText({
  apiKey: "...",
  baseURL: "https://api.openai.com/v1/",
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Hello" },
  ],
  streamOptions: { includeUsage: true },
})

// textStream is a ReadableStream<string>, supports async iteration
for await (const textPart of textStream) {
  console.log(textPart)
}
```

**Types:**

```typescript
interface StreamTextResult {
  textStream: ReadableStream<string>
  fullStream: ReadableStream<StreamTextEvent>
  reasoningTextStream: ReadableStream<string>
  messages: Promise<Message[]>
  steps: Promise<CompletionStep[]>
  usage: Promise<undefined | Usage>
  totalUsage: Promise<undefined | Usage>
}

interface StreamTextOptions extends ChatOptions {
  maxSteps?: number  // default: 1
  onEvent?: (event: StreamTextEvent) => Promise<unknown> | unknown
  onFinish?: (step?: CompletionStep) => Promise<unknown> | unknown
  onStepFinish?: (step: CompletionStep) => Promise<unknown> | unknown
  streamOptions?: { includeUsage?: boolean }
}

// StreamTextEvent replaces the old StreamTextChunkResult
type StreamTextEvent = /* union of stream event types */
```

### generateText (async call)

```typescript
import { generateText } from "@xsai/generate-text"

const { text, usage } = await generateText({
  apiKey: "...",
  baseURL: "https://api.openai.com/v1/",
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Why is the sky blue?" },
  ],
})
```

**Types:**

```typescript
interface GenerateTextResult {
  text?: string  // NOTE: optional in 0.4.x (was required in 0.2.x)
  usage: Usage
  finishReason: FinishReason
  messages: Message[]
  steps: CompletionStep<true>[]
  toolCalls: CompletionToolCall[]
  toolResults: CompletionToolResult[]
  reasoningText?: string
}
```

### listModels (async call)

```typescript
import { listModels } from "@xsai/model"

const models = await listModels({
  apiKey: "...",
  baseURL: "https://api.openai.com/v1/",
})
// Returns Model[] with { id, object, created, owned_by }
```

### Shared Types

```typescript
// From @xsai/shared-chat
interface ChatOptions {
  apiKey?: string
  baseURL: string
  model: string
  messages: Message[]
  // ... other OpenAI-compatible options
}

interface Usage {
  prompt_tokens: number
  completion_tokens: number
  total_tokens: number
}

type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage | DeveloperMessage
```

## Breaking Changes from 0.2.0-beta.3

| Change | 0.2.0-beta.3 | 0.4.x |
|--------|-------------|-------|
| `streamText` call | `await streamText()` (async) | `streamText()` (sync) |
| `StreamTextResult` | `{ textStream, chunkStream }` | `{ textStream, fullStream, usage: Promise, ... }` |
| Usage retrieval | Iterate `chunkStream` chunks | `await result.usage` |
| `StreamTextChunkResult` | Exists | Removed, replaced by `StreamTextEvent` |
| `textStream` type | Required `as unknown as AsyncIterable` cast | Native `ReadableStream`, supports `for await` and `pipeThrough()` |
| `generateText` result `.text` | `string` | `string \| undefined` |

## Utils

### smoothStream (from @xsai/utils-stream)

```typescript
import { smoothStream } from "@xsai/utils-stream"

const smoothed = textStream.pipeThrough(smoothStream({
  delay: 20,
  chunking: "line",
}))
```

### toAsyncIterator (polyfill for Safari)

```typescript
import { toAsyncIterator } from "@xsai/utils-stream"

// For browsers that don't support ReadableStream async iteration
const iterableStream = toAsyncIterator(textStream)
```

## Reference Documentation

- `references/index.md` - Full documentation index with all examples
- `references/docs/` - Individual package documentation (27 files with complete code examples)
- `references/type-defs/` - Deno Doc type definitions from esm.sh

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.