SENTINEL Docs

wrapWithSentinel

The core function that wraps your x402 fetch with budget and audit.

Wraps an x402-enabled fetch function with Sentinel budget enforcement and audit logging.

Signature

function wrapWithSentinel(
  fetchWithPayment: typeof fetch,
  config: SentinelConfig
): typeof fetch

Parameters

ParameterTypeDescription
fetchWithPaymenttypeof fetchThe x402-wrapped fetch (from wrapFetchWithPayment)
configSentinelConfigAgent identity, budget policy, audit settings, hooks

Return Type

A drop-in replacement fetch function with the same signature as fetch. Use it exactly like your original x402 fetch.

SentinelConfig Fields

PropertyTypeRequiredDescription
agentIdstringYesUnique identifier for this agent
teamstringNoTeam or department grouping
humanSponsorstringNoHuman accountable for this agent's spend
budgetBudgetPolicyNoSpending limits (omit for audit-only)
auditAuditConfigNoAudit storage and enrichment (default: in-memory)
hooksSentinelHooksNoLifecycle callbacks
metadataRecord<string, string>NoCustom key/value on every record

Usage Example

import { wrapWithSentinel, standardPolicy, MemoryStorage } from "@valeo/x402";

const secureFetch = wrapWithSentinel(fetchWithPayment, {
  agentId: "agent-weather-001",
  team: "data-ops",
  humanSponsor: "alice@company.com",
  budget: standardPolicy(),
  audit: {
    enabled: true,
    storage: new MemoryStorage(10_000),
    enrichment: {
      staticTags: ["production"],
      tagRules: [{ pattern: ".*openai.*", tags: ["llm"] }],
    },
  },
  hooks: {
    afterPayment: async (record) => console.log(`Paid $${record.amount}`),
    onBudgetExceeded: async (v) => console.error("Limit hit:", v),
  },
  metadata: { environment: "production" },
});

const res = await secureFetch("https://api.example.com/paid");