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.
# Node / TypeScript
npm install @agentguard-run/spend openai
# Python
pip install agentguard-spend openai
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)
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' },
});
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.
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.
| Property | Behavior |
|---|---|
| Where the key comes from | The 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 lives | Cached in-process up to 15 minutes, then refreshed. You never see or manage it. |
| Where it is injected | Only on calls whose base URL is the OpenRouter host. Any other provider client is left untouched. |
| What you pay | Inference is drawn from your plan allowance (Solo Managed includes $40/mo), then at cost. Governance stays free regardless. |
| If the fetch fails | A 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. |
OPENROUTER_API_KEY, and follow the bring-your-own-key quickstart. Same guard, same receipts, same zero data plane.