API Reference
Types

Types

All types are exported from @react-ai-stream/core:

import type { Message, Role, AIClient, StreamChunk } from '@react-ai-stream/core'

Message

interface Message {
  id: string
  role: Role
  content: string
  createdAt: Date
}

Role

type Role = 'user' | 'assistant' | 'system' | 'tool'

StreamChunk

The internal format that providers yield:

type StreamChunk =
  | { type: 'text'; text: string }
  | { type: 'done' }
  | { type: 'error'; error: string }

This is the same format your custom endpoint should emit as SSE data.

AIClient

interface AIClient {
  provider: AIProvider
}
 
interface AIProvider {
  stream(messages: Message[], signal: AbortSignal): AsyncIterable<StreamChunk>
}

AIClient is what createAIClient returns and what useAIChat({ client }) accepts.