Skip to content
prune.

Use Prune with the Vercel AI SDK

One baseURL change. Same generateText and streamText. Cache hits skip the model. Unique prompts can route cheaper. Vault holds the provider key.

Quick answer

If OPENAI_API_KEY lives in the Next.js app, a repo leak is a provider bill. Put the provider key in the Prune vault. Put only a prune_ key in the app. Point createOpenAI at https://api.withprune.com/v1. Cache and cheaper-model routing run on the path. Each call can carry a signed receipt.

Why not paste the provider key in the app

Vercel env screenshots, .env.local in git, and preview deployments all widen the blast radius. With Prune, rotating a leak means rotating prune_, not hunting every sk-… paste. Shield can fail closed on tools and spend before the model runs.

1. Install and env

About five minutes to first receipt. Sign up at withprune.com, vault a provider under Connect, copy your prune_ key. Never commit a provider key.

npm install ai @ai-sdk/openai
.env.local
PRUNE_API_KEY=prune_...
PRUNE_BASE_URL=https://api.withprune.com/v1

2. Drop-in client

createOpenAI speaks the OpenAI API, so the base URL includes /v1. Chat and tools keep working.

prune.ts
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

const prune = createOpenAI({
  apiKey: process.env.PRUNE_API_KEY!,
  baseURL: process.env.PRUNE_BASE_URL || "https://api.withprune.com/v1",
});

const { text } = await generateText({
  model: prune("gpt-4o-mini"),
  prompt: "Summarize our refund policy in one sentence.",
});

console.log(text);

3. Streaming

stream.ts
import { streamText } from "ai";

const result = streamText({
  model: prune("gpt-4o-mini"),
  prompt: "List three onboarding tips.",
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

4. Cache and cheaper-model routing

Dashboard Auto mode applies server-side defaults. Client headers make the intent explicit. Balanced policy can move a short simple prompt to a cheaper model; the receipt names what ran.

headers.ts
const prune = createOpenAI({
  apiKey: process.env.PRUNE_API_KEY!,
  baseURL: process.env.PRUNE_BASE_URL || "https://api.withprune.com/v1",
  headers: {
    "X-Prune-Model-Policy": "balanced", // cheaper-model routing on unique prompts
    "X-Prune-PII-Mode": "redact",
  },
});
  • Second identical call can return X-Prune-Cache-Hit: true.
  • Routed calls may show X-Prune-Routed-Model. Turn routing Off in Optimize when the model id must stay fixed.
  • Verify a signed receipt at /verify.

With a single line of code, Prune cuts your AI bill and protects your team from runaway spend, leaked keys and dangerous calls.

Related

Have an account? Sign in · PyPI.