DEV Community

Ramandeep Singh
Ramandeep Singh

Posted on

Text Generation using Vercel AI-SDK for Next.js Projects

I came across this amazing library for building AI powered applications in Next.js projects without any knowing specific LLM provider APIs. The library is called Vercel AI-SDK.

Demo

Effortlessly build powerful text generation features in your Next.js projects with the Vercel AI-SDK!

  • Unified LLM Access: Call multiple providers (OpenAI, Anthropic, Google, Azure, and more) with a single API.
  • Multi-Modal Support: Go beyond text—work with images, audio, video, and more.
  • Seamless Next.js Integration: Just add a route.ts file to your API routes—setup takes only 2-3 lines of code.
  • Get Started: Read the docs and supercharge your app with AI in minutes.

Here is a simple example of how to use the library to generate text in a Next.js project.

import { generateText } from "ai"
import { openai } from "@ai-sdk/openai"

const { text } = await generateText({
  model: openai("gpt-4o"),
  prompt: "What is the meaning of life?",
});
Enter fullscreen mode Exit fullscreen mode

Checkout the complete setup here :
https://github.com/r123singh/mountain-llm-showcase.git

Top comments (0)