AgentGuard · agentguard.run

OpenRouter + AgentGuard Spend

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.

No AgentGuard inference proxy: Your OpenRouter key, prompts, and completions travel directly between your runtime and OpenRouter. They do not traverse AgentGuard infrastructure. A configured signing private key stays in your runtime.

Why this combination

Catalog sync

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.

Observable AgentGuard routing

The OpenRouter wrapper records AgentGuard's decision for the requested model. Use the separate createRouter() path when AgentGuard should own and record candidate failover.

Configured task routing

Use policy scopes, model allowlists, cost data, and declared capability requirements to encode the assignments your operator chooses.

Optional signed decision chain

Configure Ed25519 keys and a decision store to sign and hash-chain decision metadata. Verify locally with the trusted public key.

Install

1

Install the SDK

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

# Python
pip install agentguard-spend openai
2

Set your OpenRouter key

export OPENROUTER_API_KEY=sk-or-v1-...

Stored in your env. AgentGuard never reads it.

3

Wire it up

Generate a persistent signed setup

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.

Or wrap an existing TypeScript client

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.

4

Watch decisions live

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.

5

Verify the signed chain

agentguard verify

The CLI verifies locally. The hosted browser verifier is a separate path for submitted receipts.

Inspect the current catalog and task templates

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.

What about the OpenRouter app field

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',
  },
});

Available in the TypeScript package at v0.16.0