From zero to your first encrypted write
Get an agent reading and writing encrypted, per-request-paid KV in a few commands — no signup, no dashboard, just a wallet and a key.
Prerequisites
- Node 20.3+ — the
engines.nodefloor both@agentkv/cliand@agentkv/clientdeclare; older runtimes fail the engine check on install. - Point at the API —
AGENTKV_ENDPOINT=https://api.agentx402.ai. - Optional: a spend cap —
AGENTKV_MAX_SPEND_USDrefuses any op above it.
node --version # v20.3 or newer
export AGENTKV_ENDPOINT=https://api.agentx402.ai
export AGENTKV_MAX_SPEND_USD=5 # optional — refuse any op above this Pick your path
Two ways to hold a namespace. Choose by how your agent's wallet works — then follow that track end to end.
Your own wallet
You hold the private key. The agent authenticates and pays with its own wallet — identity and payment are one key, and there's no account to manage.
-
Create a wallet.
Generate a fresh keypair. The private key prints once and is never stored — capture it and export it for the CLI and client.
agentkv wallet new # → { "address": "0x…", "privateKey": "0x…" } — shown once, not saved export AGENTKV_PRIVATE_KEY=0x…Store the private key in a secret manager — it's shown once and can't be recovered.
-
Fund it.
agentkv fundprints a card-to-USDC onramp URL that sends USDC to the wallet — the command makes no payment itself. Or send USDC to the address directly (e.g.awal send). Then pay per op — a write is $0.005, a read $0.003 — or runagentkv deposit <usd>to pre-pay credits (minimum $1) at a tenth the price.agentkv fund # prints a card → USDC onramp URL (makes no payment itself) # — or send USDC straight to the wallet address: awal send <amount> <address> # — or pre-pay credits instead of paying per op: agentkv deposit <usd> -
Write & read.
Same store from every surface — pick the one that fits your agent.
agentkv set session:42 '{"step":3}' # encrypted, paid per write agentkv get session:42 # decrypted client-sideimport { AgentKV } from "@agentkv/client"; const kv = new AgentKV({ privateKey, endpoint, maxSpendUsd: 5 }); await kv.set("session:42", { step: 3 }); // encrypts, then pays const state = await kv.get("session:42"); // → { step: 3 }// Claude Code / Cursor / any MCP client — add to your config: { "mcpServers": { "agentkv": { "command": "npx", "args": ["-y", "@agentkv/cli", "mcp"], "env": { "AGENTKV_PRIVATE_KEY": "0x…", "AGENTKV_ENDPOINT": "https://api.agentx402.ai", "AGENTKV_MAX_SPEND_USD": "5.00" } } } }
Managed wallet with awal
A managed or embedded wallet — like awal — that can't expose a signing key. A client-generated account key owns the namespace, and any wallet can fund it: payer funds, bearer owns. Provision it with a one-time deposit, or skip the deposit entirely and pay per call.
-
Mint an account key.
Generate an
ak_…bearer token plus a local encryption key. The bearer owns the namespace; the encryption key never leaves your machine.agentkv account new # → account key: ak_… # → encryption key: 0x… (local — never sent to the server) export AGENTKV_ACCOUNT_KEY=ak_… export AGENTKV_ENCRYPTION_KEY=0x…Both are unrecoverable — back them up. Lose the encryption key and the data can't be decrypted.
-
Get awal ready.
awal is the wallet that pays.
npx [email protected] statussigns you in; if its wallet is empty,awal addressgives you a deposit address — send it USDC. A brand-new awal wallet also needs a little ETH on Base (~$1) for its one-time smart-account deployment, before it can sign anything, so send that too.npx [email protected] status # sign in # if empty: awal address → send USDC, plus a little ETH (~$1, one-time) -
Provision: deposit for prepaid credits.
A brand-new
ak_…has no account yet — deposit once to provision it (minimum $1, from any wallet — payer funds, bearer owns) at a tenth the pay-per-op price. SetAGENTKV_TOPOFF=awaland the client keeps it topped up automatically as credits run low. This is the economical path for repeat use.awal x402 pay https://api.agentx402.ai/v1/account/deposit \ --headers '{"Authorization":"Bearer ak_…"}' export AGENTKV_TOPOFF=awal # tops off from awal when credits run low -
Or skip the deposit — pay per call.
No deposit needed: the first
set/getagainst a never-funded account gets a402 account_not_provisionedchallenge (distinct from an ordinary out-of-creditinsufficient_credits) instead of running unfunded — a bare awal pays it out of the box, no AgentKV-specific setup required. Our own CLI and client gate that first payment behind an explicit opt-in instead, since auto-funding it is indistinguishable from funding a typo'd key: setAGENTKV_INLINE=awalto pay each op inline, plusAGENTKV_BOOTSTRAP=1to let it cover that first challenge too. Skip the flag if the account key is read straight fromagentkv account new's own~/.agentkv/account.json(not re-exported) — a file the CLI wrote itself can't be a typo, so it bootstraps automatically.export AGENTKV_INLINE=awal # pay each op inline via x402 — no prepaid credits export AGENTKV_BOOTSTRAP=1 # opt in to paying the FIRST-ever op too agentkv set session:42 '{"step":3}' # 402s once (account_not_provisioned), awal pays it -
Write & read.
Same store, same surfaces — the client and MCP take the account key and encryption key instead of a private key.
agentkv set session:42 '{"step":3}' # encrypted, paid per write agentkv get session:42 # decrypted client-sideimport { AgentKV } from "@agentkv/client"; const kv = new AgentKV({ accountKey, encryptionKey, endpoint, maxSpendUsd: 5 }); await kv.set("session:42", { step: 3 }); // encrypts, then pays const state = await kv.get("session:42"); // → { step: 3 }// Claude Code / Cursor / any MCP client — add to your config: { "mcpServers": { "agentkv": { "command": "npx", "args": ["-y", "@agentkv/cli", "mcp"], "env": { "AGENTKV_ACCOUNT_KEY": "ak_…", "AGENTKV_ENCRYPTION_KEY": "0x…", "AGENTKV_ENDPOINT": "https://api.agentx402.ai", "AGENTKV_MAX_SPEND_USD": "5.00" } } } }
Before you ship
Writes need a human “yes” by default
Every state-changing operation — set, delete, and both deposit ops — is flagged in every manifest (MCP annotations, OpenAPI side-effect flags), so MCP clients prompt before running one and well-behaved agents ask first; reads never do. The API itself never asks — a signed request executes. Running unattended? Pre-approve those tools in your client and rely on the spend cap.
Cap the spend
Set maxSpendUsd in the client (or AGENTKV_MAX_SPEND_USD for the CLI and MCP) and any single operation above it is refused. That caps one call, not the total — to bound a runaway agent, also set maxSessionSpendUsd (AGENTKV_MAX_SESSION_SPEND_USD), which caps cumulative spend for the session. agentkv mcp warns on startup when it is unset.