Memory write

$0.001 per call · USDC via x402 · POST /api/memory

Persistent key-value memory for agents, scoped to the paying wallet. Send POST /api/memory 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, bytes, updated, expiresAt, owner and 1 more.

Your x402 payment IS your authentication: the wallet that pays owns the namespace. No signup, no API keys. Exact-key storage for structured state. For retrieval by MEANING rather than key, use the catalog slugs memory-remember and memory-recall (on MCP, through catalog.call with that slug). Body: {"key":"…","value":any JSON,"ttlSeconds":3600?} to write (optional TTL), or {"key":"…","delete":true} to remove. Add "owner":"0x…" to write into another wallet's namespace you've been granted. Values up to 64KB.

Category: Agent memory & coordination · Tags: memory storage state key-value persistence ttl store save

TRY IN PLAYGROUND →

Parameters

NameTypeRequiredDescription
keystringyesKey to write (max 256 chars)
valueanynoAny JSON value (max 64KB serialized)
ttlSecondsnumbernoOptional: auto-expire the key after N seconds
ownerstringnoOptional 0x namespace to write into (requires a readwrite grant)
deletebooleannoSet true to delete the key instead

Example request

curl -i -X POST https://agent402.tools/api/memory \
  -H "Content-Type: application/json" \
  -d '{"key":"research/task-42","value":{"status":"done","findings":["…"]},"ttlSeconds":86400}'

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

Example response

{
  "key": "research/task-42",
  "bytes": 42,
  "updated": 1760000000000,
  "expiresAt": 1760086400,
  "owner": "0x…",
  "persistent": true
}
FieldTypeAlways presentIn the example
keystringyesresearch/task-42
bytesnumberyes42
updatednumberyes1760000000000
expiresAtnumberyes1760086400
ownerstringyes0x…
persistentbooleanyestrue

From an MCP client

catalog.call {
  "slug": "memory-write",
  "params": {
    "key": "research/task-42",
    "value": {
      "status": "done",
      "findings": [
        "…"
      ]
    },
    "ttlSeconds": 86400
  }
}

The hosted connector at https://agent402.tools/mcp needs a payment for memory-write; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY (wallet only for this tool). 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?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/memory", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "key": "research/task-42",
    "value": {
      "status": "done",
      "findings": [
        "…"
      ]
    },
    "ttlSeconds": 86400
  }),
});

Related tools

Memory read

$0.001 · GET /api/memory

Read from a wallet-scoped namespace. ?key=… returns the stored value; omit key to list keys. The read half of memory-wri…

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 for distrib…

Memory forget

$0.001 · POST /api/memory/forget

Delete a remembered document by id from the recall store.

Memory grant

$0.002 · POST /api/memory/grant

Share your namespace with another wallet so different agents can coordinate through it. Grant read or readwrite access t…

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 counter

$0.001 · POST /api/memory/incr

Atomically increment (or decrement) a numeric key and return the new value - a coordination primitive for counters, lock…