Skip to main content
Prerequisite: Complete the Quickstart to get an access key. All requests go to https://gateway.ngrok.ai.
The Vercel AI SDK provides a unified interface for building AI applications. It works with the ngrok AI Gateway, adding provider failover, key rotation, and observability to Vercel’s streaming and UI components.

Installation

Basic usage

Point the OpenAI provider at your AI Gateway endpoint:

Streaming responses

The AI Gateway supports streaming. Use streamText for real-time responses:

Chat interface

Build chat applications with the useChat hook:
app/page.tsx
app/api/chat/route.ts

Using different providers

The AI Gateway routes based on the model name. Use provider prefixes to be explicit:

Model failover

List fallback models in the request. See Configure fallback models.

Environment variables

Set up your environment:
.env.local

Tool calling

The AI Gateway supports function/tool calling:

Error handling

Handle errors gracefully:
With the AI Gateway’s failover, many errors are handled automatically by retrying with different providers or keys.

Next steps