These examples use the AI SDK 5+ API (
inputSchema, message.parts, toUIMessageStreamResponse). On AI SDK 4 the option and method names differ.Installation
Configuration
Create an OpenAI provider instance pointing at the to11 gateway. Pass model ids as<provider-slug>::<model> — openai::gpt-4o below, where openai is the routing identifier of your OpenAI provider in to11. See Naming the provider in a request.
Generate text
Stream text
Use with Next.js
In a Next.js route handler:useChat hook posts to /api/chat by default. Manage the input yourself and send messages with sendMessage:
Choosing a provider package
The gateway forwards your request to the provider as you wrote it and does not convert between wire formats. Pick the AI SDK provider package that speaks the format of the provider you call:@ai-sdk/openaifor OpenAI, xAI, and the OpenAI-compatible providers. Since AI SDK 5,to11("<model>")calls the OpenAI Responses API, which the gateway serves for OpenAI and xAI providers only. For any other OpenAI-compatible provider, select Chat Completions withto11.chat("<provider-slug>::<model>").@ai-sdk/anthropicfor Anthropic.
to11("anthropic::claude-sonnet-4-6") through the OpenAI package, for example — is rejected with 400 Bad Request and the x-to11-error-code: cross_dialect header before anything is sent to the provider. See Which SDK to call a provider with.
To call an Anthropic model, point the Anthropic package at the same gateway URL: