Vercel AI SDK
Point createOpenAI and createAnthropic in the Vercel AI SDK at UnioAPI and call GPT and Claude models with generateText and streamText.
The Vercel AI SDK calls models from different vendors through one generateText /
streamText interface. Its OpenAI and Anthropic providers both accept a custom baseURL; point it at UnioAPI.
Prerequisites
- Node.js 18 or newer, with an API key in the
UNIO_API_KEYenvironment variable.
npm install ai @ai-sdk/openai @ai-sdk/anthropicCreate the providers
import { createOpenAI } from "@ai-sdk/openai";
import { createAnthropic } from "@ai-sdk/anthropic";
export const unioOpenAI = createOpenAI({
baseURL: "https://api.unioapi.com/v1",
apiKey: process.env.UNIO_API_KEY,
});
export const unioAnthropic = createAnthropic({
baseURL: "https://api.unioapi.com/v1",
apiKey: process.env.UNIO_API_KEY,
});Both base URLs end with /v1
Unlike the official Anthropic SDK, @ai-sdk/anthropic expects a baseURL that already ends in /v1 (it only
appends /messages), so both providers use https://api.unioapi.com/v1.
Generate text
import { generateText } from "ai";
const { text, usage } = await generateText({
model: unioOpenAI("gpt-5.6-sol"),
prompt: "Explain prompt caching in three sentences",
});
console.log(text, usage);For Claude, just switch the provider:
const { text } = await generateText({
model: unioAnthropic("claude-sonnet-5"),
prompt: "Explain prompt caching in three sentences",
});Streaming
import { streamText } from "ai";
const result = streamText({
model: unioAnthropic("claude-sonnet-5"),
prompt: "Write a short poem about the terminal",
});
for await (const delta of result.textStream) {
process.stdout.write(delta);
}In a Next.js route handler you can return result.toTextStreamResponse() directly.
Choosing the OpenAI endpoint
In recent AI SDK versions, unioOpenAI("model-id") uses the Responses API by default; use
unioOpenAI.chat("model-id") for Chat Completions. Responses-only models such as gpt-5.5-pro need the default form.
Defaults can differ between AI SDK versions — check the docs for the version you installed.
FAQ
404 Not Found — make sure both baseURLs are https://api.unioapi.com/v1 and the model ID is the official ID
(no vendor prefix).
401 — make sure UNIO_API_KEY is set where the code runs; on platforms such as Vercel, configure it in the
project's environment variables.
Next steps
- Node.js / TypeScript
- OpenCode setup (also built on AI SDK providers)