Skip to content

Vercel AI SDK

The Vercel AI SDK works against ai& through the @ai-sdk/openai provider with a custom base URL.

Terminal window
npm install ai @ai-sdk/openai
import { createOpenAI } from "@ai-sdk/openai";
export const aiand = createOpenAI({
baseURL: "https://api.aiand.com/v1",
apiKey: process.env.AIAND_API_KEY,
});
import { generateText } from "ai";
import { aiand } from "./client";
const { text } = await generateText({
model: aiand("openai/gpt-oss-120b"),
prompt: "Tell me a haiku about Tokyo.",
});
console.log(text);

Stream to the browser (Next.js App Router)

Section titled “Stream to the browser (Next.js App Router)”
app/api/chat/route.ts
import { streamText } from "ai";
import { aiand } from "@/lib/aiand";
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: aiand("openai/gpt-oss-120b"),
messages,
});
return result.toDataStreamResponse();
}
app/page.tsx
"use client";
import { useChat } from "ai/react";
export default function Page() {
const { messages, input, handleInputChange, handleSubmit } = useChat();
return (
<form onSubmit={handleSubmit}>
{messages.map((m) => (
<div key={m.id}>{m.role}: {m.content}</div>
))}
<input value={input} onChange={handleInputChange} />
</form>
);
}
import { tool } from "ai";
import { z } from "zod";
const result = await generateText({
model: aiand("openai/gpt-oss-120b"),
tools: {
getWeather: tool({
description: "Get current weather",
parameters: z.object({ city: z.string() }),
execute: async ({ city }) => `Sunny in ${city}, 22°C`,
}),
},
prompt: "What's the weather in Tokyo?",
});