Skip to main content
SDK · Node.js / Edge / Serverless

Vercel AI SDK ads integration.

Native adapter for the Vercel AI SDK. Monetize streaming chat responses built with streamText, generateText, and useChat without breaking your streaming architecture.

Get SDK accessRead the full docsEstimate revenue

Install

npm install @surfacedd/vercel-ai

Import

import { withSurfacedd } from '@surfacedd/vercel-ai'

Initialize

export const POST = withSurfacedd({ appId: 'app_xxx' })(async (req) => { ... })

Fetch a sponsored answer

const result = streamText({ model, messages, experimental_stream_transform: surfaceddTransform })

Features

  • Native Vercel AI SDK v4 compatibility
  • streamText + experimental_stream_transform integration
  • useChat() companion hook on the client
  • Edge runtime and Node.js runtime support
  • Works with every model provider the AI SDK supports (OpenAI, Anthropic, Google, Groq, Mistral)

Install in three steps

  1. Install. Run npm install @surfacedd/vercel-ai in your Next.js app.
  2. Wrap your route handler. Wrap your existing AI SDK route handler with withSurfacedd({ appId }). The wrapper is a no-op if a matching ad is not served.
  3. Render in useChat(). On the client, use the provided <SurfaceddMessage /> component instead of rendering raw message text — it detects and renders sponsored surfaces in-stream.

Frequently asked questions

Does it work with every AI SDK provider?

Yes. The adapter hooks into the SDK stream layer, not the provider. It works identically with OpenAI, Anthropic, Google, Groq, Mistral, Cohere, and any other provider the Vercel AI SDK supports.

Can I use it with streamObject for structured output?

streamText is fully supported. streamObject is partial: sponsored surfaces append after the object completes, not mid-stream. This is a spec trade-off we are considering for v2.

Does it work on the Edge runtime?

Yes. The adapter is zero-dependency (aside from the Surfacedd fetch client) and runs identically on Vercel Edge, Cloudflare Workers, and Node.js serverless.

Related SDKs

Ready to ship ads in your Vercel AI SDK app?

Join the waitlist for SDK access. 60% revenue share, no minimums, no contracts.

Join the SDK waitlist →See pricing