DEV Community

Alex Spinov
Alex Spinov

Posted on

Vercel AI SDK Has a Free Library for Building AI Apps with Streaming

Vercel AI SDK gives you streaming LLM responses, tool calling, structured output, and framework integrations. Build ChatGPT-like apps in hours.

Why AI SDK

Calling LLM APIs directly: manual streaming, manual tool calling, manual retry logic, different APIs for each provider.

AI SDK: one API for OpenAI, Anthropic, Google, Mistral, and 20+ providers.

What You Get for Free

Streaming text generation:

import { generateText, streamText } from 'ai';
import { openai } from '@ai-sdk/openai';

// Streaming
const result = await streamText({
  model: openai('gpt-4o'),
  prompt: 'Explain quantum computing in simple terms',
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}
Enter fullscreen mode Exit fullscreen mode

Structured output (JSON):

import { generateObject } from 'ai';
import { z } from 'zod';

const { object } = await generateObject({
  model: openai('gpt-4o'),
  schema: z.object({
    recipe: z.object({
      name: z.string(),
      ingredients: z.array(z.string()),
      steps: z.array(z.string()),
    }),
  }),
  prompt: 'Generate a pasta recipe',
});
// object.recipe is fully typed
Enter fullscreen mode Exit fullscreen mode

Tool calling:

const result = await generateText({
  model: openai('gpt-4o'),
  tools: {
    getWeather: {
      description: 'Get weather for a city',
      parameters: z.object({ city: z.string() }),
      execute: async ({ city }) => {
        return await fetchWeather(city);
      },
    },
  },
  prompt: 'What is the weather in Tokyo?',
});
Enter fullscreen mode Exit fullscreen mode

React hooks:

import { useChat } from 'ai/react';

function Chat() {
  const { messages, input, handleSubmit, handleInputChange } = useChat();
  return (
    <div>
      {messages.map(m => <div key={m.id}>{m.role}: {m.content}</div>)}
      <form onSubmit={handleSubmit}>
        <input value={input} onChange={handleInputChange} />
      </form>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

Complete chat UI with streaming in 15 lines.

Provider Support

OpenAI, Anthropic, Google (Gemini), Mistral, Cohere, Amazon Bedrock, Azure OpenAI, Groq, Perplexity, Fireworks — swap provider by changing one line.

If you're building an AI-powered app — AI SDK eliminates weeks of infrastructure code.


Need web scraping or data extraction? Check out my tools on Apify — get structured data from any website in minutes.

Custom solution? Email spinov001@gmail.com — quote in 2 hours.

Top comments (0)