Vercel AI SDK

Next.js AI routes backed by TheRouter.ai

Vercel AI SDK integrates cleanly with TheRouter.ai providers and keeps your existing stream APIs while expanding model access.

Overview

This page mirrors the OpenRouter workflow and adapts it for TheRouter.ai. Use TheRouter.ai as your OpenAI-compatible endpoint and keep model IDs in `provider/model` format.

Installation

Install the required SDKs and keep your TheRouter.ai key in environment variables.

install.sh
npm install ai @openrouter/ai-sdk-provider

Configuration

Set TheRouter.ai base URL overrides and pass your API key. Add attribution headers when your app should appear in rankings.

TypeScript
const openrouter = createOpenRouter({ apiKey: process.env.THEROUTER_API_KEY });
const result = streamText({
  model: openrouter("openai/gpt-4o-mini"),
  prompt: "Write a changelog entry",
});

Caveats

Integration note
When mixing serverless and edge runtimes, ensure API key injection and model fallback defaults are consistent across route handlers.

For production rollouts, pin SDK versions and validate model compatibility in staging before broad rollout.