npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

letagentpay

v0.2.1

Published

TypeScript SDK for LetAgentPay — AI agent spending policy middleware for fiat and x402 crypto-micropayments

Readme

letagentpay

TypeScript SDK for LetAgentPay — AI agent spending policy middleware. Set budgets, define spending policies, and control AI agent purchases.

Zero dependencies. Uses the built-in fetch API (Node.js 18+, Bun, Deno).

Installation

npm install letagentpay

Quick Start

import { LetAgentPay } from "letagentpay";

const client = new LetAgentPay({ token: "agt_xxx" });

// Create a purchase request
const result = await client.requestPurchase({
  amount: 15.0,
  category: "api_calls",
  description: "OpenAI GPT-4 call",
});
console.log(result.status); // "auto_approved" | "pending" | "rejected"

// Check budget
const budget = await client.checkBudget();
console.log(`Remaining: $${budget.remaining}`);

API

requestPurchase(options)

Create a purchase request. The policy engine runs 8 deterministic checks (budget, category, per-request limit, schedule, daily/weekly/monthly limits).

const result = await client.requestPurchase({
  amount: 25.0,
  category: "software",
  merchantName: "GitHub",         // optional
  description: "Copilot license", // optional
  agentComment: "Monthly renewal", // optional, shown to reviewers
});

// result.status: "auto_approved" | "pending" | "rejected"
// result.requestId: "uuid"
// result.policyCheck: { passed: true, checks: [...] }
// result.budgetRemaining: 475.0 (only if auto_approved)
// result.expiresAt: "2026-..." (only if pending)

checkRequest(requestId)

Check the status of a purchase request.

const status = await client.checkRequest("request-uuid");
// status.status: "auto_approved" | "pending" | "approved" | "rejected" | "expired"

confirmPurchase(requestId, options)

Confirm a purchase after approval. Use this to report the actual amount spent.

await client.confirmPurchase("request-uuid", {
  success: true,
  actualAmount: 24.99,             // optional, if different from requested
  receiptUrl: "https://example.com/receipt", // optional
});

checkBudget()

Get current budget breakdown.

const budget = await client.checkBudget();
// budget.budget: 500.0
// budget.spent: 125.5
// budget.held: 25.0   (reserved for pending requests)
// budget.remaining: 349.5
// budget.currency: "USD"

getPolicy()

Get the current spending policy.

const policy = await client.getPolicy();

listCategories()

List valid purchase categories.

const categories = await client.listCategories();
// ["groceries", "hardware", "software", "travel", ...]

myRequests(options?)

List agent's purchase requests with optional filters.

const list = await client.myRequests({ status: "pending", limit: 10 });
// list.requests: [{ requestId, status, amount, category, ... }]
// list.total: 42

guard()

Wrap an async function so it checks spending policy before executing:

import { guard } from "letagentpay";

const callOpenAI = guard(
  async (prompt: string, cost: number) => {
    // your OpenAI call here
    return "response";
  },
  { token: "agt_xxx", category: "api_calls" }
);

// Automatically sends a purchase request for $0.03 before executing
await callOpenAI("Analyze this document", 0.03);

With a fixed amount:

const sendEmail = guard(
  async (to: string, body: string) => { /* ... */ },
  { token: "agt_xxx", category: "email", amount: 0.01 }
);

x402 Crypto-Micropayments

Authorize on-chain USDC payments via the x402 protocol. Same policy engine, same token — different payment rail.

const client = new LetAgentPay({ token: "agt_xxx" });

// Agent receives HTTP 402 — ask LAP for authorization
const auth = await client.x402.authorize({
  amountUsd: 0.05,
  payTo: "0xMerchant...",
  resourceUrl: "https://api.example.com/data",
});

if (auth.authorized) {
  // Sign tx with your own wallet, then report
  await client.x402.report({
    authorizationId: auth.authorizationId!,
    txHash: "0xabc123...",
  });
} else {
  console.log(`Declined: ${auth.reason}`);
}

// Check x402 budget and wallets
const budget = await client.x402.budget();

// Register wallet address (LAP never holds keys)
await client.x402.registerWallet({ walletAddress: "0x1234..." });

Self-Hosted

Point the SDK to your own LetAgentPay instance:

const client = new LetAgentPay({
  token: "agt_xxx",
  baseUrl: "http://localhost:8000/api/v1/agent-api",
});

Environment Variables

export LETAGENTPAY_TOKEN=agt_xxx
export LETAGENTPAY_BASE_URL=https://api.letagentpay.com/api/v1/agent-api  # optional
// Token is taken from LETAGENTPAY_TOKEN
const client = new LetAgentPay();

Error Handling

import { LetAgentPay, LetAgentPayError } from "letagentpay";

try {
  await client.requestPurchase({ amount: 100, category: "hardware" });
} catch (e) {
  if (e instanceof LetAgentPayError) {
    console.log(e.status); // 403
    console.log(e.detail); // "Daily limit exceeded"
  }
}

Security Model

LetAgentPay uses server-side cooperative enforcement. When your agent calls requestPurchase(), the request is evaluated by the policy engine on the LetAgentPay server. The agent receives only the result (approved/denied/pending) and cannot:

  • Modify its own policies (the agt_ token grants access only to the Agent API)
  • Override policy check results (they come from the server)
  • Approve its own pending requests (only a human can do that via the dashboard)

This is a cooperative model — it protects against budget overruns, category violations, and scheduling mistakes by well-behaved agents. It does not sandbox a malicious agent that has direct access to payment APIs.

Best Practices

  • Don't give your agent raw payment credentials (Stripe keys, credit card numbers). LetAgentPay should be the only spending channel
  • Use pending + manual approval for high-value purchases
  • Set per-request limits as an additional barrier
  • Review the audit trail in the dashboard regularly

Documentation

License

MIT