Next

How can we implement AI integration using Vercel AI SDK in Next.js 16 Edge Functions?

November 28, 2025

download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!

You can integrate AI in Next.js 16 Edge Functions using the Vercel AI SDK to easily call language models, handle streaming, and serve AI-powered responses at the edge, improving latency and scaling.

To implement AI integration with Vercel AI SDK in Next.js 16 Edge Functions, first install the SDK packages. Then create an Edge API Route or Server Component that imports the SDK functions (like streamText or generateText) and calls an AI model (e.g., Google Gemini). Use the streaming response utilities to send AI-generated results progressively. Set the route’s runtime to edge for low latency worldwide. This leverages Vercel’s AI Gateway to manage provider integration, caching, and scaling transparently.

Code

// app/api/ai/route.ts
import { streamText, StreamingTextResponse } from 'ai';
import { google } from '@ai-sdk/google';

export const runtime = 'edge';

export async function POST(req: Request) {
  const { prompt } = await req.json();

  const response = await streamText({
    model: google('models/gemini-1.5-pro-latest'),
    prompt,
  });
  return new StreamingTextResponse(response);
}
Hire Now!

Need Help with Next Development ?

Work with our skilled next developers to accelerate your project and boost its performance.
**Hire now**Hire Now**Hire Now**Hire now**Hire now