Ointerference
DOCS
Developer Guides

TypeScript & Vercel AI SDK Guide

Build modern Next.js and Node.js applications with Interference and the Vercel AI SDK.

TypeScript & Vercel AI SDK

Interference natively integrates with the Vercel AI SDK (ai and @ai-sdk/openai-compatible) for streaming text, structured object generation, and tools.


1. Installation

npm install ai @ai-sdk/openai-compatible

2. Text Streaming in Next.js App Router

Create a streaming route in app/api/chat/route.ts:

import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";

const interference = createOpenAICompatible({
  name: "interference",
  baseURL: "https://api.interference.dev/v1",
  apiKey: process.env.INTERFERENCE_API_KEY,
});

export const runtime = "edge";

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = await streamText({
    model: interference("qwen3.6-plus"),
    messages,
  });

  return result.toDataStreamResponse();
}

3. Structured Output (generateObject)

Generate schema-validated JSON with Zod:

import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateObject } from "ai";
import { z } from "zod";

const interference = createOpenAICompatible({
  name: "interference",
  baseURL: "https://api.interference.dev/v1",
  apiKey: process.env.INTERFERENCE_API_KEY,
});

const { object } = await generateObject({
  model: interference("glm-5.3-flash"),
  schema: z.object({
    sentiment: z.enum(["positive", "neutral", "negative"]),
    confidence: z.number().min(0).max(1),
    keyTakeaways: z.array(z.string()),
  }),
  prompt: "Analyze the user feedback: 'The API is blazingly fast and super easy to setup!'",
});

console.log("Extracted Sentiment:", object);

On this page