Vercel AI SDK integration
Call Modellane models from the Vercel AI SDK with the OpenAI-compatible provider, including streamed text in Next.js route handlers.
The Vercel AI SDK reaches Modellane through its OpenAI-compatible provider. Create the provider with our base URL and stream responses into your app.
The Vercel AI SDK talks to Modellane through its OpenAI-compatible provider package, which calls the Chat Completions API (POST /v1/chat/completions). Use @ai-sdk/openai-compatible, not the @ai-sdk/openai provider, which targets OpenAI's own API.
Install#
Shell
npm install ai @ai-sdk/openai-compatibleCreate the provider#
TypeScript
// lib/modellane.ts
import { createOpenAICompatible } from "@ai-sdk/openai-compatible"
export const modellane = createOpenAICompatible({
name: "modellane",
baseURL: "https://usemodellane.com/v1",
apiKey: process.env.MODELLANE_API_KEY,
includeUsage: true,
})includeUsage requests the usage chunk on streamed calls, so the usage result of the SDK holds real token counts.
Generate text#
TypeScript
import { generateText } from "ai"
import { modellane } from "./lib/modellane"
const { text, usage } = await generateText({
model: modellane("lane-1"),
prompt: "Suggest three names for a coffee shop.",
})
console.log(text, usage)Stream from a Next.js route handler#
TypeScript
// app/api/chat/route.ts
import { convertToModelMessages, streamText, type UIMessage } from "ai"
import { modellane } from "@/lib/modellane"
export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json()
const result = streamText({
model: modellane("lane-1"),
messages: convertToModelMessages(messages),
})
return result.toUIMessageStreamResponse()
}Tool calling and structured output work through the usual tools option and generateObject on models that support them; check the Features column in Models & pricing.
Verify#
Run the generateText example in a script. A printed reply means the base URL, key and model id are right; an authentication error points at the key, and model_not_found at the model id.