Skip to Content
FrameworksVercel AI SDK + Curate-Me

Vercel AI SDK

The Vercel AI SDK’s @ai-sdk/openai provider accepts a baseURL override. Configure it once at module scope; every streamText / generateText call routes through the Curate-Me gateway.

Minimal example (Next.js API route)

// app/api/chat/route.ts import { createOpenAI } from '@ai-sdk/openai'; import { streamText } from 'ai'; const openai = createOpenAI({ baseURL: process.env.CM_GATEWAY_URL || 'https://api.curate-me.ai/v1/openai', apiKey: process.env.CM_API_KEY!, headers: { 'X-CM-API-Key': process.env.CM_API_KEY!, }, }); export async function POST(req: Request) { const { messages } = await req.json(); const result = streamText({ model: openai('gpt-4o'), messages, }); return result.toDataStreamResponse(); }

Full example at examples/integrations/vercel-ai-sdk/.

Supported versions

LibraryTested range
ai>=4.0.0,<6.0.0
@ai-sdk/openai>=1.0.0,<3.0.0
next>=14.0.0 (App Router)

Known limitations

  • Tool auto-execution: tools defined with the SDK’s tool() helper auto-execute in your process. The LLM call that selects the tool is governed; the tool body’s network calls are not.
  • useChat hook: works without modification — the hook just POSTs to your /api/chat route, which talks to the gateway.
  • Anthropic provider: if you use @ai-sdk/anthropic, override its baseURL to <gateway>/v1/anthropic. The gateway speaks Anthropic’s native wire format.
  • Edge runtime: the gateway works fine from Edge / Vercel Edge Functions; no Node-specific deps in the example.

Troubleshooting

If the stream cuts off early, check that you’re forwarding the gateway’s response headers to the client (Vercel does this by default in toDataStreamResponse()). The X-CM-Request-Id should appear in the response headers of your /api/chat endpoint.