AgentGuard · agentguard.run

Exported TypeScript framework integrations

On a supported TypeScript integration, add configured spend caps, declared capability checks, and an opt-in circuit breaker before dispatch. Signed metadata receipts require configured Ed25519 keys.

Shared policy semantics: supported hooks evaluate policy in your runtime. In enforce mode, a block action throws AgentGuardBlockedError before that hook dispatches to the provider. Ed25519 signing requires configured keys and a decision store.

Install

npm install @agentguard-run/spend        # Node / TypeScript
pip install agentguard-spend             # Python
LangChain.js

Attach one callback handler

The exported handler preflights LangChain.js chat-model and LLM callback starts, then settles usage on completion.

import { ChatOpenAI } from '@langchain/openai';
import { createLangChainHandler } from '@agentguard-run/spend/frameworks/langchain';

const guard = createLangChainHandler({
  policy,
  scope: { tenantId: 'acme', agentId: 'research-agent' },
});

const llm = new ChatOpenAI({ callbacks: [guard] });
await llm.invoke('hello');           // throws AgentGuardBlockedError if over cap
Vercel AI SDK

Wrap the model with middleware

One middleware on your language model. Works with generateText and streaming.

import { wrapLanguageModel } from 'ai';
import { openai } from '@ai-sdk/openai';
import { agentguard } from '@agentguard-run/spend/frameworks/vercel-ai';

const model = wrapLanguageModel({
  model: openai('gpt-4o-mini'),
  middleware: agentguard({
    policy: { caps: [{ amountCents: 2000, window: 'per_day', action: 'block' }] },
    scope: { tenantId: 'acme', agentId: 'assistant' },
  }),
});
Anthropic client

Use the native Anthropic binding

Anthropic and OpenAI-compatible clients have distinct exported wrappers because their request and response shapes differ.

import Anthropic from '@anthropic-ai/sdk';
import { withSpendGuardAnthropic } from '@agentguard-run/spend';

const guarded = withSpendGuardAnthropic(new Anthropic(), {
  policy,
  scope: { tenantId: 'acme', agentId: 'my-agent' },
});
Bring your own key. Production use is free up to 10,000 enforcement calls per calendar month under the package license. Caps, declared capability checks, the opt-in circuit breaker, and optional receipt signing are available without Managed. See pricing for the managed path.