AgentGuard · agentguard.run

AgentGuard Managed quickstart

You are on the Managed plan. The difference from bring-your-own-key: there is no OpenRouter key to create or store. Your license key fetches a short-lived managed key at runtime, and AgentGuard enforces spend caps, capability gates, and signed receipts on every call. Your monthly inference allowance is included.

Still zero data plane. The managed key is short-lived and fetched server-side only. Your runtime calls OpenRouter directly; prompts, completions, and signing keys never pass through AgentGuard. We provision access, we never sit in the request path.

Get running

1

Install the SDK

# Node / TypeScript
npm install @agentguard-run/spend openai

# Python
pip install agentguard-spend openai
2

Set your license key

Your license key arrived by email after checkout (starts with ag_) and is also in dashboard settings. Provide it any one of three ways:

# A) CLI (saves it to ~/.agentguard, mode 600)
agentguard auth license-key ag_your_key_here
agentguard auth status          # confirm it is configured

# B) Environment variable
export AGENTGUARD_LICENSE_KEY=ag_your_key_here

# C) Pass it in code (shown in step 3 as licenseKey)
3

Point a client at OpenRouter and wrap it

On Managed you do not set an OpenRouter key. Construct any OpenAI-compatible client pointed at OpenRouter; the guard injects your managed key for OpenRouter calls automatically.

import OpenAI from 'openai';
import { withSpendGuardOpenRouter } from '@agentguard-run/spend/frameworks/openrouter';

// apiKey is a placeholder on Managed. The guard fetches and injects your
// short-lived managed key for the OpenRouter host, then caches it 15 minutes.
const client = new OpenAI({
  apiKey: 'managed',
  baseURL: 'https://openrouter.ai/api/v1',
});

const guarded = withSpendGuardOpenRouter(client, {
  licenseKey: process.env.AGENTGUARD_LICENSE_KEY,   // or omit if set via CLI
  policy: { caps: [{ amountCents: 2000, window: 'per_day', action: 'block' }] },
  scope: { tenantId: 'acme', agentId: 'support-bot' },
});
4

Make a governed call

Use the guarded client exactly like the native one. Every call is capped, capability gated, signed, and billed to your managed allowance. openrouter/auto routes to the cheapest capable model; name a specific model any time.

const res = await guarded.chat.completions.create({
  model: 'openrouter/auto',
  messages: [{ role: 'user', content: 'Draft a one line refund note.' }],
});

console.log(res.choices[0].message.content);
// Over your cap? The call throws AgentGuardBlockedError before OpenRouter is touched.
5

Verify a receipt

Every governed action signs a content-free receipt. Paste any receipt at agentguard.run/verify and confirm it yourself. It proves which model ran and that the call stayed in policy, never your data. Receipts stay verifiable at their URLs even if you cancel.

How the managed key works

PropertyBehavior
Where the key comes fromThe SDK requests a short-lived key from /api/tenant/openrouter-key using your license key, on the server only. Never in a browser runtime.
How long it livesCached in-process up to 15 minutes, then refreshed. You never see or manage it.
Where it is injectedOnly on calls whose base URL is the OpenRouter host. Any other provider client is left untouched.
What you payInference is drawn from your plan allowance (Solo Managed includes $40/mo), then at cost. Governance stays free regardless.
If the fetch failsA non-Managed license returns nothing and the SDK behaves as bring-your-own-key. Set OPENROUTER_API_KEY to fall back to your own key any time.
Prefer your own key? Managed is optional. Skip the license key, set OPENROUTER_API_KEY, and follow the bring-your-own-key quickstart. Same guard, same receipts, same zero data plane.