Core concepts

Spending policies

A spending policy is the set of rules an agent pays under. Before anything is signed, every payment runs through ten checks against the agent's current policy version.
Code samples in

How a policy decides#

  1. All ten checks run, in order, on every payment. Each one passes, fails or asks for approval.
  2. The first failing check rejects the payment; its id is the reasonCode (for example per_transaction_limit).
  3. If nothing fails but a check asks for approval, the payment waits for an owner (requires_approval).
  4. Otherwise the payment is approved and signed. Every evaluation records the engine version (cortex-policy/1.1.0) and the policy version it used.

Spending modes#

ModeBehaviour
restrictedOnly approved services and recipients (the service scope is always the allowlist). Payments at or above the approval threshold, if one is set, need approval.
approvalEvery payment needs an owner's decision.
autonomousPays 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.

RuleTypeMeaning
moderestricted | approval | autonomousSee spending modes.
maxPerPaymentbase unitsLargest single payment.
dailyLimit, weeklyLimit, monthlyLimitbase units or nullCumulative limits over UTC days, weeks starting Monday and calendar months.
approvedAssetsstring[] (≥ 1)Asset symbols, for example sUSDC or USDC.
approvedNetworksstring[] (≥ 1)Network keys: sandbox, hyperevm, elysium.
serviceScopeallowlist | verified | anyWhich marketplace services the agent may pay.
approvedServiceIdsstring[]The allowlist of services.
approvedRecipients0x address[]Addresses the agent may pay directly.
allowedCategoriesstring[]Service categories; empty means every category.
maxPaymentsPerMinute, maxPaymentsPerHourinteger or nullFrequency limits.
approvalThresholdbase units or nullPayments at or above it need an owner decision.
expiresAtISO date-time or nullAfter it, every payment is refused.
priceTolerancePct0–100How far a quote may exceed a fixed listed price.

The ten checks#

#CheckWhat it verifies
1agent_authorizationThe workspace is not frozen, the agent is active, it has an active policy, and its owner-delegated spend permission is neither revoked nor expired.
2available_balanceThe agent has an active account for the payment's network and asset with enough balance.
3approved_recipientThe 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.
4approved_assetThe asset is approved by the policy, matches a verified token contract and is accepted by the service.
5network_compatibilityThe network is approved by the policy, payments are supported there, and the service settles on it.
6per_transaction_limitThe 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.
7cumulative_limitDaily, weekly and monthly totals (UTC windows, authorized plus settled) stay within their limits, and the per-minute and per-hour payment counts are respected.
8policy_expirationThe policy has not expired and the price quote is still valid.
9approval_requirementApproval mode, or an amount at or above the approval threshold, needs an owner decision. A rejected or expired approval fails the check.
10duplicate_protectionThe 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.

KeyModePer paymentDailyApproval at
researchautonomous$1.00$10.00$0.50
api_consumerrestricted$0.05$5.00None
codingautonomous$2.00$15.00$1.00
data_collectionautonomous$0.10$8.00None
contentautonomous$1.00$12.00$0.50
enterpriserestricted$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.

Administrators cannot change your policies
No CortexPay endpoint lets a platform administrator edit a workspace's policies, approve its payments or move its funds.

Endpoints#

  • GET/api/policies

    Spending policies with current rules and the agents using them.

    Key: policies:read · key's rate limit

  • POST/api/policiesIdempotency-Key

    Same as POST /api/policies/create.

    Key: policies:write · session owner/admin · 30/min

  • POST/api/policies/createIdempotency-Key

    Create a policy (version 1) { name, description?, templateKey?, rules, notes? }.

    Key: policies:write · session owner/admin · 30/min

  • GET/api/policies/:id

    Policy with current rules, version history (with diffs) and agents.

    Key: policies:read · key's rate limit

  • PATCH/api/policies/:id

    Rename, describe, archive or restore; new rules publish a new version.

    Key: policies:write · session owner/admin · 30/min

  • GET/api/policies/:id/versions

    Version history, newest first, with diffs.

    Key: policies:read · key's rate limit

  • POST/api/policies/:id/versions

    Publish new rules as version N+1 { rules, baseVersion, notes? }.

    Key: policies:write · session owner/admin · 30/min

  • POST/api/policies/evaluate

    Dry run of the ten checks for { agentId, serviceId, amount? }. Records nothing.

    Key: policies:read · 60/min

  • DELETE/api/agents/:id/services/:serviceId

    Emergency removal of an approved service (new policy version).

    Key: policies:write · session owner/admin · 30/min