Overview of AI SDK Core for LLM integration
mainAI SDK Core provides a standardized way to integrate Large Language Models (LLMs) into your applications, allowing you to focus on building AI features rather than handling technical integration details. It offers a unified API for text generation, structured data output, and tool usage across different model providers.
The core functions are:
- generateText: Generates text and tool calls. Ideal for non-interactive automation tasks like drafting emails or summarizing content.
- streamText: Streams text and tool calls. Designed for interactive use cases like chat bots and content streaming.
Both functions support structured output via the output property (e.g., Output.object(), Output.array()), enabling typed, schema-validated data generation for extraction, classification, and streaming UIs.
// Example: Using generateText for automation
import { generateText } from 'ai';
const { text, toolCalls } = await generateText({
model: myModel,
prompt: 'Summarize this article: ...',
output: 'object',
schema: z.object({ summary: z.string() })
});
// Example: Using streamText for interactive chat
import { streamText } from 'ai';
const stream = await streamText({
model: myModel,
prompt: 'Hello, how can I help?',
});
for await (const chunk of stream.textStream) {
console.log(chunk);
}