Skip to main content
The Vercel AI SDK’s OpenAI provider accepts a custom baseURL, which means you can point it at Portrix and gain access to all 400+ models through the same streamText, generateText, and useChat interface you already know. Streaming, tool calling, and structured output work without any additional configuration because Portrix normalises every model’s response to the OpenAI SSE format.

Installation

Configuration

Use createOpenAI to create a custom provider instance that routes all requests through Portrix. Define this once and import it wherever you need a model:
You can now use portrix("provider/model") anywhere the Vercel AI SDK accepts a LanguageModel.

API route

Create a Next.js App Router API route that streams a response using streamText:
Set maxDuration to a value appropriate for your Vercel plan. Streaming responses from large models can take longer than the default 10-second function timeout on the Hobby plan.

useChat hook

Create a client component that uses the useChat hook from ai/react to stream responses from your API route:

Switching models

Create multiple provider instances or select a model dynamically at runtime. This lets you route different request types to the most appropriate model:
Use modelForTask in your API route to route requests dynamically:

Streaming and UI

All Vercel AI SDK streaming features — real-time token delivery, useChat state management, and toDataStreamResponse() — work with Portrix responses without any extra configuration. Portrix normalises every model’s output to the OpenAI Server-Sent Events format, so the SDK’s stream parser handles responses from Anthropic, Google, Mistral, and every other provider identically to native OpenAI responses.
Define PORTRIX_API_KEY as a plain (non-NEXT_PUBLIC_) environment variable in your Vercel project settings. Vercel automatically makes non-prefixed variables available to server-side runtimes only, keeping your key out of the client bundle. You can set it under Project Settings → Environment Variables in the Vercel dashboard.