npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spendguard/vercel-ai

v0.2.2

Published

Vercel AI SDK middleware for SpendGuard budget guardrails (covers Mastra Agents via subpath alias)

Readme

@spendguard/vercel-ai

Vercel AI SDK middleware for Agentic SpendGuard budget guardrails. Drop-in via wrapLanguageModel({ model, middleware: createSpendGuardMiddleware(...) }) on any @ai-sdk/* provider — pre-call budget reservation before the upstream provider HTTP call fires, end-of-stream commit reconciles real token usage, signed audit trail. Transitively covers Mastra Agents via the @spendguard/vercel-ai/mastra subpath alias.

npm version License: Apache 2.0

Status

0.1.0 — first public release. Closes D06 (Vercel AI SDK middleware). See docs/specs/coverage/D06_vercel_ai_sdk/ for the locked spec set and CHANGELOG.md for the SLICE-by-SLICE feature list.

What it does

Vercel AI SDK v4+ (ai) is the dominant TS-side LLM router. Mastra Agents call generateText / streamText from ai underneath, so a single middleware covers both ecosystems.

@spendguard/vercel-ai ships a LanguageModelV1Middleware factory — createSpendGuardMiddleware — that you drop onto any @ai-sdk/* provider via wrapLanguageModel({ model, middleware }). No model subclassing, no proxy fork. The Mastra subpath (@spendguard/vercel-ai/mastra) re-exports the same factory under the Mastra-idiomatic name createSpendGuardLanguageMiddleware — strict function-reference equality holds.

Install

pnpm add @spendguard/sdk @spendguard/vercel-ai ai

@spendguard/sdk, ai (Vercel AI SDK), and zod are declared as peer dependencies so the adapter pins none of them — your project's lockfile wins. Node 20.10+ is required.

For real provider HTTP, add the official @ai-sdk/* provider you target:

pnpm add @ai-sdk/openai     # or @ai-sdk/anthropic, @ai-sdk/google, ...

Quick start

import { generateText, wrapLanguageModel } from "ai";
import { openai } from "@ai-sdk/openai";
import { SpendGuardClient } from "@spendguard/sdk";
import { createSpendGuardMiddleware } from "@spendguard/vercel-ai";

const client = new SpendGuardClient({
  socketPath: "/var/run/spendguard/adapter.sock",
  tenantId: "00000000-0000-4000-8000-000000000001",
  runtimeKind: "vercel-ai-js",
});
await client.connect();
await client.handshake();

const middleware = createSpendGuardMiddleware({
  client,
  tenantId: "00000000-0000-4000-8000-000000000001",
  budgetId: "44444444-4444-4444-8444-444444444444",
});

const model = wrapLanguageModel({
  model: openai("gpt-4o-mini"),
  middleware,
});

try {
  const { text } = await generateText({ model, prompt: "hello vercel ai" });
  console.log(text);
} finally {
  await client.close();
}

For the Mastra-side import:

import { createSpendGuardLanguageMiddleware } from "@spendguard/vercel-ai/mastra";

Same factory. Same options surface. Strict === equality with the root export.

Documentation

License

Apache-2.0 — see the repo root LICENSE and LICENSE_NOTICES.md for third-party attribution.