Build Smarter Apps with the AI SDK - The AI Toolkit for TypeScript

Explore how the AI SDK brings powerful AI capabilities to TypeScript developers. From integrating OpenAI models to managing tools and function calling, this toolkit simplifies the process of building intelligent, context-aware applications—all with clean, idiomatic TypeScript.

[object Object] profile picture

Abhishek Bhardwaj

- Jul 18, 2025

Build Smarter Apps with the AI SDK - The AI Toolkit for TypeScript

Overview

The AI SDK provides a unified, developer-friendly toolkit for integrating AI models into your TypeScript applications. It eliminates provider-specific complexities, allowing you to focus on building intelligent features without reinventing the wheel.

For instance, here’s how simple it is to generate text using Anthropic’s Claude model via the AI SDK:

1import { generateText } from "ai"
2import { anthropic } from "@ai-sdk/anthropic"
3
4const { text } = await generateText({
5  model: anthropic("claude-3-5-sonnet-latest"),
6  prompt: "What is love?"
7})

To get the most out of the AI SDK, it's important to understand some core AI concepts that power modern applications.

Generative Artificial Intelligence

Generative AI refers to models capable of producing content—whether it’s text, images, audio, or code—based on patterns learned from vast training datasets. These models predict what should come next based on statistical likelihood.

Examples:

  • Given a photo, a generative model can generate a caption.
  • Given an audio file, a generative model can generate a transcription.
  • Given a text description, a generative model can generate an image.

This predictive power makes generative AI a cornerstone of modern creative and productivity tools.

Large Language Models

A large language model (LLM) is a subset of generative models focused primarily on text. An LLM takes a sequence of words as input and aims to predict the most likely sequence to follow. It assigns probabilities to potential next sequences and then selects one. The model continues to generate sequences until it meets a specified stopping criterion.

LLMs learn by training on massive collections of written text, which means they will be better suited to some use cases than others. For example, a model trained on GitHub data would understand the probabilities of sequences in source code particularly well.

Embedding Models

Unlike generative models, embedding models don’t produce content—they convert data into numerical vector formats (called embeddings). These embeddings capture semantic meaning and are ideal for search, recommendation systems, clustering, and more.

Providers and Models

AI providers like OpenAI, Anthropic, and others offer access to various models, each with unique APIs and capabilities.

The AI SDK abstracts away provider-specific implementations by introducing a standardized language model interface. This makes it easy to:

  • Swap providers without major code changes
  • Avoid vendor lock-in
  • Maintain a clean, consistent codebase

Prompts

Prompts are how you instruct a language model. The quality of the prompt often determines the quality of the output. The AI SDK simplifies the process by supporting multiple types of prompts.

Text Prompts

Text prompts are straightforward string instructions. They’re perfect for generating simple outputs with minimal overhead.

You can set text prompts using the prompt property made available by AI SDK functions like streamText or generateObject. You can structure the text in any way and inject variables, e.g. using a template literal.

1const result = await generateText({
2  model: yourModel,
3  prompt: 'Invent a new holiday and describe its traditions.',
4});

Dynamic prompts can also be generated using template literals:

1const result = await generateText({
2  model: yourModel,
3  prompt:
4    `I’m planning a trip to ${destination} for ${lengthOfStay} days. ` +
5    `What are the must-visit places?`,
6});

System Prompts

System prompts act as behavioral guides. They help shape how the AI responds by providing initial instructions.

1const result = await generateText({
2  model: yourModel,
3  system:
4    `You're a travel planner. ` +
5    `Give users a personalized list of places to visit.`,
6  prompt:
7    `I’m going to ${destination} for ${lengthOfStay} days. ` +
8    `Please suggest an itinerary.`,
9});

Message Prompts

Best for multi-turn conversations (like chatbots), message prompts let you structure context-rich interactions using roles.(data) for that message type.

1const result = await streamUI({
2  model: yourModel,
3  messages: [
4    { role: 'user', content: 'Hi!' },
5    { role: 'assistant', content: 'Hello! How can I assist you?' },
6    { role: 'user', content: 'Where’s the best Currywurst in Berlin?' },
7  ],
8});

You can also mix content types in messages, such as images or files alongside text.

Tools

Large language models are excellent at reasoning—but struggle with tasks requiring precise actions, like calculations or fetching real-time data.

Tools in the AI SDK allow LLMs to "extend" their capabilities by calling functions, APIs, or executing logic as needed.

What is a tool?

A tool is a callable object that an LLM can invoke to perform a task. You can pass tools into functions like generateText or streamText.

Each tool includes:

  • Description: An optional description of the tool that can influence when the tool is picked.
  • Parameters: A Zod schema or a JSON schema that defines the parameters. The schema is consumed by the LLM, and also used to validate the LLM tool calls.
  • Execute: An optional async function that is called with the arguments from the tool call.

The AI SDK handles:

  • Tool invocation
  • Validation
  • Response injection

Streaming

Streaming lets users see AI responses as they’re being generated—just like ChatGPT. This dramatically improves user experience, especially when models take longer to respond.

Here’s why streaming is valuable:

  • Reduces perceived wait time
  • Increases interactivity for chat interfaces
  • Enables partial rendering of long content

However, if your use case involves short or real-time interactions, a simpler blocking approach may be sufficient.

With the AI SDK, setting up a streaming interface is quick and efficient:

1import { openai } from '@ai-sdk/openai';
2import { streamText } from 'ai';
3
4const { textStream } = streamText({
5  model: openai('gpt-4-turbo'),
6  prompt: 'Write a poem about embedding models.',
7});
8
9for await (const textPart of textStream) {
10  console.log(textPart);
11}

Agents

Agents are AI-powered systems that handle decision-making, perform tasks, and interact with tools or APIs. The AI SDK allows you to build agents with varying degrees of autonomy and complexity.

Building Blocks

Here are the core patterns for building intelligent agents:

1. Single-Step Generation

Make a one-off call to an LLM. Best for simple text generation or classification.

2. Tool-Enhanced Generation

Combine LLM reasoning with tools (like a weather API or database). The model can decide when and how to use tools to improve accuracy and interactivity.

Multi-step tool use is supported using the maxSteps parameter.

3. Multi-Agent Workflows

Coordinate multiple models (or agents) to solve complex problems. Each agent specializes in a different part of the workflow—like planning, execution, or validation.

This approach enables more structured, scalable AI systems.

Conclusion

The AI SDK bridges the gap between powerful language models and real-world applications by offering a consistent, intuitive API for TypeScript developers. Whether you're working with OpenAI, Anthropic, or others, the SDK streamlines integration, simplifies prompt engineering, and unlocks advanced capabilities like tool usage, agents, and streaming—all in a unified experience.

By adopting the AI SDK, you future-proof your AI stack and accelerate development while avoiding vendor lock-in. It’s the perfect toolkit for building fast, flexible, and intelligent applications in the rapidly evolving world of AI.

Start building smarter, faster, and more scalable apps today—with the AI SDK.