Core concepts
Spending policies
How a policy decides#
- All ten checks run, in order, on every payment. Each one passes, fails or asks for approval.
- The first failing check rejects the payment; its id is the
reasonCode(for exampleper_transaction_limit). - If nothing fails but a check asks for approval, the payment waits for an owner (
requires_approval). - Otherwise the payment is
approvedand signed. Every evaluation records the engine version (cortex-policy/1.1.0) and the policy version it used.
Spending modes#
| Mode | Behaviour |
|---|---|
restricted | Only approved services and recipients (the service scope is always the allowlist). Payments at or above the approval threshold, if one is set, need approval. |
approval | Every payment needs an owner's decision. |
autonomous | Pays on its own within the limits and the service scope; payments at or above the approval threshold need approval. |
Rules#
Money values are strings of integer base units (6 decimals for USDC and sUSDC: "1000000" is $1.00). Limits set to null are off.
| Rule | Type | Meaning |
|---|---|---|
mode | restricted | approval | autonomous | See spending modes. |
maxPerPayment | base units | Largest single payment. |
dailyLimit, weeklyLimit, monthlyLimit | base units or null | Cumulative limits over UTC days, weeks starting Monday and calendar months. |
approvedAssets | string[] (≥ 1) | Asset symbols, for example sUSDC or USDC. |
approvedNetworks | string[] (≥ 1) | Network keys: sandbox, hyperevm, elysium. |
serviceScope | allowlist | verified | any | Which marketplace services the agent may pay. |
approvedServiceIds | string[] | The allowlist of services. |
approvedRecipients | 0x address[] | Addresses the agent may pay directly. |
allowedCategories | string[] | Service categories; empty means every category. |
maxPaymentsPerMinute, maxPaymentsPerHour | integer or null | Frequency limits. |
approvalThreshold | base units or null | Payments at or above it need an owner decision. |
expiresAt | ISO date-time or null | After it, every payment is refused. |
priceTolerancePct | 0–100 | How far a quote may exceed a fixed listed price. |
The ten checks#
| # | Check | What it verifies |
|---|---|---|
| 1 | agent_authorization | The workspace is not frozen, the agent is active, it has an active policy, and its owner-delegated spend permission is neither revoked nor expired. |
| 2 | available_balance | The agent has an active account for the payment's network and asset with enough balance. |
| 3 | approved_recipient | The recipient matches the service's registered payment address, the service is operational, its category is allowed, and it is within the service scope (allowlist, verified or any). Unregistered URLs pass only if the recipient is allowlisted or the scope is any. |
| 4 | approved_asset | The asset is approved by the policy, matches a verified token contract and is accepted by the service. |
| 5 | network_compatibility | The network is approved by the policy, payments are supported there, and the service settles on it. |
| 6 | per_transaction_limit | The amount is above zero and within the per-payment limit. For fixed-price services the quote may not exceed the listed price plus the price tolerance. |
| 7 | cumulative_limit | Daily, weekly and monthly totals (UTC windows, authorized plus settled) stay within their limits, and the per-minute and per-hour payment counts are respected. |
| 8 | policy_expiration | The policy has not expired and the price quote is still valid. |
| 9 | approval_requirement | Approval mode, or an amount at or above the approval threshold, needs an owner decision. A rejected or expired approval fails the check. |
| 10 | duplicate_protection | The quote has no earlier authorization, the payment nonce is unused, and an identical request was not paid moments ago. |
Templates#
Use templateKey when registering an agent (policy: { kind: "template" }). Templates use the networks and assets of the workspace mode.
| Key | Mode | Per payment | Daily | Approval at |
|---|---|---|---|---|
research | autonomous | $1.00 | $10.00 | $0.50 |
api_consumer | restricted | $0.05 | $5.00 | None |
coding | autonomous | $2.00 | $15.00 | $1.00 |
data_collection | autonomous | $0.10 | $8.00 | None |
content | autonomous | $1.00 | $12.00 | $0.50 |
enterprise | restricted | $50.00 | $500.00 | $25.00 |
Create a policy#
POST /api/policies/create takes { name, description?, templateKey?, rules, notes? } and creates version 1. It needs an Idempotency-Key; with an API key it needs policies:write.
import { CortexPay } from "@cortexpay/sdk";
const cortex = new CortexPay({ apiKey: process.env.CORTEXPAY_API_KEY!, baseUrl: "https://cortexpay.vercel.app" });
const policy = await cortex.policies.create({
name: "Research budget",
rules: {
mode: "autonomous",
maxPerPayment: "1000000", // $1.00 in base units
dailyLimit: "10000000",
weeklyLimit: "50000000",
monthlyLimit: null,
approvedAssets: ["sUSDC"],
approvedNetworks: ["sandbox"],
serviceScope: "verified",
approvedServiceIds: [],
approvedRecipients: [],
allowedCategories: ["research", "data"],
maxPaymentsPerMinute: 30,
maxPaymentsPerHour: 600,
approvalThreshold: "500000",
expiresAt: null,
priceTolerancePct: 0,
},
});
console.log(policy.id);Dry-run evaluation#
POST /api/policies/evaluate runs the same ten checks with the same inputs as a real payment and records nothing: no request, quote, evaluation or payment. Send { agentId, serviceId }, and optionally amount (decimal dollars, instead of the listed price), policyId (try another policy) or rules (try unsaved rules).
import { CortexPay } from "@cortexpay/sdk";
const cortex = new CortexPay({ apiKey: process.env.CORTEXPAY_API_KEY!, baseUrl: "https://cortexpay.vercel.app" });
const result = await cortex.policies.evaluate({ agentId: "AGENT_ID", serviceId: "SERVICE_ID", amount: "0.75" });
console.log(result.decision, result.reasonCode);
for (const c of result.checks) console.log(c.id, c.status, c.detail);Versions#
Rules are never edited in place. POST /api/policies/:id/versions with { rules, baseVersion, notes? } publishes the next version, and every agent on the policy uses it from the next payment. If someone published in between, the call returns 409 version_conflict; reload and try again.
Emergency removal of a service
DELETE /api/agents/:id/services/:serviceId takes one service off the agent's policy at once. It publishes a new version, so it applies to every agent on that policy, and their access to the service is revoked.
Endpoints#
- GET
/api/policiesSpending policies with current rules and the agents using them.
Key: policies:read · key's rate limit
- POST
/api/policiesIdempotency-KeySame as POST /api/policies/create.
Key: policies:write · session owner/admin · 30/min
- POST
/api/policies/createIdempotency-KeyCreate a policy (version 1) { name, description?, templateKey?, rules, notes? }.
Key: policies:write · session owner/admin · 30/min
- GET
/api/policies/:idPolicy with current rules, version history (with diffs) and agents.
Key: policies:read · key's rate limit
- PATCH
/api/policies/:idRename, describe, archive or restore; new rules publish a new version.
Key: policies:write · session owner/admin · 30/min
- GET
/api/policies/:id/versionsVersion history, newest first, with diffs.
Key: policies:read · key's rate limit
- POST
/api/policies/:id/versionsPublish new rules as version N+1 { rules, baseVersion, notes? }.
Key: policies:write · session owner/admin · 30/min
- POST
/api/policies/evaluateDry run of the ten checks for { agentId, serviceId, amount? }. Records nothing.
Key: policies:read · 60/min
- DELETE
/api/agents/:id/services/:serviceIdEmergency removal of an approved service (new policy version).
Key: policies:write · session owner/admin · 30/min