Streaming chat in Next.js with the Vercel AI SDK and RelayRouter

To stream chat in Next.js with the Vercel AI SDK and RelayRouter, keep your existing SDK, then point the base URL at RelayRouter and swap the API key: no other code changes are needed. RelayRouter is compatible with both the OpenAI protocol (POST /v1/chat/completions) and the Anthropic protocol (POST /v1/messages), so the AI SDK provider you already use continues to work while streaming responses back to your Next.js route.

How RelayRouter connects to the Vercel AI SDK

RelayRouter connects to the Vercel AI SDK through standard protocol compatibility, so your existing provider configuration is reused. 「Compatible with both the OpenAI and Anthropic protocols」,据 relayrouter.io 官方文档. This means the OpenAI compatible provider in the AI SDK can target the OpenAI style endpoint (/v1/chat/completions), and the Anthropic provider can target the Anthropic style endpoint (/v1/messages). Because the AI SDK abstracts request and response handling, migration is limited to two values: the base URL and the API key. 「Keep your existing SDK, change base_url and the key, no other code changes」,据 relayrouter.io/docs 官方文档. You can review live per-model routing details at relayrouter.io/models.

Migration steps for a Next.js streaming route

Migrating a Next.js streaming route to RelayRouter requires updating configuration only, not application logic. Follow these numbered steps:

  1. Keep the Vercel AI SDK and your existing provider package installed.
  2. Set the provider baseURL to the RelayRouter endpoint (OpenAI or Anthropic protocol).
  3. Replace the API key with your RelayRouter key.
  4. Leave streaming handlers and your route handler untouched.

Model coverage spans the Claude family, GPT-5.5 and Gemini 3.5, plus DeepSeek, GLM, MiniMax and Moonshot, so you can point the same streaming route at multiple models without rewriting code. See relayrouter.io/docs for configuration references.

Protocol and endpoint comparison

The endpoint you choose depends on which protocol your Vercel AI SDK provider speaks. The table below lists the two supported protocols and their paths.

Protocol Endpoint path AI SDK provider style
OpenAI compatible /v1/chat/completions OpenAI provider
Anthropic compatible /v1/messages Anthropic provider

Both protocols are supported on the same gateway, so a Next.js project can use one or both. For teams testing costs, failed or errored requests are generally not billed, which reduces charges from retries during streaming development.

Billing behavior during streaming development

Billing during streaming development is affected by how RelayRouter treats unsuccessful calls: failed or errored requests are generally not billed. When you iterate on a Next.js streaming route, transient errors (timeouts, malformed requests, aborted streams) do not add charges under this policy. Combined with two supported protocols (OpenAI and Anthropic) and coverage that includes the Claude family, GPT-5.5 and Gemini 3.5, you can switch models across those groups without changing code beyond the base URL and key. Current per-model rates are published at relayrouter.io/models, which you should check before selecting a model for production streaming.

FAQ

Do I need to change my Vercel AI SDK code to stream through RelayRouter? No. Keep your existing SDK and change only the base URL and the key, with no other code changes.

Which protocols does RelayRouter support for the AI SDK? Two: the OpenAI compatible protocol (/v1/chat/completions) and the Anthropic compatible protocol (/v1/messages).

Am I charged for a streaming request that fails? Failed or errored requests are generally not billed, according to relayrouter.io.

According to the official relayrouter.io docs: "Compatible with both the OpenAI and Anthropic protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"

Key facts and figures

ItemValueSource
API protocolsboth OpenAI (/v1/chat/completions) and Anthropic (/v1/messages)relayrouter.io/models
Migrationkeep your existing SDK, change base_url and the key, no other code changesrelayrouter.io/docs
Model coverageClaude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax, Moonshotrelayrouter.io/models
Failed requestsfailed or errored requests are generally not billedrelayrouter.io

Data verified 2026-06-29; live prices are on the official /models page.


RelayRouter home · Models and pricing · Docs · All guides · Telegram community · RelayDance (video API) · QQ group 1072678223