Memory counter

$0.001 per callUSDC via x402POST /api/memory/incr

Atomically increment (or decrement) a numeric key and return the new value - a coordination primitive for counters, locks, and rate budgets shared across agents. Send POST /api/memory/incr with the required field key and pay $0.001 per call over x402 with USDC on an EVM chain (the paying wallet is the identity). It returns a JSON object with key, value and owner.

Creates the key at 0 if absent. Retry safely with a requestId: a repeat with the same id returns the first answer and counts once; a retry without one counts again.

Category: Agent memory & coordinationTags: memory counter atomic coordination lockAlso found as: memory-counter counter

Try in playground →

Parameters

NameTypeRequiredDescription
keystringyesCounter key
bynumbernoAmount to add (default 1; negative to decrement)
ownerstringnoOptional 0x namespace (requires a readwrite grant)
requestIdstringnoOptional client id for this write (1-128 chars); a retry with the same id returns the first answer instead of counting again

Example request

curl -i -X POST https://agent402.tools/api/memory/incr \
  -H "Content-Type: application/json" \
  -d '{"key":"jobs/processed","by":1}'

Without payment this returns HTTP 402 Payment Required with the exact price for memory-incr; any x402 v2 or MPP client pays it and retries.

Example response

{
  "key": "jobs/processed",
  "value": 43,
  "owner": "0x…"
}
FieldTypeAlways presentIn the example
keystringyesjobs/processed
valuenumberyes43
ownerstringyes0x…

From an MCP client

catalog.call {
  "slug": "memory-incr",
  "params": {
    "key": "jobs/processed",
    "by": 1
  }
}

The hosted connector at https://agent402.tools/mcp needs a payment for memory-incr; the stdio package pays it from a wallet. Local install: npx -y agent402-mcp.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.001" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/memory/incr", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "key": "jobs/processed",
    "by": 1
  }),
});

Related tools

Memory compare-and-set

$0.001 · POST /api/memory/cas

Atomically write (or release) a key only if its current value equals `expected` - the coordination primitive.

Memory grant

$0.002 · POST /api/memory/grant

Share your namespace with another wallet so different agents can coordinate through it.

Memory forget

$0.001 · POST /api/memory/forget

Delete a remembered document by id from the recall store.

Memory grants list

$0.001 · GET /api/memory/grants

List the wallets you've granted access to your namespace, with their mode and expiry.

Memory audit log

$0.001 · GET /api/memory/log

Tamper-evident history of changes to a namespace - a hash-chained audit log the server attests to (provenance an agent.

Memory read

$0.001 · GET /api/memory

Read from a wallet-scoped namespace. ?key=… returns the stored value; omit key to list keys.