@ola-893/agentpay-core
v0.4.0
Published
Guarded paid API sessions for agents: deterministic policy and native NEAR payments
Readme
AgentPay Core
Native NEAR USDC payment-stream guardrails for agents. Install with npm install @ola-893/[email protected]. This release lets the caller pin the signed quote before requesting OPEN. The vault contract is unchanged.
import { createNearGateway } from '@ola-893/agentpay-core/near';
import { guardedFetch } from '@ola-893/agentpay-core';
const client = await createNearGateway({
configPath: '/private/profile/deployment.json',
stateRoot: '/private/agentpay/state',
paymentsEnabled: true,
});
try {
const request = guardedFetch(fetch, { client, tier: 'basic' });
const url = new URL(client.service.requestPath, client.serviceUrl);
url.searchParams.set('q', 'payment streams');
const response = await request(url);
console.log(response.status, await response.json());
} finally {
await client.close();
await client.dispose();
}Configure financial limits, service paths, tiers, inference and host guardrails with the CLI. A service must implement AgentPay's NEAR quote/health/402/session protocol; ordinary third-party 402 APIs need adapters. There is no generic payment-origin discovery. Requests allow GET/HEAD, forbid redirects and foreign origins, and retry a supported payment challenge once.
createNearGateway verifies the chain, vault and exact restricted agent key. Its executor persists session context and uncertain transaction intents, rechecks permits before submission, and reuses only the matching service/tier/recipient/active chain session. Host observations drive configurable failure thresholds; they are not exposed as model tools. A separate policy worker signs exact OPEN/CLOSE permits. The contract independently enforces financial limits.
Use createToolHandlers/definitionsFor from @ola-893/agentpay-core/tools, or agentPayTools(client) from @ola-893/agentpay-core/vercel-ai (Vercel AI SDK 6). Both use the same four MCP-compatible tools: check, open, fetch, close. Fetch accepts a configured tier and optional URL query string. It returns untrusted provider content plus actual payment decisions/receipts.
Long-running hosts should use startMonitor(client, { onEvent, onError }) from @ola-893/agentpay-core/monitor and await monitor.stop() before closing/disposal. Monitoring requires a running process; on-chain lease expiry always caps accrual. dispose() stops the worker and does not by itself submit CLOSE.
The exported OfflineGateway is a deterministic test double used by unit/protocol tests. It is not wired into the CLI or advertised as an agent payment run. Local process separation assumes a trusted OS user. TEE isolation, sponsorship, multi-service routing and production security assurance are not implemented.
