Point an OpenAI-compatible client at OpenRouter, then wrap it with the exported AgentGuard OpenRouter binding. Policy is evaluated in your runtime before supported dispatch. Decision signing and persistence are optional configuration.
The agentguard models pricing-sync option imports the current OpenRouter catalog prices into the local override table instead of relying on fixed counts or copied prices.
The OpenRouter wrapper records AgentGuard's decision for the requested model. Use the separate createRouter() path when AgentGuard should own and record candidate failover.
Use policy scopes, model allowlists, cost data, and declared capability requirements to encode the assignments your operator chooses.
Configure Ed25519 keys and a decision store to sign and hash-chain decision metadata. Verify locally with the trusted public key.
# Node / TypeScript
npm install @agentguard-run/spend openai
# Python
pip install agentguard-spend openai
export OPENROUTER_API_KEY=sk-or-v1-...
Stored in your env. AgentGuard never reads it.
agentguard auth openrouter
agentguard wizard
Before the wizard, request pricing sync through the agentguard models command when you need the current OpenRouter catalog. The wizard writes policy and quickstart files, creates a local Ed25519 key, and configures NdjsonDecisionLogStore for the local dashboard.
import OpenAI from 'openai';
import { withSpendGuardOpenRouter } from '@agentguard-run/spend/frameworks/openrouter';
import type { SpendPolicy } from '@agentguard-run/spend';
const policy: SpendPolicy = {
id: 'code-review-team-v1',
name: 'Code review team',
scope: { tenantId: 'acme', teamId: 'engineering' },
caps: [
{ amountCents: 5000, window: 'per_day', action: 'downgrade',
downgradeTo: 'anthropic/claude-haiku-4-5' },
{ amountCents: 20000, window: 'per_day', action: 'block' },
],
mode: 'enforce',
version: 1,
effectiveFrom: new Date().toISOString(),
};
const client = new OpenAI({
apiKey: process.env.OPENROUTER_API_KEY,
baseURL: 'https://openrouter.ai/api/v1',
});
const guarded = withSpendGuardOpenRouter(client, {
policy,
scope: { tenantId: 'acme', teamId: 'engineering', userId: 'alice' },
});
This manual example uses the default in-memory stores and does not sign. Add config.signingKeys and config.logStore, or use the wizard path above, for persistent signed records. See the Python package's own documentation for its typed API.
agentguard serve # opens http://localhost:8787
For wizard-generated or explicitly file-backed configuration, the local dashboard reads ~/.agentguard/<scope>/decisions.ndjson and exposes signed entries for verification.
agentguard verify
The CLI verifies locally. The hosted browser verifier is a separate path for submitted receipts.
agentguard models
The command supports explicit options for pricing sync, task-template filtering, text search, and JSON output. Those modes use the current synced catalog and package task templates. This page does not freeze provider prices or make model-quality benchmark claims.
When you call OpenRouter, pass an app header so they can attribute usage and show your app in the rankings:
const client = new OpenAI({
apiKey: process.env.OPENROUTER_API_KEY,
baseURL: 'https://openrouter.ai/api/v1',
defaultHeaders: {
'HTTP-Referer': 'https://your-app.example.com',
'X-Title': 'Your App Name',
},
});
agentguard models catalog search, task filters, and JSON outputagentguard models with its pricing-sync option to persist OpenRouter prices into the local cost tableagentguard wizard guided policy, model, cap, signing-key, and local-store setup