{
  "openapi": "3.1.0",
  "info": {
    "title": "valve · one.valve.city",
    "version": "1.0.0",
    "description": "# Surfaces\n\n`one.valve.city` exposes seven surfaces under one host. Most customers come for\nthe **JSON-RPC gateway** at `/rpc` — the actual product. `/ws` is its streaming\nsibling, `/beacon` serves the consensus layer, `/chifra` serves the TrueBlocks\naddress index, `/mempool` serves the mempool GraphQL API with a key, `/pay`\nhandles keyless x402 payments, and `/v1` is the\nmanagement backplane (accounts, keys, projects, billing). The document below is\nthe machine-readable OpenAPI for `/v1`; the other six are described in prose here and rendered separately at\n[/docs/rpc](/docs/rpc) for the JSON-RPC namespaces.\n\n## /rpc — JSON-RPC (the gateway)\n\nThe product surface. Pick either auth shape:\n\n- **Path-auth** — `POST https://one.valve.city/rpc/:key/:arch/:chainId` — the\n  canonical pattern, copy-paste-friendly with the `vk_demo` key. Example:\n  `POST https://one.valve.city/rpc/vk_demo/evm/369`.\n- **Header-auth** — `POST https://one.valve.city/rpc/:arch/:chainId` with\n  `Authorization: Bearer vk_…` — use this when the URL is shared with a third\n  party (Postman collections, Grafana datasources, etc.) and you want the key\n  out of the path.\n\n### Which chains\n\nThe discovery manifest at `GET /` lists the served chains two ways:\n\n- `surfaces.rpc.chains` groups the bare EVM chain ids by `:arch`\n  (`{ \"evm\": [1, 369, 943, 11155111] }`). These are the `:chainId` values\n  for the paths above.\n- `surfaces.rpc.networks` gives the same chains as CAIP-2 keys\n  (`[\"eip155:1\", \"eip155:369\", …]`), sorted by arch, then chain id.\n\n`surfaces.beacon.chains` and `surfaces.beacon.networks` do the same for\n`/beacon`. `surfaces.chifra.chains` maps each chifra chain name to its chain\nid for `/chifra`.\n\n### Request size and batch limits\n\n| | Before the key is checked | Public key (`vk_demo`) | Project key |\n|---|---|---|---|\n| Request body | **256 KiB** | **1 MiB** | **5 MiB** |\n| Calls in one batch | — | **100** | **1,000** |\n\n- **The body limit depends on your key.** Any body up to 256 KiB is read at\n  once. A larger body is read only for a key that passes all of its own\n  rules (secret, JWT, network, origin and IP), up to that key's limit. Any\n  other request gets the 256 KiB limit.\n- **A body over the limit** gets HTTP 413 and JSON-RPC `-32600`, with\n  `id: null` and a message that names the limit, for example\n  `Request body too large (limit 5 MiB)`. A large body that holds more than\n  100,000 `{`, `[` and `,` characters gets 413 and\n  `Request body too complex`.\n- **A batch over the limit** gets HTTP 400 and one JSON-RPC `-32600` error\n  with `id: null`, for example `batch too large: 1001 calls, max 1000`. No\n  call in it runs, and it costs nothing. Split it into smaller batches. The\n  same limit applies to a batch sent over a WebSocket.\n- **A body that is not valid JSON** gets HTTP 400 and JSON-RPC `-32700`\n  `Parse error`, with `id: null`.\n- **Large bodies are rationed per relay process.** Each process reads at\n  most 3 bodies over 256 KiB at once for project keys, at most 2 of them\n  for one account, and at most 2 of them from one client address. Public\n  keys have 1 such slot of their own, and lose it while the project-key\n  slots are full. Past that, the next large body gets HTTP 503,\n  `Retry-After: 1` and JSON-RPC `-32005`. Retry it. A request that\n  declares a `Content-Length` of 256 KiB or less, or sends no body, is\n  never held back. A chunked request declares no length, so it counts as\n  large.\n- **A large body must arrive within 10 seconds.** A body still arriving then\n  gets HTTP 408 and JSON-RPC `-32600` `Request body not received in time`,\n  and we close the connection.\n\n### Credits per second\n\nEach account can spend a set number of credits in each 1-second window. The\nlimit depends on the account's tier, FULL (1,250,000 credits and 1,000\nrequests per second) or SLOW (125,000 credits and 100 requests per second).\nEvery call in a batch counts, and every key on the account shares the window.\n\n- **Which tier.** An account is FULL when it has paid in at least $1 in all,\n  over its life, AND its balance is at least $0.04. Every other account is\n  SLOW. \"Paid in\" means an x402 payment or an on-chain deposit; free, trial\n  and admin-grant credits never count. A paid total stays yours after you\n  spend it. Under $0.04 the account is SLOW but still served. A deposit that\n  takes the paid total to $1 moves the account to FULL when it lands (an\n  x402 payment when it settles, an on-chain deposit when we see it), or\n  within 5 minutes at the latest.\n\n- **The tier.** Every reply the meter judged carries `X-Valve-Tier`\n  (`FULL` or `SLOW`): a served answer, a throttle and an upstream\n  error. A refusal made before the tier was read carries none.\n- **The window.** A throttled reply, and a served reply the window counted,\n  carry `X-RateLimit-Limit` (credits per window), `X-RateLimit-Remaining`\n  (credits left in this window) and `X-RateLimit-Reset` (whole seconds\n  until the window resets, at least 1). A browser page can read them.\n- **Over the window.** HTTP 429, JSON-RPC `-32005`\n  `Credits per second exceeded`, and a `Retry-After` equal to the time\n  until the window resets, rounded up to whole seconds. The error `data`\n  holds `tier`, `limit`, `cost`, `remaining` and `retryAfterMs`.\n  Every call of a batch gets it. Over WebSocket the `data` is the same.\n- **Larger than the window.** A request or batch whose cost alone is over\n  the tier's limit can never fit. We refuse it at once with HTTP 200 and\n  JSON-RPC `-32602`, with no `Retry-After`, and do not bill it. The\n  message names the cost, the limit and the tier; the `data` holds\n  `tier`, `limit` and `cost`. Split the batch, or deposit to reach\n  the FULL tier's higher limit. Over WebSocket the error is the same.\n- **Whole seconds.** The window is 1 second long, so `X-RateLimit-Reset`\n  and `Retry-After` are always `1`. Read `retryAfterMs` in the error\n  `data` for a finer wait.\n\n`GET /v1/methods` (see below) lists the common methods. It is not the full list. The\ngateway also accepts methods that this list leaves out, such as `msgboard_*` and more\n`ots_*` methods. The gateway forwards methods from these families: `eth_*`, `debug_*`,\n`trace_*`, `erigon_*`, `txpool_*`, `parity_*`, `ots_*` and `msgboard_*`. Each method follows\nthe standard EVM JSON-RPC specification. The reference viewer at [/docs/rpc](/docs/rpc)\nshows the OpenRPC document of each namespace on its own tab, with the parameters and the\nresult of each method. To try a call, send it to\nchain 369 with the public key `vk_demo`.\n\n### Pricing\n\nA credit is a nano-dollar. The price of one call is:\n\n```\nprice = base price x gas multiplier + range charge + size charge\n```\n\nThe base price is the price of the method. The gas multiplier is 1 except for\ncall simulations that ask for a lot of gas. The range charge applies to log\nqueries over a wide block span. The size charge applies to a large answer.\n\n#### Gas multiplier\n\n`eth_call`, `eth_estimateGas`, `eth_createAccessList`, `trace_call`, `debug_traceCall`, `eth_callMany`, `debug_traceCallMany`, `trace_callMany`, `eth_simulateV1` run calls on the node.\nA node lets one such call use up to 500,000,000 gas. The first 50,000,000 gas is in the base price.\nEach further full 50,000,000 gas adds the base price once more:\n\n```\ngas multiplier = max(1, floor(min(gas, 500,000,000) / 50,000,000))\n```\n\nSo 99,999,999 gas costs 1x, 100,000,000 gas costs 2x, and one call is at most 10x.\nThe gas is the `gas` field of the call object; a value we cannot read, or longer than a 64-bit\nnumber, counts as 500,000,000. In `eth_callMany`, `debug_traceCallMany` and `trace_callMany`,\nthe first 50,000,000 gas of each call is included: the multiplier is 1 plus, for each call, its steps\n(clamped to 500,000,000) minus one. A default many-call request is 1x; a large one can pass 10x,\nbecause the node gives each call its own limit. `eth_simulateV1` adds up all calls in all `blockStateCalls`, at most 500,000,000\nin all; a call there with no `gas` field counts as 50,000,000, and a block that sets\n`blockOverrides.gasLimit` and has such a call counts at least that limit.\n\nFor a call with no `gas` field we set `gas` to `0x2faf080` (50,000,000), so it costs 1x, in every\nmethod above except `eth_simulateV1`, which we send as you wrote it. On a project key we never change a\n`gas` value that you set. A call with a `gasPrice` or `maxFeePerGas` gets the same `gas`; a sender that cannot pay for\nit gets an \"insufficient funds\" error, so set `gas` yourself. For `eth_estimateGas` we also lower its\n`blockOverrides.gasLimit` to the priced gas: the node retries a reverting estimate at the block's gas limit.\nOnly the base price is multiplied. Each call in a batch is priced on its own gas. A request whose price\nexceeds the credits-per-second window could never pass the meter, so we refuse it at once with\n`-32602` and do not bill it; send smaller requests.\n\nOn the public key (`vk_demo`), every call runs with at most 50,000,000 gas, as before the node\nlimit went up: we lower a larger `gas`, and in `eth_simulateV1` a larger `blockOverrides.gasLimit`, to\n50,000,000. A simulation whose gas, counted as above, is still over 50,000,000 gets\n`-32602` `simulate gas exceeds 50000000 for the public key; use a project key` and costs nothing. A simulated call with no\n`gas` in a block with no override runs at the chain's block gas limit. Use a project key for more gas.\n\n#### Size charge\n\nThe first 256 KiB (262,144 bytes) of each answer cost nothing extra.\nPast that, a call pays 6,250 credits per 1,000,000 bytes. We bill each started\n65,536-byte chunk, and we round the total up to a whole credit. We measure the\nuncompressed JSON body, not the compressed bytes on the wire. The charge applies\nto every method. `txpool_content` and `txpool_inspect` on a paying project key have paid it since before the size charge\nreached every method (see the `txpool_*` section below). Subscription notifications pay no size charge.\nA per-request payment (x402) pays a flat price: the base price times the gas multiplier, with no size or range charge.\n\n#### Range charge\n\nAn `eth_getLogs` call over 1,000 blocks or fewer pays no range charge. Past\nthat, it pays for each started 1,000 blocks. A filter with a `blockHash` spans 1 block.\nThe rate depends on the chain:\n\n| Chain | Credits per started 1,000 blocks |\n|---|---|\n| 1 | 1,000 |\n| 369 | 250 |\n| 943 | 250 |\n| 11155111 | 1,000 |\n\n`eth_getFilterLogs` pays the same charge on the span of the filter. The span runs\nfrom the `fromBlock` of the filter to its `toBlock`, or to the current head when\n`toBlock` is a tag such as `latest`. A long-lived filter therefore costs more with\neach call. The public key cannot call `eth_getFilterLogs`. A paid key that names a\nfilter id we do not know gets `-32000` `filter not found`.\n\n#### Base prices that changed\n\nOn chain 1, four block-trace methods have their own base price:\n\n| Method | Base credits |\n|---|---|\n| `trace_block` | 4,500 |\n| `debug_traceBlockByNumber` | 6,900 |\n| `debug_traceBlockByHash` | 6,900 |\n| `trace_replayBlockTransactions` | 9,000 |\n\nChains 369 and 943 keep the usual base price of these methods. The size charge covers their cost.\n\nThese status methods cost 250 credits each on chains 1, 369 and 943: `eth_syncing`, `eth_protocolVersion`, `msgboard_status`, `msgboard_categories`.\n`eth_chainId`, `net_version`, `net_listening` are free on every chain.\n\n#### Worked examples\n\n| Call | Credits: base + range + size |\n|---|---|\n| `eth_getLogs`, chain 1, 10,000 blocks, 1,600,000 bytes | 3,000 + 9,000 + 8,602 = **20,602** |\n| `eth_getBlockReceipts`, chain 1, 872,000 bytes | 1,500 + 4,096 = **5,596** |\n| `trace_block`, chain 1, 2,300,000 bytes | 4,500 + 13,108 = **17,608** |\n| `trace_block`, chain 369, 1,572,864 bytes | 1,800 + 8,192 = **9,992** |\n| `debug_traceBlockByNumber`, chain 1, 1,700,000 bytes | 6,900 + 9,012 = **15,912** |\n\nSome calls cost what they cost today. An `eth_call` with no `gas` field or up to\n99,999,999 gas, an `eth_getLogs` call up to 1,000 blocks with an answer under 256 KiB, and each\n`msgboard_subscription` notification do not change. The WebSocket price of an `eth_subscription`\nnotification does change. The WebSocket Billing section gives it.\n\n#### Block-range caps\n\nA log query may not span more blocks than the cap of your key:\n\n| Key | Cap, in blocks |\n|---|---|\n| Public key | 1,000 |\n| Project key | 10,000 |\n\nOur own internal keys have a cap of 100,000 blocks. The project cap is 1,000 for `trace_filter`. A call over the cap gets HTTP 200\nand this error. It costs nothing:\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"error\": {\n    \"code\": -32602,\n    \"message\": \"query exceeds max block range 10000\",\n    \"data\": { \"maxBlockRange\": 10000, \"requestedRange\": 25000 }\n  }\n}\n```\n\nOn the public key the message ends with `for this key; use a paid key for wider ranges`.\n\nA project key has the same rules as the public key for a filter we cannot\ncheck against the cap. We refuse it with HTTP 200 and `-32602`, and it costs nothing:\n\n| You sent | Message |\n|---|---|\n| A filter field we do not know | `unknown filter field <name>` |\n| More than 100 addresses in `address` | `address list longer than 100` |\n| More than 100 alternatives in one topic position | `topic list longer than 100` |\n| More than 4 topic positions | `more than 4 topic positions` |\n| `safe` or `finalized` together with a block number | `use numeric block bounds with safe or finalized on this key` |\n| Two different tags, such as `finalized` to `latest` | `use numeric block bounds for this range on this key` |\n| A tag such as `latest` while our view of the chain head is stale | `chain head unknown; use numeric block bounds` |\n\nThe same tag at both ends, and `latest` to `pending`, span 1 block and pass. A\nquery with two block numbers never needs the chain head.\n\nIn a batch, the log queries together may not span more blocks than the cap. The\ncall that takes the total past the cap gets `-32602` with the message\n`batch exceeds max total block range 10000`. It costs nothing.\n\n#### Answers that are too large\n\nWe refuse an answer over 150,000,000 bytes with `-32005` `response size exceeded`.\nWe bill that call as an answer of exactly 150,000,000 bytes, because the node did the work.\nAfter repeated oversize answers (3 in 60 seconds, per key, chain and method, on each\nrelay worker), we refuse a repeat of one of those calls before we send it to a node.\nA repeat is the same method with the same params, or the same batch. That call gets\n`-32005` `too many oversize responses; narrow the request`, and it costs nothing.\nEvery other call of the method goes through as usual.\nNarrow the request, or wait for the window to end.\n\nOn a WebSocket, the cap is 104,857,600 bytes (100 MiB). An answer over it\nends the socket with close code `4005`. Each call still waiting on that socket keeps the charge we took when we admitted\nit: the base price plus the range charge. It pays no size charge. The close counts toward\nthe pause above for each method that had a call waiting.\n\nIn a batch, a call with a `null` id gets `-32600` `null id in batch`.\nEvery call whose id another call in the batch shares gets `-32600`\n`duplicate id in batch`. We do not run these calls and we do not charge them.\n\n#### Headers\n\nA served answer, and an answer refused as too large, carry two headers. The\nthrottle refusal and every other refusal omit them.\n\n- `X-Valve-Billed-Bytes` is the number of response bytes we billed. For a batch,\n  it counts the upstream bytes plus the whole JSON envelope of each answer we served\n  ourselves.\n- `X-Valve-Credits` is the total credits we debited for the call or the batch.\n\nA browser page can read both headers on a cross-origin call.\n\n### Methods we refuse, and `txpool_*` on project keys\n\nWe refuse these methods for every key:\n\n- `personal_*` and `miner_*`;\n- `web3_clientVersion`, `admin_*` and `reth_*`;\n- the node-operator controls `debug_set*`, `debug_db*` and\n  `debug_chaindb*`. Tracing (`debug_trace*`) stays open.\n\nA paying project key can read the pending pool with four `txpool_*`\nmethods. A paying key is one whose calls we bill to your credits or per\nrequest. A credit-exempt key does not get them.\n\n- `txpool_status`\n- `txpool_content`\n- `txpool_contentFrom`\n- `txpool_inspect`\n\nWe refuse every other `txpool_*` method. Your key's method policy still\napplies: the `standard` policy denies `txpool_*`. A refused method gets\nJSON-RPC `-32000` with a message that names the method.\n`txpool_content` returns the whole pool, which can be tens of megabytes on\nchain 1.\n\n`txpool_content` and `txpool_inspect` bill the base price plus a size charge on\nthe uncompressed answer. The first 262,144 bytes are included. Past them, we bill\n6,250 credits per 1,000,000 bytes, counted in started 65,536-byte chunks. For example, a\n9,000,000-byte answer adds 54,887 credits. We count the bytes before compression, so a\ngzip answer costs the same as a plain one. The `X-Valve-Billed-Bytes` header\nreports the bytes we billed, and `X-Valve-Credits` reports the credits we debited.\nWe refuse an answer over 150,000,000 bytes and bill it at the cap: the base price plus\n935,936 credits. A key that pays per request (x402) gets `-32000` for these two\nmethods, because its price is fixed before the call.\n\nThe free tier (the demo key `vk_demo`, and any key with per-IP limits) gets\nthe same four methods, with limits:\n\n- `txpool_status` works on every chain, under the tier's normal limits.\n- `txpool_content`, `txpool_inspect` and `txpool_contentFrom` work on\n  chains 369 and 943 only. Each client IP address gets one call to any of\n  the three every 10 seconds on each chain. All free-tier callers together\n  get 10 calls per second. Over a limit, you get HTTP 429, JSON-RPC\n  `-32005` and a `Retry-After` header.\n- We cache each answer for 10 seconds, so a free-tier answer can be up to\n  10 seconds old.\n- Send these three as single requests. Inside a batch they get `-32000`.\n- Free-tier calls cost no credits. They still count toward the key's daily\n  request limit.\n\n### `msgboard_*` — Distributed MsgBoard sub-protocol\n\nPulseChain reth nodes expose the [msgboard](https://msgboard.xyz) sub-protocol — permissionless,\nephemeral, proof-of-work-gated on-chain messages. valve relays the namespace through\nthe same `vk_` key surface; per-chain availability is auto-detected via a periodic\n`msgboard_status` probe and surfaced on the chain-health dashboard.\n\nCanonical method definitions live in msgboard's own OpenRPC document at\n[msgboard.xyz/openrpc.json](https://msgboard.xyz/openrpc.json) (v0.0.28 at time of writing:\n`msgboard_status`, `msgboard_categories`, `msgboard_content`, `msgboard_addMessage`,\n`msgboard_getMessage`). A frozen snapshot ships with this api at `packages/api/specs/msgboard.openrpc.json`\nas a vendored fallback; the docs UI does not (yet) render OpenRPC inline — until that lands,\ntreat msgboard.xyz as the source of truth for method semantics.\n\nGaps to file upstream with the msgboard maintainers when convenient: the published OpenRPC\nomits the `msgboard_subscribe` / `msgboard_unsubscribe` pair, which IS implemented\nupstream (`valve-tech/reth/crates/net/msgboard/src/rpc_api.rs` around line 161 —\n`#[subscription(name = \"subscribe\", unsubscribe = \"unsubscribe\", item = RPCMessage)]`).\nValve relays both today.\n\n## /ws — WebSocket (vk_ key)\n\nThere are TWO websocket surfaces. Do not miss the second one.\n\n`/ws/health` streams per-chain health frames as the relay's view of upstream\nstatus changes. One frame per state transition; consumers can derive the current\nview by reading the most recent frame per chain.\n\n**The RPC endpoint itself accepts a websocket upgrade**, on the same path as\nHTTP with a `wss://` scheme and no separate route:\n\n```\nwss://one.valve.city/rpc/<key>/evm/<chainId>\n```\n\nIt carries ordinary JSON-RPC — single and batch — and live\n`eth_subscribe` / `eth_unsubscribe` for `newHeads`, `logs` and\n`newPendingTransactions`. On chains that run the msgboard protocol the\n`msgboard_subscribe` / `msgboard_unsubscribe` pair rides the same socket.\n\nThe key goes in the PATH here, not a header: a browser's WebSocket constructor\ntakes a url and a subprotocol list and cannot send `Authorization`. A\nserver-side client that CAN set headers may still use the header form.\n\n### Billing\n\nEvery call you send bills exactly as it does over HTTP, single or batch. A\nsubscription bills twice over: once to establish it, then again for **each\nnotification we push you**. A busy `logs` or `newPendingTransactions`\nsubscription is therefore a continuous charge, not a one-off — size your budget\nagainst the notification rate, not the call count.\n\n| What | Credits |\n|---|---|\n| `eth_subscribe`, once per subscription | 750 |\n| Each `eth_subscription` notification | 4,500 |\n| Each `msgboard_subscription` notification | 1,500 |\n| Each subscription-hour a subscription stays open | 25,000 |\n| One `eth_getLogs` call, for comparison | 3,000 |\n\nA credit is a nano-dollar. The `eth_subscription` price applies on chains\n1, 369, 943, 11155111. Other chains bill 1,500 credits for each notification.\n\nWe also charge for the time a subscription stays open. The charge is\n25,000 credits per subscription-hour, about $0.018 per subscription per month.\nIt applies to every open subscription on every chain, from the price date.\nA credit-exempt key is a key that pays no credits. It pays no subscription-hour charge.\n\nA `logs` subscription sends one notification for each matching log. So a\nblock with 65 matching logs costs 292,500 credits\nover a subscription. One `eth_getLogs` call that fetches the same block costs\n3,000. For a busy filter, polling costs less. A subscription gives you each\nlog as soon as we see it.\n\n### Connection limits\n\nWe enforce these limits. A client that ignores them sees what looks like an\nunexplained disconnect. Plan for all seven.\n\n- **A connection can stay open for about 24 hours.** At that safety cap we\n  close it with code `4008`. This applies to every key, on both tiers. The\n  cap has jitter, so the whole fleet does not reconnect in the same second.\n  We send no message before the close. Your subscriptions do not survive a\n  close. Reconnect and subscribe again.\n- **We ping every connection every 30 seconds.** Any frame from you counts as\n  a sign of life: a pong, a ping of your own, a request. Every standard\n  WebSocket client answers pings on its own. A client that sends nothing at\n  all for two pings in a row is closed with code `4011`. Five minutes with\n  no frame at all closes it with `4003`.\n- **We re-check your key every minute.** A revoked key closes with `4001`,\n  and a project whose credits run out closes with `4006`, within about a\n  minute, even on a connection that sends nothing.\n- **The demo key (`vk_demo`) is the public tier.** Its connection lifetime\n  is the same as a project key's: up to about 24 hours. Its other limits are much\n  tighter: 24 concurrent connections per IP address, 2 subscriptions per\n  connection, and `eth` plus `msgboard` subscriptions only. On that tier\n  we refuse `newPendingTransactions`. We also refuse `logs` unless you\n  pass a non-empty `address` or `topics` filter. A project key has none of\n  these restrictions.\n- **The per-IP cap counts addresses, not people.** One address can carry a\n  household, an office, a VPN exit or a mobile carrier's customers. All of\n  them share the 24. If you run many public-tier clients from one address,\n  use a project key instead. Code `4010` tells you that you reached the cap.\n- **A closing connection stops counting at once.** At the lifetime close and\n  the idle close, we release your slot before we send the close. You can\n  reconnect the moment you see the close. The connection you replace does not\n  count against you. A full restart of the relay can exit before the release\n  finishes. A slot it misses stops counting within about four minutes.\n- **A client that stops reading gets disconnected.** We bound how much we\n  buffer for you. Exceed it and the connection closes with code `4009`.\n- **A rate limit delays notifications; it does not disconnect you.** A\n  notification costs credits and counts toward your credits-per-second\n  limit. It does not count toward your requests-per-second limit: only your\n  own requests and `eth_subscribe` calls do. When a notification would go\n  over a limit, we hold it, and the ones behind it, in order, until the\n  limit allows it. We bill each held notification before we send it. Only if the hold\n  grows too long do we close, with `4029`. Running out of credits closes\n  with `4006`.\n- **On a paid key we pace notifications.** We send them evenly, at the rate\n  your credits-per-second limit allows, shared over your connections that are receiving notifications.\n  Each connection has its own pace, so a burst on one chain does not hold up\n  another. A block with many matching logs arrives complete and in order,\n  spread over up to a few seconds, instead of hitting the limit part way.\n\n### Close codes\n\n| Code | Meaning |\n|------|---------|\n| `1006` | The connection dropped with no close frame (reported by your client, not sent by us). Reconnect with backoff. |\n| `1009` | A frame you sent was over 100 MiB. |\n| `1011` | Internal error while we set up your connection: a key or connection check failed, or did not finish within 10 seconds. Nothing you sent was billed. Reconnect with backoff. |\n| `1012` | Service restart. We restarted the relay, or retired the older relay process your connection was on. Reconnect now. |\n| `1013` | Try again later. We held your notifications while our metering could not answer (reason `Metering unavailable, retry later`), or while a per-request payment held your account (reason `Payment in progress, retry later`), and the hold grew past what we keep for you. Reconnect with backoff. |\n| `4000` | Malformed path |\n| `4001` | Invalid, revoked or inactive key |\n| `4002` | Chain not served |\n| `4003` | Idle timeout (five minutes with no frame from you, not even a pong) |\n| `4005` | Upstream closed and did not come back, or the upstream closed your connection for a policy reason (we close you at once, with the upstream code in the reason) |\n| `4006` | Your account is out of credits (reason `Out of credits`), or it is closing (reason `Account closing`). Add credit before you reconnect. A rate limit never sends this code. |\n| `4008` | Safety cap reached, after about 24 hours (expected; reconnect) |\n| `4009` | You are not reading fast enough, or your subscriptions push more notifications than we can bill (more than 10,000 waiting), or you sent more than 64 frames or 1 MiB before we finished checking your key. After an upstream restart, new notifications wait while we send the ones you missed, and they count toward the 10,000, so heavy traffic during a long fill can end in `4009` |\n| `4010` | Too many concurrent connections from your IP address |\n| `4011` | Ping timeout: you sent no frame, not even a pong, for two of our pings |\n| `4012` | Upstream buffer overflow |\n| `4013` | Your subscription fell too far behind upstream. Subscribe again, then fetch what you missed from your last block. |\n| `4029` | Rate limited (reason `Rate limited, retry later`), or a daily limit reached (reason `Daily request limit reached` or `Daily CU limit reached`). A rate limit delays your notifications; it does not close the connection by itself. We close with this code only when the delay grows past what we hold for you: the notifications waiting behind a rate-limited one pass our backlog limit, one of them waits 30 seconds, or our upstream node restarts while they still wait 10 seconds later. A daily limit closes at once, because it does not clear until the next day. We bill a held notification before we send it. Reconnect with backoff. |\n| `4014` | We could not fill the gap after an upstream restart. Subscribe again, then fetch what you missed from your last block. A connection with more than 256 `newHeads` and `logs` subscriptions (`WS_BACKFILL_MAX_SUBS`) always gets `4014` on an upstream restart. |\n\nWhen an upstream node restarts, we hold your connection open. We open your\nsubscriptions again on the new upstream, on the same subscription ids. Then we\nsend the `newHeads` and `logs` notifications you missed, in order, before\nany new ones. If we cannot fill that gap, or it needs more notifications than\nour per-restart limit, we close you with `4014`. Logs from the last few\nblocks before the head are best effort: if the upstream's `logs` push trails\nits head by more than 4 blocks when it drops, you can miss them. We close you\nwith `4005` if the upstream stays down past our retry window, or at once on\nan upstream policy close. A deploy keeps your\nconnection too: the relay process you are on stops taking new connections and\nkeeps yours. When a second deploy follows\nwhile you are still connected, or we restart the relay, we close you with\n`1012`, and the service is back within a few seconds. Your client sees\n`1006` only when the network breaks, or when a server dies without a clean\nstop.\n\n### Reconnect and fill the gap\n\nExpect a close at least once a day, and sometimes when we deploy. After you\nreconnect, subscribe again. Then fetch what you missed with `eth_getLogs` or\n`eth_getBlockByNumber`, from the last block you handled. No common client\ndoes this last step for you.\n\n| Close code | viem 2.x | web3.js v4 | ethers v6 |\n|---|---|---|---|\n| `4008` safety cap | reconnects, can stall | reconnects | does not reconnect |\n| `1012` restart | reconnects, can stall | reconnects | does not reconnect |\n| `4003` idle | reconnects, can stall | reconnects | does not reconnect |\n\nIn each sample below, `handle` stands for your own code.\n\n**viem** reconnects 2 seconds after a close, and it subscribes again for you.\nIf that attempt fails, viem does not try again at once. Its next attempt waits\nfor its keep-alive request, up to 30 seconds later. After a short outage, viem\nstays blind until that next keep-alive tick. After 4 failed attempts, 1.5 to 2\nminutes after the close, it drops your subscriptions. It raises no error for\nthe drop. It can still connect once more, but it does not subscribe again.\nWith `keepAlive: false`, one failed attempt stops it.\n\nSo the sample below turns viem's reconnect off and reconnects by itself. It\nalso starts again when no block arrives for 60 seconds. viem keeps one socket\nfor each URL and gives it to every client, even after the socket dies. So the\nsample closes the dead socket before it watches again. viem cannot see the\nclose code, so the sample also retries after `4001`.\n\nviem's `emitMissed` option works only in poll mode, so it does not fill a gap\non a subscription. Do not rely on the previous block that `watchBlocks` passes\nto `onBlock`. When a close lands while viem fetches a block, viem passes no\nblock and forgets the previous one. Keep your own record of the last block you\nhandled. The sample handles each block number once, so it skips a reorg at a\nheight it already handled:\n\n```ts\nimport { createPublicClient, webSocket } from 'viem'\nimport { mainnet } from 'viem/chains'\n\nconst client = createPublicClient({\n  chain: mainnet,\n  // watch() reconnects by itself, so viem's own reconnect is off.\n  transport: webSocket('wss://one.valve.city/rpc/<key>/evm/1', { reconnect: false }),\n})\n\nlet last: bigint | undefined // the last block your app handled\nlet queue = Promise.resolve() // runs one catch-up at a time\n\nfunction watch() {\n  let timer: ReturnType<typeof setTimeout> | undefined\n  let stopped = false\n  const restart = async () => {\n    if (stopped) return\n    stopped = true\n    clearTimeout(timer)\n    unwatch()\n    // viem gives a dead socket to every new request. Close it, so the next watch opens a new one.\n    await client.transport.getRpcClient().then((rpc) => rpc.close(), () => {})\n    setTimeout(watch, 2_000)\n  }\n  // 60 seconds is five missed 12-second blocks, so one slow block does not trip it.\n  const rearm = () => { clearTimeout(timer); timer = setTimeout(restart, 60_000) }\n  rearm()\n  const unwatch = client.watchBlocks({\n    onBlock: (block) => {\n      rearm()\n      if (!block) return // viem passes no block when its own fetch fails\n      queue = queue.then(async () => {\n        // Move last only after handle(), so a failed fetch is retried on the next head.\n        for (let n = last === undefined ? block.number : last + 1n; n <= block.number; n++) {\n          handle(n === block.number ? block : await client.getBlock({ blockNumber: n }))\n          last = n\n        }\n      }).catch((error) => console.warn(error))\n    },\n    // viem passes a SocketClosedError here when the socket closes.\n    onError: (error) => { console.warn(error); restart() },\n  })\n}\nwatch()\n```\n\nTo fetch logs, keep the sample's reconnect and gap-detection logic. Replace\nthe inner per-block loop with one `client.getLogs` call, from the block after\n`last` to `block.number`. Then set `last` to `block.number`. Do not use\n`watchEvent` for this. A `watchEvent` log does not tell you that its block\nis complete, so a fill from the next block can miss a log. If you do not watch\nblocks, use the plain recipe below.\n\n**web3.js v4** reconnects on these three codes. It waits 5 seconds and tries up\nto 5 times. It does not subscribe again. After it reconnects, call\n`resubscribe()` on each subscription you hold. Then fetch the gap. web3.js\ndoes not reconnect after a clean `1000` or `1001`. It emits `disconnect`\ninstead. A proxy on the path can send `1001`. Listen for the provider's\n`disconnect` event and reconnect yourself.\n\n**ethers v6** does not reconnect on any code. In v6.17.0 its WebSocket close\nhandler is commented out. You must detect the close, create a new provider and\nsubscribe again. The recipe below does the same job on a plain `WebSocket`.\nYou can use it for your subscriptions and keep ethers for everything else.\n\n**A plain WebSocket, for any client.** This works in a browser and in Node.js\n22 or later. On each open it reads the current block with\n`eth_blockNumber`, and it subscribes only after that reply. A close before\nthe reply leaves nothing subscribed, so nothing is missed. On the first open\nit keeps that block as the checkpoint. After the subscribe reply, it fetches\nthe logs from the checkpoint to the latest block. That fetch also catches a\nlog mined just before the subscription started.\n\nWhen the fetch succeeds, the sample moves the checkpoint to the block it read\non this open. So each fetch covers about one connection lifetime, a few\nhundred blocks. The range includes the checkpoint block itself, and the set\ndrops the repeats. The set keys each log by block hash and log index. A log\nthat a reorg moves to a new block therefore counts as new, and so does a\n`removed: true` notice.\n\nA failed request prints the error and changes nothing. After a failed fetch,\nthe next fetch covers two connection lifetimes. That retry waits for the next\nclose, up to an hour later. The sample retries every close except `4000`,\n`4001` and `4002`. Those mean the URL or the key is wrong.\n\n```js\nconst url = 'wss://one.valve.city/rpc/<key>/evm/1'\nconst filter = { address: '0xYourContract' }\nconst seen = new Set() // one \"blockHash:logIndex\" per log you handled\nlet checkpoint = null // the hex block number where the next fill starts\n\nfunction onLog(log) {\n  // A reorg notice (removed: true) has the key of the log it removes, so mark it.\n  const id = log.blockHash + ':' + log.logIndex + (log.removed ? ':removed' : '')\n  if (!seen.has(id)) { seen.add(id); handle(log) }\n}\n\nfunction connect() {\n  const ws = new WebSocket(url)\n  const send = (id, method, params) => ws.send(JSON.stringify({ jsonrpc: '2.0', id, method, params }))\n  let head\n  ws.onopen = () => send(2, 'eth_blockNumber', [])\n  ws.onmessage = ({ data }) => {\n    const msg = JSON.parse(data)\n    // A failed request changes nothing. The next reconnect tries again.\n    if (msg.error) return console.warn('request', msg.id, 'failed', msg.error)\n    if (msg.method === 'eth_subscription') onLog(msg.params.result)\n    // Subscribe only after the head arrives. Then fill from the checkpoint.\n    if (msg.id === 2) { head = msg.result; checkpoint ??= head; send(1, 'eth_subscribe', ['logs', filter]) }\n    if (msg.id === 1) send(3, 'eth_getLogs', [{ ...filter, fromBlock: checkpoint }])\n    if (msg.id === 3) { msg.result.forEach(onLog); checkpoint = head }\n  }\n  ws.onclose = ({ code }) => { if (![4000, 4001, 4002].includes(code)) setTimeout(connect, 2000) }\n}\nconnect()\n```\n\nBoth samples above retry every 2 seconds, forever, on every close code. This\nincludes `4001` (bad key) and `4010` (per-IP cap). A production client\nshould back off between retries, not retry at a fixed interval. It should\nalso stop retrying after `4001`. A production app also prunes the set and\nhandles reorgs.\n\n## /beacon — consensus-layer REST (vk_ key)\n\n`GET https://one.valve.city/beacon/:key/:chainId/*` proxies the beacon\n(consensus-layer) REST API. The key goes in the path, exactly as\n`/rpc/:key/:arch/:chainId` does, and it is the same `vk_` project key —\nthere is no separate credential and no public/demo key on this surface.\n\n- **GET only, and read-only.** Paths are matched against an explicit\n  allowlist of `/eth/v1/**` and `/eth/v2/**` read endpoints; anything else\n  returns 404. The beacon API's write endpoints (`POST /eth/v1/beacon/blocks`,\n  pool submissions) are never reachable — these nodes back valve's own\n  validators.\n- **Chains 1, 369, 943 and 11155111.** These are the networks with a\n  lighthouse node, which is not the same list as the chains valve serves RPC\n  for; read the authoritative list from `surfaces.beacon.chains` in the\n  discovery manifest at `GET /`. `surfaces.beacon.networks` gives the same\n  list as CAIP-2 keys (`eip155:369`). Any other chain id returns 404.\n- **Priced per endpoint, like RPC.** Every allowlisted path maps to one\n  `beacon.*` method key in the same `method_pricing` table the JSON-RPC\n  methods use, so the same credits, rate limits and CU limits apply. Per-key\n  method policies apply too: a key restricted to an explicit method list does\n  not reach `/beacon` until the `beacon.*` keys are added to that list.\n- **`/eth/v1/beacon/states/{id}/validators` and `.../validator_balances`\n  require `?id=` or `?status=`.** Unfiltered they return up to 1.07 GB on\n  chain 1, so an unfiltered call returns 400.\n- **25 MB response cap.** A response over the cap returns 413 and is still\n  billed — the node did the work to produce it. Note that `?status=active`\n  selects the whole active validator set and stays over the cap on a large\n  network; narrow the query with `?id=`, or read one validator at\n  `/eth/v1/beacon/states/{state_id}/validators/{validator_id}`.\n- **Old blocks on chain 943: use `/eth/v1/beacon/blinded_blocks/{block_id}`.**\n  Below the live node's oldest block, `/eth/v2/beacon/blocks/{slot}` answers\n  404, because the archive holds no payloads. The blinded route answers from the\n  archive, at the price of a full block (1000 credits). Only a 404 with\n  `X-Valve-Beacon-Origin: archive` is an empty slot, for a slot below the\n  archive's head. A 404 with origin `a` or `b` means the relay did not reach\n  the archive: retry it.\n  `Eth-Consensus-Version` names the fork. To rebuild the full block, call\n  `debug_getRawBlock(block_hash)`, with `block_hash` from the blinded block's\n  `execution_payload_header`, for the transactions and\n  `eth_getBlockByHash(block_hash, false)` for the withdrawals. Copy the header's\n  fields into `execution_payload`, and require `hash_tree_root(block)` to\n  equal the root from `/eth/v1/beacon/blocks/{slot}/root`. The route passes\n  `execution_optimistic` through unchanged. On the archive it stays `true` and\n  says nothing about the old block. Read `X-Valve-Credits` for the cost of\n  `debug_getRawBlock`. The root check held on 268 payload blocks of chain 943\n  (bellatrix and capella, transaction types 0x0 and 0x2), with payload fields\n  taken from reth, which is stricter than copying them from the header. That test\n  ran against the box's reth, not through the gateway. A sample of 8 blocks\n  through the public RPC with a demo key returned the same data. Chains 369 and 1\n  are untested.\n- **`/eth/v1/events` is excluded.** It is a Server-Sent Events stream with no\n  response size and no end.\n\n## /chifra — TrueBlocks chifra, read-only (vk_ key)\n\n`GET https://one.valve.city/chifra/:key/<endpoint>?chain=<name>&...` proxies\n[TrueBlocks chifra](https://trueblocks.io/api/), the address appearance index.\nThe key goes in the path, as on `/beacon`. It is the same `vk_` project key,\nand there is no public or demo key on this surface. Example, on PulseChain:\n`GET https://one.valve.city/chifra/<YOUR_KEY>/list?addrs=0x…&chain=pulsechain`.\n\n- **Endpoints: `/list`, `/export`, `/status` and `/when`.** Every other\n  path returns 404, including `/monitors`, `/config`, `/scrape`, `/chunks`,\n  `/init` and `/slurp`. `surfaces.chifra.endpoints` in the discovery\n  manifest at `GET /` lists them.\n- **GET and HEAD only.** Any other method returns 405.\n- **Read parameters only.** chifra's writes are query parameters (`cache`,\n  `decache`, `update`, `repair` and others), so each endpoint accepts a fixed\n  list of the read parameters from chifra's API. Any other parameter returns\n  400 and names the parameter.\n- **The chain is chifra's `chain` parameter, by name:** `pulsechain` (369),\n  `pulsechain-v4` (943), `mainnet` (1) or `sepolia` (11155111). PulseChain's\n  index is current; the `pulsechain-v4` index runs well behind its chain head,\n  so read `/status?chain=pulsechain-v4` before you rely on it. With no\n  `chain`, the relay uses `mainnet`, chifra's own default. Any other name, or a\n  chain id, returns 400. The key's network rules apply to that chain.\n- **JSON only, and no internal errors.** `fmt` may only be `json`. When chifra\n  reports a problem inside an answer, `errors` holds one entry with\n  `code: \"chifra_error\"`; chifra's own text never reaches you. A request chifra\n  refuses returns its status with `code: \"chifra_rejected\"`, unbilled.\n- **`firstBlock` and `lastBlock` are both inclusive.** `firstBlock` equal to\n  `lastBlock` asks for one block. A `firstBlock` later than `lastBlock`\n  returns 400 with `code: \"invalid_block_range\"`. When chifra refuses your\n  parameters, you get a 400 with a fixed `code` (`invalid_block_range`,\n  `block_beyond_head` or `invalid_address`) and our own message, unbilled,\n  never an empty answer.\n- **`/export?approvals` returns transactions, not logs (changed 2026-11-24).**\n  chifra 6 returns each transaction that holds an ERC-20 `Approval` log, with\n  `hash`, `from`, `to`, `input` and its `receipt`; the logs are inside\n  `receipt.logs`. Before, it returned one record per `Approval` log\n  (`address`, `topics`, `data`, `logIndex`). Every other endpoint and\n  parameter keeps its shape.\n- **Priced per call.** Every endpoint has one price, the `chifra.call` row in\n  the same `method_pricing` table the JSON-RPC methods use, so the same credits,\n  rate limits and CU limits apply. `X-Valve-Credits` gives the credits each\n  call cost. A failed call is not billed. Per-key method policies apply: a key\n  restricted to an explicit method list does not reach `/chifra` until the\n  `chifra.*` keys (`chifra.list`, `chifra.export`, …) are added to it.\n- **25 MB response cap, 30 s timeout.** A response over the cap returns 413 and\n  is still billed, because chifra did the work. Narrow an `/export` with\n  `firstRecord`/`maxRecords` or `firstBlock`/`lastBlock`. A timeout returns\n  504, unbilled.\n\n## /mempool — mempool GraphQL, keyed (vk_ key)\n\n`POST https://one.valve.city/mempool/:key/graphql` (or `/mempool/:key/query`)\nserves the [mempool.valve.city](https://mempool.valve.city) GraphQL API with your\nproject key: where a pending transaction was seen, at which public endpoints, and\nwhen. It is the same API and the same schema\n(`https://mempool.valve.city/query/schema.graphql`). Without a key, use\n`https://mempool.valve.city/query`, limited per caller address to 60 requests a\nsecond and 600 a minute. With a key, your key's own limits apply instead. Example:\n`curl -s https://one.valve.city/mempool/<YOUR_KEY>/graphql -H 'content-type: application/json' -d '{\"query\":\"{ endpoints { id name chainId } }\"}'`.\n\n- **100 requests a second per key on every tier.** SLOW and FULL keys alike:\n  the server behind this surface runs on four database connections, so the\n  gateway caps `mempool.call` at 100 a second per key. The key's own limits\n  and the account ceiling still apply when they are lower. Past the cap you get\n  429 with `Retry-After: 1`. Other refusals get the `/rpc` answers: 429 over\n  a rate limit, 402 with no credits. A bad key gets 401. The public and demo\n  keys (`vk_demo`) get 403: use the unkeyed endpoint.\n- **POST, or GET with `?query=`.** The body is one JSON object with\n  `query`, and optionally `operationName` and `variables`. Other fields are\n  dropped. A persisted-query hash without the query text returns 400.\n- **Queries only.** A batch (a JSON array of operations) returns 400: send one\n  operation per request. A subscription returns 400: the live census websocket\n  stays on `wss://mempool.valve.city/query`. A mutation returns 403. The API\n  has no mutations; the gateway refuses one anyway.\n- **Priced per request: 1,500 credits,** the same as an `eth_getBlockByNumber`\n  call on our own chains. One row, `mempool.call`, in the same\n  `method_pricing` table the JSON-RPC methods use, prices every query on every\n  chain. `X-Valve-Credits` gives the credits each call cost. A served answer is\n  billed, even when it carries GraphQL `errors`, because the server ran the\n  query. A refused query (a GraphQL validation error) keeps its status, 422 or\n  400, and is not billed. An upstream failure or a timeout (504) is not billed.\n- **Networks and methods.** The key's method policy applies to the method key\n  `mempool.query`. One query can span chains, so the gateway checks and bills\n  the default network: a key restricted to an explicit network list returns 403.\n- **10 MB response cap, 15 s timeout.** A response over the cap returns 413 and\n  is billed, because the server did the work. The server itself stops a query\n  at 10 s and returns 504.\n\n## /pay — x402 facilitator primitives (keyless)\n\nThe `/pay/*` surface implements the [x402 protocol](https://x402.org/) and is\nkeyless — the EIP-3009 `transferWithAuthorization` payload in the\n`X-PAYMENT` header *is* the credential. All five `/pay` endpoints\n(`/supported`, `/verify`, `/settle`, `/settle/{authId}`, `/health`) are\nREST-shaped and documented in this spec under the `x402` tag.\n\n**Architecture note.** `/pay/*` is reverse-proxied by Caddy to the standalone\n**facilitator service**, not this api process — `/pay` is where x402 clients\nexpect to find a facilitator's spec'd primitives. `POST /v1/credits/topup`\nis a different shape: a **valve api workflow endpoint** that accepts an x402\n`X-PAYMENT` header, calls the facilitator to verify+settle the payment, and\nthen issues credits to the caller's valve account in one round-trip. Two\nprefixes by design — `/pay` is the protocol primitives (facilitator,\nspec-shaped), `/v1` is the management surface (this api, business-shaped),\nand the x402-tagged endpoints in this document live on whichever side handles\nthe actual logic. Tag-cross-reference: every endpoint that consumes the x402\ncredential is tagged `x402` regardless of which prefix it ships under.",
    "contact": {
      "email": "dev@valve.city"
    },
    "license": {
      "name": "MIT",
      "identifier": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://one.valve.city",
      "description": "production"
    },
    {
      "url": "http://localhost:3010",
      "description": "local api"
    }
  ],
  "tags": [
    {
      "name": "auth",
      "description": "wallet sign-in, session tokens, CLI auth"
    },
    {
      "name": "accounts",
      "description": "account + address management"
    },
    {
      "name": "projects",
      "description": "project + key management"
    },
    {
      "name": "credits",
      "description": "top-up, refund, balance, refresh (admin)"
    },
    {
      "name": "tokens",
      "description": "session-token (vt_…) management for browser + CLI bearers"
    },
    {
      "name": "provider",
      "description": "verify, status, domain proofs"
    },
    {
      "name": "method-policies",
      "description": "per-project RPC method allow-lists"
    },
    {
      "name": "analytics",
      "description": "project + account stats"
    },
    {
      "name": "system",
      "description": "methods, stats, health"
    },
    {
      "name": "substreams",
      "description": "substreams gRPC gateway discovery + pricing (covers both sf.substreams.* and sf.firehose.* services)"
    },
    {
      "name": "graphql",
      "description": "GraphQL endpoint + introspection"
    },
    {
      "name": "x402",
      "description": "keyless payment endpoints (/pay)"
    }
  ],
  "components": {
    "securitySchemes": {
      "sessionToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "session",
        "description": "Issued by `POST /v1/auth/verify`; sent as `Authorization: Bearer <token>`."
      },
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "vk_",
        "description": "Project key (`vk_…`). Used on `/rpc`, `/ws`, and a small set of `/v1` read endpoints. The same key is validated by relay against the keystore."
      },
      "x402": {
        "type": "apiKey",
        "in": "header",
        "name": "X-PAYMENT",
        "description": "Out-of-band — see the `/pay` appendix in this spec's description and x402.org. Keyless: the EIP-3009 `transferWithAuthorization` payload is the credential."
      },
      "walletAccessUntil": {
        "type": "apiKey",
        "in": "header",
        "name": "x-valve-until",
        "description": "EIP-712 access proof — unix timestamp (seconds) declaring when this signature expires. Pair with `x-valve-signature`. Issued by signing the `Access(uint256 validUntil)` typed-data payload (see `ACCESS_DOMAIN` / `ACCESS_TYPES` in `@valve/types`)."
      },
      "walletAccessSignature": {
        "type": "apiKey",
        "in": "header",
        "name": "x-valve-signature",
        "description": "EIP-712 access proof — hex signature of the Access typed-data payload (same `validUntil` as the paired `x-valve-until` header). The recovered signer address is mapped to an accountId via Redis cache → Postgres lookup. Expired or unmapped signatures return 401."
      }
    }
  },
  "paths": {
    "/v1/auth/verify": {
      "post": {
        "tags": [
          "auth"
        ],
        "summary": "Verify wallet ownership and issue/create account",
        "description": "Recovers the signing address from an EIP-712 signature over the access domain. Creates a fresh account on first sight; otherwise updates `lastLoginAt`. Address → `accountId` is cached in Redis so subsequent `vk_` validation in the relay can resolve owner-account without a DB round-trip. The first-time PRVX trial-credit grant runs out-of-transaction (a Postgres hiccup on the grant must not fail signup) and is idempotent on `tx_hash`.",
        "operationId": "authVerify",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "validUntil": {
                    "type": "integer",
                    "description": "Unix seconds after which the signature is rejected."
                  },
                  "signature": {
                    "type": "string",
                    "description": "EIP-712 signature over `{ validUntil }` against the access domain."
                  }
                },
                "required": [
                  "validUntil",
                  "signature"
                ]
              },
              "example": {
                "validUntil": 1717002000,
                "signature": "0xabcdef0123…"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing or newly-created account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accountId": {
                      "type": "string"
                    },
                    "address": {
                      "type": "string",
                      "description": "EIP-55 checksummed address."
                    },
                    "isAdmin": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "accountId",
                    "address"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`validUntil` or `signature` missing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Signature expired or verification failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Account-creation transaction failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/cli": {
      "post": {
        "tags": [
          "auth"
        ],
        "summary": "Issue a 30-day session token for the CLI login flow",
        "description": "Called by the browser page after the user signs the EIP-712 access message. Verifies the wallet signature (custom `x-valve-until` + `x-valve-signature` header pair, not OAuth — see headers below), creates a 30-day `session_token` row, and returns a callback URL that redirects the TUI's local HTTP server. The returned `token` has the prefix `vt_` and SHOULD be stored only in the TUI's keychain — it grants full session-token access for 30 days.",
        "operationId": "authCliExchange",
        "parameters": [
          {
            "name": "x-valve-until",
            "in": "header",
            "required": true,
            "description": "Unix-seconds expiry of the EIP-712 access signature.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-valve-signature",
            "in": "header",
            "required": true,
            "description": "EIP-712 signature over the access domain.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "callbackPort": {
                    "description": "Local port the TUI is listening on for the callback. Integer 1-65535, accepted as number or numeric string."
                  },
                  "nonce": {
                    "type": "string",
                    "description": "Opaque nonce echoed back in `callbackUrl`; CSRF-style binding."
                  }
                },
                "required": [
                  "callbackPort",
                  "nonce"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Session token issued; redirect to `callbackUrl`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string",
                      "description": "Bearer token of the form `vt_…`"
                    },
                    "accountId": {
                      "type": "string"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time",
                      "description": "ISO-8601, 30 days from issue."
                    },
                    "callbackUrl": {
                      "type": "string",
                      "format": "uri",
                      "description": "Redirect URL with token + accountId + nonce in the query string."
                    },
                    "nonce": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "token",
                    "accountId",
                    "expiresAt",
                    "callbackUrl",
                    "nonce"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid `callbackPort` / `nonce`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "EIP-712 signature missing, expired, or invalid.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Token persistence failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/accounts": {
      "get": {
        "tags": [
          "accounts"
        ],
        "summary": "List accounts (caller's by default; admin can list all)",
        "description": "Without `?all=true`: returns a single-element array containing the caller's account. With `?all=true`: returns every non-soft-deleted account (admin only — non-admin callers get 403). Soft-deleted accounts (those with `unlinkedAt` set) are filtered out in both modes.",
        "operationId": "listAccounts",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "all",
            "in": "query",
            "description": "Set to `true` to list every account (admin only).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "Array of account rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "accountId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "name": {
                        "type": "string"
                      },
                      "email": {
                        "type": "string",
                        "format": "email",
                        "description": "A placeholder of the form `<address>@wallet` until you set an email with PATCH. Sign-in uses the wallet, never the email."
                      },
                      "address": {
                        "type": "string",
                        "nullable": true,
                        "description": "EIP-55 checksummed wallet address."
                      },
                      "isAdmin": {
                        "type": "boolean"
                      },
                      "verifiedAt": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                      },
                      "lastLoginAt": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                      },
                      "unlinkedAt": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true,
                        "description": "Soft-delete marker. Accounts with this set are filtered from list/get endpoints."
                      },
                      "projectLimit": {
                        "type": "integer",
                        "description": "Maximum number of non-archived projects this account may own. This is the effective limit: the larger of the value an admin set and the tier that lifetime paid deposits unlock (3 projects free, 10 at 10 USD paid, 25 at 100 USD paid). Grants and trials do not count as paid. Read-only: this is the effective value, so a client must not write it back; send `projectLimit` to PATCH only as an admin, from `projectLimitStored`."
                      },
                      "projectLimitStored": {
                        "type": "integer",
                        "description": "The value stored on the account (what an admin set). `projectLimit` is the effective value."
                      },
                      "projectCount": {
                        "type": "integer",
                        "description": "Number of non-archived projects this account owns now."
                      },
                      "nextProjectTier": {
                        "type": "object",
                        "nullable": true,
                        "description": "The next project tier, or null when the account is at the top tier. Credits are strings of whole credits (1 USD = 1e9 credits). Pay `paidCreditsToGo` more in tokens to unlock it.",
                        "properties": {
                          "limit": {
                            "type": "integer",
                            "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                          },
                          "minPaidCredits": {
                            "type": "string",
                            "description": "Lifetime paid credits that unlock this tier."
                          },
                          "paidCreditsToGo": {
                            "type": "string",
                            "description": "Paid credits the account still needs to reach this tier."
                          }
                        },
                        "required": [
                          "limit",
                          "minPaidCredits",
                          "paidCreditsToGo"
                        ]
                      },
                      "dataRetentionDays": {
                        "type": "integer",
                        "description": "The number of days Valve keeps the request log for this account. 0 means request logging is off, and 0 is the value for a new account. Request logging is off unless you turn it on. When it is off, Valve keeps only hourly request counts and credits for each key, for billing. Valve never records the client user agent."
                      },
                      "createdAt": {
                        "type": "string",
                        "format": "date-time"
                      }
                    },
                    "required": [
                      "accountId",
                      "name",
                      "email",
                      "isAdmin",
                      "projectLimit",
                      "projectCount",
                      "nextProjectTier",
                      "dataRetentionDays",
                      "createdAt"
                    ]
                  }
                }
              }
            }
          },
          "403": {
            "description": "Caller is not an admin and asked for `?all=true`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Caller account not found (soft-deleted or missing).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/accounts/me": {
      "get": {
        "tags": [
          "accounts"
        ],
        "summary": "Fetch the caller's own account",
        "description": "Returns the signed-in account with its effective `projectLimit`, its `projectCount`, and `nextProjectTier`: the next project tier in credits, or null at the top tier.",
        "operationId": "getMyAccount",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "The caller's account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accountId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "email": {
                      "type": "string",
                      "format": "email",
                      "description": "A placeholder of the form `<address>@wallet` until you set an email with PATCH. Sign-in uses the wallet, never the email."
                    },
                    "address": {
                      "type": "string",
                      "nullable": true,
                      "description": "EIP-55 checksummed wallet address."
                    },
                    "isAdmin": {
                      "type": "boolean"
                    },
                    "verifiedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "lastLoginAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "Soft-delete marker. Accounts with this set are filtered from list/get endpoints."
                    },
                    "projectLimit": {
                      "type": "integer",
                      "description": "Maximum number of non-archived projects this account may own. This is the effective limit: the larger of the value an admin set and the tier that lifetime paid deposits unlock (3 projects free, 10 at 10 USD paid, 25 at 100 USD paid). Grants and trials do not count as paid. Read-only: this is the effective value, so a client must not write it back; send `projectLimit` to PATCH only as an admin, from `projectLimitStored`."
                    },
                    "projectLimitStored": {
                      "type": "integer",
                      "description": "The value stored on the account (what an admin set). `projectLimit` is the effective value."
                    },
                    "projectCount": {
                      "type": "integer",
                      "description": "Number of non-archived projects this account owns now."
                    },
                    "nextProjectTier": {
                      "type": "object",
                      "nullable": true,
                      "description": "The next project tier, or null when the account is at the top tier. Credits are strings of whole credits (1 USD = 1e9 credits). Pay `paidCreditsToGo` more in tokens to unlock it.",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                        },
                        "minPaidCredits": {
                          "type": "string",
                          "description": "Lifetime paid credits that unlock this tier."
                        },
                        "paidCreditsToGo": {
                          "type": "string",
                          "description": "Paid credits the account still needs to reach this tier."
                        }
                      },
                      "required": [
                        "limit",
                        "minPaidCredits",
                        "paidCreditsToGo"
                      ]
                    },
                    "dataRetentionDays": {
                      "type": "integer",
                      "description": "The number of days Valve keeps the request log for this account. 0 means request logging is off, and 0 is the value for a new account. Request logging is off unless you turn it on. When it is off, Valve keeps only hourly request counts and credits for each key, for billing. Valve never records the client user agent."
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "accountId",
                    "name",
                    "email",
                    "isAdmin",
                    "projectLimit",
                    "projectCount",
                    "nextProjectTier",
                    "dataRetentionDays",
                    "createdAt"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Account not found or soft-deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/accounts/:accountId": {
      "get": {
        "tags": [
          "accounts"
        ],
        "summary": "Fetch a single account",
        "description": "Returns the account row. Non-admin callers can only fetch their own `accountId`; admins can fetch any. Soft-deleted accounts return 404 even when fetched by admins.",
        "operationId": "getAccount",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "description": "Account UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The account row.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accountId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "email": {
                      "type": "string",
                      "format": "email",
                      "description": "A placeholder of the form `<address>@wallet` until you set an email with PATCH. Sign-in uses the wallet, never the email."
                    },
                    "address": {
                      "type": "string",
                      "nullable": true,
                      "description": "EIP-55 checksummed wallet address."
                    },
                    "isAdmin": {
                      "type": "boolean"
                    },
                    "verifiedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "lastLoginAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "Soft-delete marker. Accounts with this set are filtered from list/get endpoints."
                    },
                    "projectLimit": {
                      "type": "integer",
                      "description": "Maximum number of non-archived projects this account may own. This is the effective limit: the larger of the value an admin set and the tier that lifetime paid deposits unlock (3 projects free, 10 at 10 USD paid, 25 at 100 USD paid). Grants and trials do not count as paid. Read-only: this is the effective value, so a client must not write it back; send `projectLimit` to PATCH only as an admin, from `projectLimitStored`."
                    },
                    "projectLimitStored": {
                      "type": "integer",
                      "description": "The value stored on the account (what an admin set). `projectLimit` is the effective value."
                    },
                    "projectCount": {
                      "type": "integer",
                      "description": "Number of non-archived projects this account owns now."
                    },
                    "nextProjectTier": {
                      "type": "object",
                      "nullable": true,
                      "description": "The next project tier, or null when the account is at the top tier. Credits are strings of whole credits (1 USD = 1e9 credits). Pay `paidCreditsToGo` more in tokens to unlock it.",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                        },
                        "minPaidCredits": {
                          "type": "string",
                          "description": "Lifetime paid credits that unlock this tier."
                        },
                        "paidCreditsToGo": {
                          "type": "string",
                          "description": "Paid credits the account still needs to reach this tier."
                        }
                      },
                      "required": [
                        "limit",
                        "minPaidCredits",
                        "paidCreditsToGo"
                      ]
                    },
                    "dataRetentionDays": {
                      "type": "integer",
                      "description": "The number of days Valve keeps the request log for this account. 0 means request logging is off, and 0 is the value for a new account. Request logging is off unless you turn it on. When it is off, Valve keeps only hourly request counts and credits for each key, for billing. Valve never records the client user agent."
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "accountId",
                    "name",
                    "email",
                    "isAdmin",
                    "projectLimit",
                    "projectCount",
                    "nextProjectTier",
                    "dataRetentionDays",
                    "createdAt"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access this account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Account not found or soft-deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "accounts"
        ],
        "summary": "Update an account",
        "description": "Patch a subset of mutable fields. Non-admins may update `name`, `email`, and `dataRetentionDays` on their own account only. Admins additionally may update `isAdmin` and `projectLimit` on any account. Empty body (no recognized fields) returns 400 — explicit, not a no-op.",
        "operationId": "updateAccount",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "description": "Account UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "projectLimit": {
                    "type": "integer",
                    "description": "Admin-only. Maximum non-archived projects per account."
                  },
                  "dataRetentionDays": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Request logging is off unless you turn it on. When it is off, Valve keeps only hourly request counts and credits for each key, for billing. A new account starts with 0 (off). To turn it on, set the number of days Valve keeps the request log: Valve deletes older rows. Must be a non-negative integer; a negative value is rejected because it would place the purge cutoff in the future and delete the account's entire history. 0 means \"do not record\" — new requests stop being written to the request log immediately, they are not recorded and purged later. Three limits apply: (1) rolling the api back to a version older than this feature turns recording back on, because an api that does not publish this setting is treated as \"record\"; (2) an already-open WebSocket keeps the config it had at connect time, so opting out does not take effect on that connection until it reconnects; (3) x402 payment records (relay.per_request_payment) are kept regardless, because they are the financial record needed to reconcile a disputed payment."
                  },
                  "isAdmin": {
                    "type": "boolean",
                    "description": "Admin-only. Grants global admin to the account."
                  }
                }
              },
              "example": {
                "name": "Acme",
                "dataRetentionDays": 30
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated account row. When the request changed dataRetentionDays, the response also carries a retentionSync object reporting how that change propagated to the account's keys — check retentionSync.failed and retry the PATCH if it is nonzero, since a failed key was not republished and still runs the old retention setting.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accountId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "email": {
                      "type": "string",
                      "format": "email",
                      "description": "A placeholder of the form `<address>@wallet` until you set an email with PATCH. Sign-in uses the wallet, never the email."
                    },
                    "address": {
                      "type": "string",
                      "nullable": true,
                      "description": "EIP-55 checksummed wallet address."
                    },
                    "isAdmin": {
                      "type": "boolean"
                    },
                    "verifiedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "lastLoginAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "Soft-delete marker. Accounts with this set are filtered from list/get endpoints."
                    },
                    "projectLimit": {
                      "type": "integer",
                      "description": "Maximum number of non-archived projects this account may own. This is the effective limit: the larger of the value an admin set and the tier that lifetime paid deposits unlock (3 projects free, 10 at 10 USD paid, 25 at 100 USD paid). Grants and trials do not count as paid. Read-only: this is the effective value, so a client must not write it back; send `projectLimit` to PATCH only as an admin, from `projectLimitStored`."
                    },
                    "projectLimitStored": {
                      "type": "integer",
                      "description": "The value stored on the account (what an admin set). `projectLimit` is the effective value."
                    },
                    "projectCount": {
                      "type": "integer",
                      "description": "Number of non-archived projects this account owns now."
                    },
                    "nextProjectTier": {
                      "type": "object",
                      "nullable": true,
                      "description": "The next project tier, or null when the account is at the top tier. Credits are strings of whole credits (1 USD = 1e9 credits). Pay `paidCreditsToGo` more in tokens to unlock it.",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                        },
                        "minPaidCredits": {
                          "type": "string",
                          "description": "Lifetime paid credits that unlock this tier."
                        },
                        "paidCreditsToGo": {
                          "type": "string",
                          "description": "Paid credits the account still needs to reach this tier."
                        }
                      },
                      "required": [
                        "limit",
                        "minPaidCredits",
                        "paidCreditsToGo"
                      ]
                    },
                    "dataRetentionDays": {
                      "type": "integer",
                      "description": "The number of days Valve keeps the request log for this account. 0 means request logging is off, and 0 is the value for a new account. Request logging is off unless you turn it on. When it is off, Valve keeps only hourly request counts and credits for each key, for billing. Valve never records the client user agent."
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "retentionSync": {
                      "type": "object",
                      "description": "Present only when this PATCH changed dataRetentionDays. Reports how many of the account's keys had their published Redis config resynced to the new value.",
                      "properties": {
                        "resynced": {
                          "type": "integer",
                          "description": "Keys successfully republished with the new retention setting."
                        },
                        "failed": {
                          "type": "integer",
                          "description": "Keys that failed to republish and still run the old retention setting."
                        }
                      },
                      "required": [
                        "resynced",
                        "failed"
                      ]
                    }
                  },
                  "required": [
                    "accountId",
                    "name",
                    "email",
                    "isAdmin",
                    "projectLimit",
                    "projectCount",
                    "nextProjectTier",
                    "dataRetentionDays",
                    "createdAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "No recognized fields in the body.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access this account, or attempted an admin-only field without admin.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Account not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects": {
      "get": {
        "tags": [
          "projects"
        ],
        "summary": "List projects",
        "description": "Default: returns the caller's projects. `?accountId=<uuid>`: returns that account's projects (admin OR same account). `?all=true`: returns every project across every account (admin only).",
        "operationId": "listProjects",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "description": "Target account to list projects for. Defaults to the caller's account.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "Set to `true` for global listing (admin only).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Array of project rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "projectId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "accountId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "name": {
                        "type": "string"
                      },
                      "keyLimit": {
                        "type": "integer",
                        "description": "Maximum number of active `vk_` keys in the project. This is the effective limit: the larger of the stored value and the tier the owning account's lifetime paid deposits unlock (3 keys free, 10 at 10 USD paid, 25 at 100 USD paid). The limit applies only when you create a key: keys above it keep working."
                      },
                      "keyCount": {
                        "type": "integer",
                        "description": "Number of active `vk_` keys in the project now."
                      },
                      "nextKeyTier": {
                        "type": "object",
                        "nullable": true,
                        "description": "The next key tier, or null at the top. `limit` is the key limit that tier gives. Credits are strings (1 USD = 1e9 credits).",
                        "properties": {
                          "limit": {
                            "type": "integer",
                            "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                          },
                          "minPaidCredits": {
                            "type": "string",
                            "description": "Lifetime paid credits that unlock this tier."
                          },
                          "paidCreditsToGo": {
                            "type": "string",
                            "description": "Paid credits the account still needs to reach this tier."
                          }
                        },
                        "required": [
                          "limit",
                          "minPaidCredits",
                          "paidCreditsToGo"
                        ]
                      },
                      "dailyRequestLimit": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 1000000000,
                        "description": "Requests per UTC day across every `vk_` key in the project combined. `0` means no limit, the default. Every request a key in the project authorizes counts, WebSocket subscription notifications included. A key can also have its own per-day limit; the relay applies both, so the stricter one binds. Past the limit, HTTP answers 429 (JSON-RPC `-32005`, `Rate limit exceeded (per day)`) with `Retry-After` counting down to the next UTC midnight, and a WebSocket closes with code `4029` and reason `Daily request limit reached`."
                      },
                      "unlinkedAt": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true,
                        "description": "Soft-delete marker. Set by `DELETE /v1/projects/:id` along with cascade-unlink of the project's `vk_` keys."
                      },
                      "createdAt": {
                        "type": "string",
                        "format": "date-time"
                      }
                    },
                    "required": [
                      "projectId",
                      "accountId",
                      "name",
                      "createdAt"
                    ]
                  }
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access the requested account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "projects"
        ],
        "summary": "Create a project",
        "description": "Creates a project for the caller's account, or for `body.accountId` if the caller is admin/self. Returns 409 if the target account has reached its effective `projectLimit`: the larger of the value an admin set and the tier that lifetime paid deposits unlock. The 409 body carries `code: \"project_limit_reached\"`, `projectLimit`, and `nextProjectTier` (null at the top tier), so a client can show how much to pay.",
        "operationId": "createProject",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "1-100 characters, trimmed."
                  },
                  "accountId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Optional. Defaults to the caller's account; non-self requires admin."
                  }
                },
                "required": [
                  "name"
                ]
              },
              "example": {
                "name": "My API"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created project.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projectId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "accountId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "keyLimit": {
                      "type": "integer",
                      "description": "Maximum number of active `vk_` keys in the project. This is the effective limit: the larger of the stored value and the tier the owning account's lifetime paid deposits unlock (3 keys free, 10 at 10 USD paid, 25 at 100 USD paid). The limit applies only when you create a key: keys above it keep working."
                    },
                    "keyCount": {
                      "type": "integer",
                      "description": "Number of active `vk_` keys in the project now."
                    },
                    "nextKeyTier": {
                      "type": "object",
                      "nullable": true,
                      "description": "The next key tier, or null at the top. `limit` is the key limit that tier gives. Credits are strings (1 USD = 1e9 credits).",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                        },
                        "minPaidCredits": {
                          "type": "string",
                          "description": "Lifetime paid credits that unlock this tier."
                        },
                        "paidCreditsToGo": {
                          "type": "string",
                          "description": "Paid credits the account still needs to reach this tier."
                        }
                      },
                      "required": [
                        "limit",
                        "minPaidCredits",
                        "paidCreditsToGo"
                      ]
                    },
                    "dailyRequestLimit": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 1000000000,
                      "description": "Requests per UTC day across every `vk_` key in the project combined. `0` means no limit, the default. Every request a key in the project authorizes counts, WebSocket subscription notifications included. A key can also have its own per-day limit; the relay applies both, so the stricter one binds. Past the limit, HTTP answers 429 (JSON-RPC `-32005`, `Rate limit exceeded (per day)`) with `Retry-After` counting down to the next UTC midnight, and a WebSocket closes with code `4029` and reason `Daily request limit reached`."
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "Soft-delete marker. Set by `DELETE /v1/projects/:id` along with cascade-unlink of the project's `vk_` keys."
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "projectId",
                    "accountId",
                    "name",
                    "createdAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`name` missing, empty, or over 100 chars.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to create projects for the target account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "Target account has reached its effective `projectLimit`. `code` is `project_limit_reached`. `nextProjectTier` gives the paid credits that unlock more projects, or null at the top tier.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "project_limit_reached"
                      ]
                    },
                    "projectLimit": {
                      "type": "integer"
                    },
                    "nextProjectTier": {
                      "type": "object",
                      "nullable": true,
                      "description": "The next project tier, or null when the account is at the top tier. Credits are strings of whole credits (1 USD = 1e9 credits). Pay `paidCreditsToGo` more in tokens to unlock it.",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                        },
                        "minPaidCredits": {
                          "type": "string",
                          "description": "Lifetime paid credits that unlock this tier."
                        },
                        "paidCreditsToGo": {
                          "type": "string",
                          "description": "Paid credits the account still needs to reach this tier."
                        }
                      },
                      "required": [
                        "limit",
                        "minPaidCredits",
                        "paidCreditsToGo"
                      ]
                    }
                  },
                  "required": [
                    "error",
                    "code",
                    "projectLimit",
                    "nextProjectTier"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/:projectId": {
      "patch": {
        "tags": [
          "projects"
        ],
        "summary": "Update a project (name, daily request limit, relay modifiers)",
        "description": "Patches `name`, `dailyRequestLimit` and/or `modifiers` (per-project relay-routing modifiers). At least one must be present. A sent `dailyRequestLimit` is republished to every active key of the project at once, and the response reports how many keys took it in `limitSync`. `modifiers` is deep-merged with the stored config — missing leaves in the patch preserve the existing ones, so toggling one knob never silently wipes a sibling. Returns the merged project row with the resolved `modifiers` config.",
        "operationId": "updateProject",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "1-100 characters, trimmed."
                  },
                  "dailyRequestLimit": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000000000,
                    "description": "Requests per UTC day across every key in the project. `0` removes the limit. A JSON number only: a string, a fraction, a negative or a value over 1,000,000,000 is refused with 400."
                  },
                  "modifiers": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Validated by `modifiersConfigSchema` (Zod) before persistence. Shape evolves; see `@valve/types`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated project with its merged modifiers config.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projectId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "accountId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "dailyRequestLimit": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Requests per UTC day across every key in the project. `0` = no limit."
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "modifiers": {
                      "type": "object",
                      "additionalProperties": true,
                      "nullable": true
                    },
                    "limitSync": {
                      "type": "object",
                      "description": "Present only when the request sent `dailyRequestLimit`. `failed` > 0 means some keys still serve the previous limit until their next edit; repeat the PATCH to retry.",
                      "properties": {
                        "resynced": {
                          "type": "integer"
                        },
                        "failed": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "resynced",
                        "failed"
                      ]
                    }
                  },
                  "required": [
                    "projectId",
                    "accountId",
                    "name",
                    "createdAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input — empty `name`, oversize `name`, a `dailyRequestLimit` that is not a whole number from 0 to 1,000,000,000, invalid `modifiers`, or no field present.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access the owning account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Project not found or soft-deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "projects"
        ],
        "summary": "Soft-delete a project (cascades to its `vk_` keys)",
        "description": "Sets `unlinkedAt` on the project row AND on every `vk_` key under it. For each key, removes the cached `valve:keyconfig:<vk>` from Redis and publishes a `valve:key:invalidate` message so the relay drops the key from its in-process LRU within the next pubsub tick. Idempotent — re-deleting an already-soft-deleted project returns 404.",
        "operationId": "deleteProject",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deletion acknowledged.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deleted": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "deleted"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access the owning account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Project not found or already soft-deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write or Redis publish failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys": {
      "post": {
        "tags": [
          "projects"
        ],
        "summary": "Issue a new `vk_` API key under a project",
        "description": "Creates a key, materializes its constraint rows (origins/methods/networks), auto-links the \"all\" system method-policy preset so the key is unrestricted by default, and syncs the resolved config to Redis so the relay sees it on the next request.",
        "operationId": "createKey",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "projectId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "name": {
                    "type": "string"
                  },
                  "allowedOrigins": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "methodList": {
                    "type": "array",
                    "nullable": true,
                    "items": {
                      "type": "string"
                    },
                    "description": "`null`: every method. `[]`: no method; on a chain override, no method on that chain. A list: only those methods, at most 1000 names after the dedupe. A chain list replaces the default on its chain; an absent chain value inherits the default. `[]` needs the empty list to be available; until then it answers 400."
                  },
                  "allowedMethods": {
                    "type": "array",
                    "nullable": true,
                    "deprecated": true,
                    "items": {
                      "type": "string"
                    },
                    "description": "Deprecated: send `methodList`. The old meaning, kept for older clients: `[]` or `null` allows every method, a list allows only those. It can never set 'no method'. A value equal to the scope's current `allowedMethods` (as a set) changes nothing, so it never removes a block. Do not send it with `methodList` for the same scope."
                  },
                  "enabledNetworks": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Networks the key may reach. Each entry is a registered EVM chain id (`8453`) or a CAIP-2 network key (`eip155:8453`); the API stores and returns CAIP-2. Empty = every network."
                  }
                },
                "required": [
                  "projectId",
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created key with resolved constraints.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projectKeyId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "projectId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string",
                      "description": "The `vk_…` token sent to the relay as `Authorization: Bearer`. Treat as a credential — surfaced here only for owner-readable list/get endpoints."
                    },
                    "limitScope": {
                      "type": "string",
                      "enum": [
                        "key",
                        "client"
                      ],
                      "description": "Which counter the limits use. `client` gives each client its own copy of this key's per-second, per-day and CU limits, and its own copy of the tier's requests-per-second ceiling. Only the account's credits-per-second limit and the project's daily request limit apply to all clients together. The billing class stays the key's. Has no effect on a key in `ip` rate-limit mode. Default `key`."
                    },
                    "trustedForwarders": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "maxItems": 8,
                      "description": "Exact addresses (IPv4 /32 or IPv6 /128, at most 8) of your own servers. A request from one of them may name its client in the `X-Valve-Client-IP` header. Used only with `limitScope: client`."
                    },
                    "paramRules": {
                      "type": "object",
                      "nullable": true,
                      "description": "Argument rules for the key: allow or deny a call by the values in its arguments (the `to` of an `eth_call`, the `address` and topics of an `eth_getLogs`, the decoded `to`, selector and `chainId` of an `eth_sendRawTransaction`), plus two key-wide limits. A rule judges every method of its family: `eth_call` judges `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `eth_callMany`, `debug_traceCallMany`, `trace_callMany`, `eth_callBundle`; `eth_getLogs` judges `eth_getLogs`, `eth_newFilter`, `eth_subscribe`; `eth_sendRawTransaction` judges `eth_sendRawTransaction`, `eth_sendRawTransactionConditional`, `eth_sendRawTransactionSync`, `eth_sendBundle`, `eth_sendPrivateTransaction`; `eth_getBalance` judges `eth_getBalance`, `eth_getProof`, `eth_getAccount`; `eth_getCode` judges `eth_getCode`; `eth_getStorageAt` judges `eth_getStorageAt`, `eth_getProof`. An absent `networks` means every network. A rule network must be an EVM (`eip155`) network. A rule applies to a call when the call is of its method (family) and on its networks. A matching `deny` rule refuses the call. If any `allow` rule applies for a method, the call must hold for at least one of them. With no applicable `allow` rule, the call passes. All conditions of a rule must hold. Method policies run first and a rule never widens them. `null` means no rules. While a rule applies, the relay refuses (`-32000`) a call it cannot read exactly: `params` that is not an array; a value not of the exact `0x` hex form (an empty `to` or a bare `0x` included); a method name that is not a string, or that spells a family method in another letter case or with look-alike characters; a tx object key that folds to `to`, `data`, `input` or `authorizationList` but is spelled otherwise; `input` and `data` that differ; a log filter with an unknown field; a raw transaction that does not decode or is over 1 MiB. Under an `eth_call` `allow` rule the relay also refuses: any state or block override, which is any non-null param from the first override slot on (`eth_call`, `eth_estimateGas` and `eth_createAccessList` from `params[2]`, `trace_call` from `params[3]`, which covers `params[3]` and `params[4]`, `debug_traceCall` from `params[3]` plus a `params[2]` tracing-option key that folds to `stateOverrides` or `blockOverrides`), so an empty `{}` override is refused too; a tx object key outside the call fields (`from`, `to`, `gas`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, `maxFeePerBlobGas`, `value`, `data`, `input`, `nonce`, `type`, `chainId`, `accessList`, `authorizationList`, `blobVersionedHashes`, `blobs`); a non-empty `authorizationList` (EIP-7702) on a tx object or a raw transaction; the override keys of the multi-call methods. A create (no `to`) fails every `to` allow and every `selector` allow, and trips no `to` or `selector` deny. While a rule applies, a multi-call request may carry at most 100 inner calls and 100 blocks or bundles; one inner call that fails refuses the whole request. A filter or a subscription made before a rule change stays live and keeps its old filter until it expires. Limits: at most 32 rules per key; 1 to 100 values per condition; at most 1000 values per key; 1 to 32 networks per rule; `maxLogBlockRange` 1 to 100000 or null; `maxStateBlockDepth` 0 to 100000000 or null. The API stores values lowercase, de-duplicated and sorted, and stores `chainId` as a decimal string. The API body limit of 100 KB binds before the 128 KiB column limit, so there is no separate document-size limit. `maxLogBlockRange` caps `eth_getLogs`, `eth_newFilter` and `eth_getFilterLogs`. With it set, `eth_getFilterLogs` is refused on a credit-exempt key and on any key the relay keeps no filter records for; use `eth_getLogs`. `maxStateBlockDepth` judges the block parameter of `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getAccount`, `eth_getStorageAt`, `eth_getProof`, `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `trace_callMany`, `eth_callMany`, `debug_traceCallMany`, `eth_callBundle`. The tags `latest`, `pending`, `safe` and `finalized` pass without a depth check, so `safe` and `finalized` are not bounded by the limit, even on a chain whose finality stalls. A block hash, or a numeric block while the head is unknown, is refused. `debug_traceBlockByNumber`, `debug_traceBlockByHash`, `trace_block`, `trace_replayBlockTransactions`, `debug_storageRangeAt`, `eth_getBlockByNumber`, `eth_getBlockByHash` read old state without it. To close them, deny those method names with a method policy.",
                      "required": [
                        "rules",
                        "maxLogBlockRange",
                        "maxStateBlockDepth"
                      ],
                      "properties": {
                        "rules": {
                          "type": "array",
                          "maxItems": 32,
                          "items": {
                            "type": "object",
                            "required": [
                              "effect",
                              "method",
                              "where"
                            ],
                            "properties": {
                              "effect": {
                                "type": "string",
                                "enum": [
                                  "allow",
                                  "deny"
                                ]
                              },
                              "method": {
                                "type": "string",
                                "enum": [
                                  "eth_call",
                                  "eth_getLogs",
                                  "eth_sendRawTransaction",
                                  "eth_getBalance",
                                  "eth_getCode",
                                  "eth_getStorageAt"
                                ]
                              },
                              "networks": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 32,
                                "items": {
                                  "type": "string"
                                },
                                "description": "Registered networks, as a chain id (`8453`) or a CAIP-2 key (`eip155:8453`). The API returns CAIP-2. Absent = every network."
                              },
                              "where": {
                                "type": "array",
                                "minItems": 1,
                                "description": "Conditions, each field at most once. A call matches the rule when every condition holds.",
                                "items": {
                                  "type": "object",
                                  "required": [
                                    "field",
                                    "in"
                                  ],
                                  "properties": {
                                    "field": {
                                      "type": "string",
                                      "enum": [
                                        "to",
                                        "selector",
                                        "address",
                                        "topic0",
                                        "topic1",
                                        "topic2",
                                        "topic3",
                                        "chainId"
                                      ]
                                    },
                                    "in": {
                                      "type": "array",
                                      "minItems": 1,
                                      "maxItems": 100,
                                      "items": {
                                        "type": "string"
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        },
                        "maxLogBlockRange": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 1,
                          "maximum": 100000,
                          "description": "Largest block span of an `eth_getLogs`, `eth_newFilter` or `eth_getFilterLogs`. The smaller of this and the tier cap applies. null = no key limit."
                        },
                        "maxStateBlockDepth": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 0,
                          "maximum": 100000000,
                          "description": "Largest distance from the chain head a state read may name. null = no limit."
                        }
                      }
                    },
                    "secretRequired": {
                      "type": "boolean",
                      "description": "When true, the relay additionally enforces the `secret` on each request."
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "constraints": {
                      "type": "object",
                      "description": "The key's effective constraint set. Top-level fields are the defaults; `chainOverrides` specifies per-chain replacements (a chain key with `null` values inherits the top-level defaults).",
                      "properties": {
                        "allowedOrigins": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Browser `Origin` allow-list. Empty array = unrestricted."
                        },
                        "methodList": {
                          "type": "array",
                          "nullable": true,
                          "items": {
                            "type": "string"
                          },
                          "description": "`null`: every method. `[]`: no method; on a chain override, no method on that chain. A list: only those methods. A chain list replaces the default on its chain; an absent chain value inherits the default. The linked method policies apply as well: a call must pass both."
                        },
                        "allowedMethods": {
                          "type": "array",
                          "deprecated": true,
                          "items": {
                            "type": "string"
                          },
                          "description": "Deprecated: read `methodList`. The old meaning, kept for older clients: always an array, and `[]` means every method. A key that allows no method also reads `[]` here."
                        },
                        "enabledNetworks": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Network allow-list as CAIP-2 keys (`eip155:8453`). Empty = every network."
                        },
                        "chainOverrides": {
                          "type": "object",
                          "additionalProperties": true,
                          "description": "Per-chain replacements, keyed by chain-ID string. Each value is `{ allowedOrigins, allowedMethods, methodList }`, with `methodList` and the deprecated `allowedMethods` as at the top level."
                        }
                      }
                    }
                  },
                  "required": [
                    "projectKeyId",
                    "projectId",
                    "name",
                    "value",
                    "secretRequired",
                    "createdAt",
                    "constraints"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Missing `projectId`/`name`, an unregistered network in `enabledNetworks`, `methodList` is `[]` before the empty list is available ('Allowing no method (methodList []) is not available yet...') or is not `null` or a list of method names, a list holds more than 1000 names, `allowedMethods` is not a list of method names, or the body sends both `methodList` and `allowedMethods`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized for the project.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "Project has reached its effective key limit. `code` is `key_limit_reached`. `nextKeyTier` gives the paid credits that unlock more keys, or null at the top tier.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "key_limit_reached"
                      ]
                    },
                    "keyLimit": {
                      "type": "integer"
                    },
                    "nextKeyTier": {
                      "type": "object",
                      "nullable": true,
                      "description": "The next project tier, or null when the account is at the top tier. Credits are strings of whole credits (1 USD = 1e9 credits). Pay `paidCreditsToGo` more in tokens to unlock it.",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "description": "The limit this tier gives: projects for `nextProjectTier`, keys for `nextKeyTier`."
                        },
                        "minPaidCredits": {
                          "type": "string",
                          "description": "Lifetime paid credits that unlock this tier."
                        },
                        "paidCreditsToGo": {
                          "type": "string",
                          "description": "Paid credits the account still needs to reach this tier."
                        }
                      },
                      "required": [
                        "limit",
                        "minPaidCredits",
                        "paidCreditsToGo"
                      ]
                    }
                  },
                  "required": [
                    "error",
                    "code",
                    "keyLimit",
                    "nextKeyTier"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write or Redis sync failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "projects"
        ],
        "summary": "List `vk_` keys",
        "description": "Defaults to the caller's account; `?accountId=` switches target (admin or self). `?projectId=` filters to a single project. Each entry includes the resolved constraint set so consumers don't need to follow up with separate queries.",
        "operationId": "listKeys",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Array of keys with resolved constraints.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "projectKeyId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "projectId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "name": {
                        "type": "string"
                      },
                      "value": {
                        "type": "string",
                        "description": "The `vk_…` token sent to the relay as `Authorization: Bearer`. Treat as a credential — surfaced here only for owner-readable list/get endpoints."
                      },
                      "limitScope": {
                        "type": "string",
                        "enum": [
                          "key",
                          "client"
                        ],
                        "description": "Which counter the limits use. `client` gives each client its own copy of this key's per-second, per-day and CU limits, and its own copy of the tier's requests-per-second ceiling. Only the account's credits-per-second limit and the project's daily request limit apply to all clients together. The billing class stays the key's. Has no effect on a key in `ip` rate-limit mode. Default `key`."
                      },
                      "trustedForwarders": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "maxItems": 8,
                        "description": "Exact addresses (IPv4 /32 or IPv6 /128, at most 8) of your own servers. A request from one of them may name its client in the `X-Valve-Client-IP` header. Used only with `limitScope: client`."
                      },
                      "paramRules": {
                        "type": "object",
                        "nullable": true,
                        "description": "Argument rules for the key: allow or deny a call by the values in its arguments (the `to` of an `eth_call`, the `address` and topics of an `eth_getLogs`, the decoded `to`, selector and `chainId` of an `eth_sendRawTransaction`), plus two key-wide limits. A rule judges every method of its family: `eth_call` judges `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `eth_callMany`, `debug_traceCallMany`, `trace_callMany`, `eth_callBundle`; `eth_getLogs` judges `eth_getLogs`, `eth_newFilter`, `eth_subscribe`; `eth_sendRawTransaction` judges `eth_sendRawTransaction`, `eth_sendRawTransactionConditional`, `eth_sendRawTransactionSync`, `eth_sendBundle`, `eth_sendPrivateTransaction`; `eth_getBalance` judges `eth_getBalance`, `eth_getProof`, `eth_getAccount`; `eth_getCode` judges `eth_getCode`; `eth_getStorageAt` judges `eth_getStorageAt`, `eth_getProof`. An absent `networks` means every network. A rule network must be an EVM (`eip155`) network. A rule applies to a call when the call is of its method (family) and on its networks. A matching `deny` rule refuses the call. If any `allow` rule applies for a method, the call must hold for at least one of them. With no applicable `allow` rule, the call passes. All conditions of a rule must hold. Method policies run first and a rule never widens them. `null` means no rules. While a rule applies, the relay refuses (`-32000`) a call it cannot read exactly: `params` that is not an array; a value not of the exact `0x` hex form (an empty `to` or a bare `0x` included); a method name that is not a string, or that spells a family method in another letter case or with look-alike characters; a tx object key that folds to `to`, `data`, `input` or `authorizationList` but is spelled otherwise; `input` and `data` that differ; a log filter with an unknown field; a raw transaction that does not decode or is over 1 MiB. Under an `eth_call` `allow` rule the relay also refuses: any state or block override, which is any non-null param from the first override slot on (`eth_call`, `eth_estimateGas` and `eth_createAccessList` from `params[2]`, `trace_call` from `params[3]`, which covers `params[3]` and `params[4]`, `debug_traceCall` from `params[3]` plus a `params[2]` tracing-option key that folds to `stateOverrides` or `blockOverrides`), so an empty `{}` override is refused too; a tx object key outside the call fields (`from`, `to`, `gas`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, `maxFeePerBlobGas`, `value`, `data`, `input`, `nonce`, `type`, `chainId`, `accessList`, `authorizationList`, `blobVersionedHashes`, `blobs`); a non-empty `authorizationList` (EIP-7702) on a tx object or a raw transaction; the override keys of the multi-call methods. A create (no `to`) fails every `to` allow and every `selector` allow, and trips no `to` or `selector` deny. While a rule applies, a multi-call request may carry at most 100 inner calls and 100 blocks or bundles; one inner call that fails refuses the whole request. A filter or a subscription made before a rule change stays live and keeps its old filter until it expires. Limits: at most 32 rules per key; 1 to 100 values per condition; at most 1000 values per key; 1 to 32 networks per rule; `maxLogBlockRange` 1 to 100000 or null; `maxStateBlockDepth` 0 to 100000000 or null. The API stores values lowercase, de-duplicated and sorted, and stores `chainId` as a decimal string. The API body limit of 100 KB binds before the 128 KiB column limit, so there is no separate document-size limit. `maxLogBlockRange` caps `eth_getLogs`, `eth_newFilter` and `eth_getFilterLogs`. With it set, `eth_getFilterLogs` is refused on a credit-exempt key and on any key the relay keeps no filter records for; use `eth_getLogs`. `maxStateBlockDepth` judges the block parameter of `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getAccount`, `eth_getStorageAt`, `eth_getProof`, `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `trace_callMany`, `eth_callMany`, `debug_traceCallMany`, `eth_callBundle`. The tags `latest`, `pending`, `safe` and `finalized` pass without a depth check, so `safe` and `finalized` are not bounded by the limit, even on a chain whose finality stalls. A block hash, or a numeric block while the head is unknown, is refused. `debug_traceBlockByNumber`, `debug_traceBlockByHash`, `trace_block`, `trace_replayBlockTransactions`, `debug_storageRangeAt`, `eth_getBlockByNumber`, `eth_getBlockByHash` read old state without it. To close them, deny those method names with a method policy.",
                        "required": [
                          "rules",
                          "maxLogBlockRange",
                          "maxStateBlockDepth"
                        ],
                        "properties": {
                          "rules": {
                            "type": "array",
                            "maxItems": 32,
                            "items": {
                              "type": "object",
                              "required": [
                                "effect",
                                "method",
                                "where"
                              ],
                              "properties": {
                                "effect": {
                                  "type": "string",
                                  "enum": [
                                    "allow",
                                    "deny"
                                  ]
                                },
                                "method": {
                                  "type": "string",
                                  "enum": [
                                    "eth_call",
                                    "eth_getLogs",
                                    "eth_sendRawTransaction",
                                    "eth_getBalance",
                                    "eth_getCode",
                                    "eth_getStorageAt"
                                  ]
                                },
                                "networks": {
                                  "type": "array",
                                  "minItems": 1,
                                  "maxItems": 32,
                                  "items": {
                                    "type": "string"
                                  },
                                  "description": "Registered networks, as a chain id (`8453`) or a CAIP-2 key (`eip155:8453`). The API returns CAIP-2. Absent = every network."
                                },
                                "where": {
                                  "type": "array",
                                  "minItems": 1,
                                  "description": "Conditions, each field at most once. A call matches the rule when every condition holds.",
                                  "items": {
                                    "type": "object",
                                    "required": [
                                      "field",
                                      "in"
                                    ],
                                    "properties": {
                                      "field": {
                                        "type": "string",
                                        "enum": [
                                          "to",
                                          "selector",
                                          "address",
                                          "topic0",
                                          "topic1",
                                          "topic2",
                                          "topic3",
                                          "chainId"
                                        ]
                                      },
                                      "in": {
                                        "type": "array",
                                        "minItems": 1,
                                        "maxItems": 100,
                                        "items": {
                                          "type": "string"
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          },
                          "maxLogBlockRange": {
                            "type": "integer",
                            "nullable": true,
                            "minimum": 1,
                            "maximum": 100000,
                            "description": "Largest block span of an `eth_getLogs`, `eth_newFilter` or `eth_getFilterLogs`. The smaller of this and the tier cap applies. null = no key limit."
                          },
                          "maxStateBlockDepth": {
                            "type": "integer",
                            "nullable": true,
                            "minimum": 0,
                            "maximum": 100000000,
                            "description": "Largest distance from the chain head a state read may name. null = no limit."
                          }
                        }
                      },
                      "secretRequired": {
                        "type": "boolean",
                        "description": "When true, the relay additionally enforces the `secret` on each request."
                      },
                      "unlinkedAt": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                      },
                      "createdAt": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "constraints": {
                        "type": "object",
                        "description": "The key's effective constraint set. Top-level fields are the defaults; `chainOverrides` specifies per-chain replacements (a chain key with `null` values inherits the top-level defaults).",
                        "properties": {
                          "allowedOrigins": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Browser `Origin` allow-list. Empty array = unrestricted."
                          },
                          "methodList": {
                            "type": "array",
                            "nullable": true,
                            "items": {
                              "type": "string"
                            },
                            "description": "`null`: every method. `[]`: no method; on a chain override, no method on that chain. A list: only those methods. A chain list replaces the default on its chain; an absent chain value inherits the default. The linked method policies apply as well: a call must pass both."
                          },
                          "allowedMethods": {
                            "type": "array",
                            "deprecated": true,
                            "items": {
                              "type": "string"
                            },
                            "description": "Deprecated: read `methodList`. The old meaning, kept for older clients: always an array, and `[]` means every method. A key that allows no method also reads `[]` here."
                          },
                          "enabledNetworks": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Network allow-list as CAIP-2 keys (`eip155:8453`). Empty = every network."
                          },
                          "chainOverrides": {
                            "type": "object",
                            "additionalProperties": true,
                            "description": "Per-chain replacements, keyed by chain-ID string. Each value is `{ allowedOrigins, allowedMethods, methodList }`, with `methodList` and the deprecated `allowedMethods` as at the top level."
                          }
                        }
                      }
                    },
                    "required": [
                      "projectKeyId",
                      "projectId",
                      "name",
                      "value",
                      "secretRequired",
                      "createdAt",
                      "constraints"
                    ]
                  }
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access the requested account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/:keyId": {
      "get": {
        "tags": [
          "projects"
        ],
        "summary": "Fetch one key + usage summary",
        "description": "Returns the key, its resolved constraint set, and a 24h/7d usage rollup.",
        "operationId": "getKey",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Key with constraints + usage.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projectKeyId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "projectId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string",
                      "description": "The `vk_…` token sent to the relay as `Authorization: Bearer`. Treat as a credential — surfaced here only for owner-readable list/get endpoints."
                    },
                    "limitScope": {
                      "type": "string",
                      "enum": [
                        "key",
                        "client"
                      ],
                      "description": "Which counter the limits use. `client` gives each client its own copy of this key's per-second, per-day and CU limits, and its own copy of the tier's requests-per-second ceiling. Only the account's credits-per-second limit and the project's daily request limit apply to all clients together. The billing class stays the key's. Has no effect on a key in `ip` rate-limit mode. Default `key`."
                    },
                    "trustedForwarders": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "maxItems": 8,
                      "description": "Exact addresses (IPv4 /32 or IPv6 /128, at most 8) of your own servers. A request from one of them may name its client in the `X-Valve-Client-IP` header. Used only with `limitScope: client`."
                    },
                    "paramRules": {
                      "type": "object",
                      "nullable": true,
                      "description": "Argument rules for the key: allow or deny a call by the values in its arguments (the `to` of an `eth_call`, the `address` and topics of an `eth_getLogs`, the decoded `to`, selector and `chainId` of an `eth_sendRawTransaction`), plus two key-wide limits. A rule judges every method of its family: `eth_call` judges `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `eth_callMany`, `debug_traceCallMany`, `trace_callMany`, `eth_callBundle`; `eth_getLogs` judges `eth_getLogs`, `eth_newFilter`, `eth_subscribe`; `eth_sendRawTransaction` judges `eth_sendRawTransaction`, `eth_sendRawTransactionConditional`, `eth_sendRawTransactionSync`, `eth_sendBundle`, `eth_sendPrivateTransaction`; `eth_getBalance` judges `eth_getBalance`, `eth_getProof`, `eth_getAccount`; `eth_getCode` judges `eth_getCode`; `eth_getStorageAt` judges `eth_getStorageAt`, `eth_getProof`. An absent `networks` means every network. A rule network must be an EVM (`eip155`) network. A rule applies to a call when the call is of its method (family) and on its networks. A matching `deny` rule refuses the call. If any `allow` rule applies for a method, the call must hold for at least one of them. With no applicable `allow` rule, the call passes. All conditions of a rule must hold. Method policies run first and a rule never widens them. `null` means no rules. While a rule applies, the relay refuses (`-32000`) a call it cannot read exactly: `params` that is not an array; a value not of the exact `0x` hex form (an empty `to` or a bare `0x` included); a method name that is not a string, or that spells a family method in another letter case or with look-alike characters; a tx object key that folds to `to`, `data`, `input` or `authorizationList` but is spelled otherwise; `input` and `data` that differ; a log filter with an unknown field; a raw transaction that does not decode or is over 1 MiB. Under an `eth_call` `allow` rule the relay also refuses: any state or block override, which is any non-null param from the first override slot on (`eth_call`, `eth_estimateGas` and `eth_createAccessList` from `params[2]`, `trace_call` from `params[3]`, which covers `params[3]` and `params[4]`, `debug_traceCall` from `params[3]` plus a `params[2]` tracing-option key that folds to `stateOverrides` or `blockOverrides`), so an empty `{}` override is refused too; a tx object key outside the call fields (`from`, `to`, `gas`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, `maxFeePerBlobGas`, `value`, `data`, `input`, `nonce`, `type`, `chainId`, `accessList`, `authorizationList`, `blobVersionedHashes`, `blobs`); a non-empty `authorizationList` (EIP-7702) on a tx object or a raw transaction; the override keys of the multi-call methods. A create (no `to`) fails every `to` allow and every `selector` allow, and trips no `to` or `selector` deny. While a rule applies, a multi-call request may carry at most 100 inner calls and 100 blocks or bundles; one inner call that fails refuses the whole request. A filter or a subscription made before a rule change stays live and keeps its old filter until it expires. Limits: at most 32 rules per key; 1 to 100 values per condition; at most 1000 values per key; 1 to 32 networks per rule; `maxLogBlockRange` 1 to 100000 or null; `maxStateBlockDepth` 0 to 100000000 or null. The API stores values lowercase, de-duplicated and sorted, and stores `chainId` as a decimal string. The API body limit of 100 KB binds before the 128 KiB column limit, so there is no separate document-size limit. `maxLogBlockRange` caps `eth_getLogs`, `eth_newFilter` and `eth_getFilterLogs`. With it set, `eth_getFilterLogs` is refused on a credit-exempt key and on any key the relay keeps no filter records for; use `eth_getLogs`. `maxStateBlockDepth` judges the block parameter of `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getAccount`, `eth_getStorageAt`, `eth_getProof`, `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `trace_callMany`, `eth_callMany`, `debug_traceCallMany`, `eth_callBundle`. The tags `latest`, `pending`, `safe` and `finalized` pass without a depth check, so `safe` and `finalized` are not bounded by the limit, even on a chain whose finality stalls. A block hash, or a numeric block while the head is unknown, is refused. `debug_traceBlockByNumber`, `debug_traceBlockByHash`, `trace_block`, `trace_replayBlockTransactions`, `debug_storageRangeAt`, `eth_getBlockByNumber`, `eth_getBlockByHash` read old state without it. To close them, deny those method names with a method policy.",
                      "required": [
                        "rules",
                        "maxLogBlockRange",
                        "maxStateBlockDepth"
                      ],
                      "properties": {
                        "rules": {
                          "type": "array",
                          "maxItems": 32,
                          "items": {
                            "type": "object",
                            "required": [
                              "effect",
                              "method",
                              "where"
                            ],
                            "properties": {
                              "effect": {
                                "type": "string",
                                "enum": [
                                  "allow",
                                  "deny"
                                ]
                              },
                              "method": {
                                "type": "string",
                                "enum": [
                                  "eth_call",
                                  "eth_getLogs",
                                  "eth_sendRawTransaction",
                                  "eth_getBalance",
                                  "eth_getCode",
                                  "eth_getStorageAt"
                                ]
                              },
                              "networks": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 32,
                                "items": {
                                  "type": "string"
                                },
                                "description": "Registered networks, as a chain id (`8453`) or a CAIP-2 key (`eip155:8453`). The API returns CAIP-2. Absent = every network."
                              },
                              "where": {
                                "type": "array",
                                "minItems": 1,
                                "description": "Conditions, each field at most once. A call matches the rule when every condition holds.",
                                "items": {
                                  "type": "object",
                                  "required": [
                                    "field",
                                    "in"
                                  ],
                                  "properties": {
                                    "field": {
                                      "type": "string",
                                      "enum": [
                                        "to",
                                        "selector",
                                        "address",
                                        "topic0",
                                        "topic1",
                                        "topic2",
                                        "topic3",
                                        "chainId"
                                      ]
                                    },
                                    "in": {
                                      "type": "array",
                                      "minItems": 1,
                                      "maxItems": 100,
                                      "items": {
                                        "type": "string"
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        },
                        "maxLogBlockRange": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 1,
                          "maximum": 100000,
                          "description": "Largest block span of an `eth_getLogs`, `eth_newFilter` or `eth_getFilterLogs`. The smaller of this and the tier cap applies. null = no key limit."
                        },
                        "maxStateBlockDepth": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 0,
                          "maximum": 100000000,
                          "description": "Largest distance from the chain head a state read may name. null = no limit."
                        }
                      }
                    },
                    "secretRequired": {
                      "type": "boolean",
                      "description": "When true, the relay additionally enforces the `secret` on each request."
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "constraints": {
                      "type": "object",
                      "description": "The key's effective constraint set. Top-level fields are the defaults; `chainOverrides` specifies per-chain replacements (a chain key with `null` values inherits the top-level defaults).",
                      "properties": {
                        "allowedOrigins": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Browser `Origin` allow-list. Empty array = unrestricted."
                        },
                        "methodList": {
                          "type": "array",
                          "nullable": true,
                          "items": {
                            "type": "string"
                          },
                          "description": "`null`: every method. `[]`: no method; on a chain override, no method on that chain. A list: only those methods. A chain list replaces the default on its chain; an absent chain value inherits the default. The linked method policies apply as well: a call must pass both."
                        },
                        "allowedMethods": {
                          "type": "array",
                          "deprecated": true,
                          "items": {
                            "type": "string"
                          },
                          "description": "Deprecated: read `methodList`. The old meaning, kept for older clients: always an array, and `[]` means every method. A key that allows no method also reads `[]` here."
                        },
                        "enabledNetworks": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Network allow-list as CAIP-2 keys (`eip155:8453`). Empty = every network."
                        },
                        "chainOverrides": {
                          "type": "object",
                          "additionalProperties": true,
                          "description": "Per-chain replacements, keyed by chain-ID string. Each value is `{ allowedOrigins, allowedMethods, methodList }`, with `methodList` and the deprecated `allowedMethods` as at the top level."
                        }
                      }
                    },
                    "usage": {
                      "type": "object",
                      "description": "Two per-window figures, each over the same windows (total = 90 days, last24h, last7d). `requests` counts every call the key made, including calls the relay refused. `credits` is what those calls were charged, in NANO-DOLLARS — 1,700 credits is $0.0000017, so never render it as a dollar amount without the scale. They are separate because `credits` used to be returned alone under the request names, and the relay charges 0 credits on almost every call, so busy keys reported no traffic. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero. Plus `analyticsDisabled: true` when this key has opted out of RPC-request logging (`dataRetentionDays: 0`) — distinguishes \"opted out\" from \"just quiet\", both of which otherwise read as all-zero counters.",
                      "properties": {
                        "requests": {
                          "type": "object",
                          "nullable": true,
                          "description": "Calls received in each window, including calls the relay refused (a rate limit, a policy, no credits). Null while the rollup is pending.",
                          "properties": {
                            "total": {
                              "type": "integer",
                              "description": "The 90-day retention window."
                            },
                            "last24h": {
                              "type": "integer"
                            },
                            "last7d": {
                              "type": "integer"
                            }
                          },
                          "required": [
                            "total",
                            "last24h",
                            "last7d"
                          ]
                        },
                        "credits": {
                          "type": "object",
                          "nullable": true,
                          "description": "Credits charged in each window: refused calls cost nothing and count 0. A credit is a nano-dollar. Null while the rollup is pending.",
                          "properties": {
                            "total": {
                              "type": "number",
                              "description": "The 90-day retention window."
                            },
                            "last24h": {
                              "type": "number"
                            },
                            "last7d": {
                              "type": "number"
                            }
                          },
                          "required": [
                            "total",
                            "last24h",
                            "last7d"
                          ]
                        },
                        "asOf": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "When the rollup job last rewrote the partial hour. Null before its first full run. An old value means the job has stalled and every figure is stale."
                        },
                        "since": {
                          "type": "object",
                          "description": "Per window: the real start of the data when it is later than the window start, else null. A figure with a non-null `since` covers only the time from that instant.",
                          "properties": {
                            "total": {
                              "type": "string",
                              "format": "date-time",
                              "nullable": true,
                              "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                            },
                            "last24h": {
                              "type": "string",
                              "format": "date-time",
                              "nullable": true,
                              "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                            },
                            "last7d": {
                              "type": "string",
                              "format": "date-time",
                              "nullable": true,
                              "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                            }
                          }
                        },
                        "until": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                        },
                        "pending": {
                          "type": "boolean",
                          "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                        },
                        "analyticsDisabled": {
                          "type": "boolean"
                        }
                      },
                      "required": [
                        "requests",
                        "credits"
                      ],
                      "additionalProperties": true
                    }
                  },
                  "required": [
                    "projectKeyId",
                    "projectId",
                    "name",
                    "value",
                    "secretRequired",
                    "createdAt",
                    "constraints",
                    "usage"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Key not found or not owned by the caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "projects"
        ],
        "summary": "Update a key (name, constraints, per-chain overrides)",
        "description": "Patches `name` + any of the constraint axes (origins, methods, enabled networks) either globally or via `chainOverrides[<chainId>]`. The PATCH semantics are *replace-axis* — each axis array passed wholly replaces the prior set. Re-syncs the resolved config to Redis on success.",
        "operationId": "updateKey",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "allowedOrigins": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "methodList": {
                    "type": "array",
                    "nullable": true,
                    "items": {
                      "type": "string"
                    },
                    "description": "`null`: every method. `[]`: no method; on a chain override, no method on that chain. A list: only those methods, at most 1000 names after the dedupe. A chain list replaces the default on its chain; an absent chain value inherits the default. `[]` needs the empty list to be available; until then it answers 400."
                  },
                  "allowedMethods": {
                    "type": "array",
                    "nullable": true,
                    "deprecated": true,
                    "items": {
                      "type": "string"
                    },
                    "description": "Deprecated: send `methodList`. The old meaning, kept for older clients: `[]` or `null` allows every method, a list allows only those. It can never set 'no method'. A value equal to the scope's current `allowedMethods` (as a set) changes nothing, so it never removes a block. Do not send it with `methodList` for the same scope."
                  },
                  "enabledNetworks": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Networks the key may reach. Each entry is a registered EVM chain id (`8453`) or a CAIP-2 network key (`eip155:8453`); the API stores and returns CAIP-2. Empty = every network."
                  },
                  "secretRequired": {
                    "type": "boolean"
                  },
                  "limitScope": {
                    "type": "string",
                    "enum": [
                      "key",
                      "client"
                    ],
                    "description": "Which counter the limits use. `client` gives each client its own copy of this key's per-second, per-day and CU limits, and its own copy of the tier's requests-per-second ceiling. Only the account's credits-per-second limit and the project's daily request limit apply to all clients together. The billing class stays the key's. Has no effect on a key in `ip` rate-limit mode. Default `key`."
                  },
                  "trustedForwarders": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 8,
                    "description": "Exact addresses (IPv4 /32 or IPv6 /128, at most 8) of your own servers. A request from one of them may name its client in the `X-Valve-Client-IP` header. Used only with `limitScope: client`."
                  },
                  "paramRules": {
                    "type": "object",
                    "nullable": true,
                    "description": "Argument rules for the key: allow or deny a call by the values in its arguments (the `to` of an `eth_call`, the `address` and topics of an `eth_getLogs`, the decoded `to`, selector and `chainId` of an `eth_sendRawTransaction`), plus two key-wide limits. A rule judges every method of its family: `eth_call` judges `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `eth_callMany`, `debug_traceCallMany`, `trace_callMany`, `eth_callBundle`; `eth_getLogs` judges `eth_getLogs`, `eth_newFilter`, `eth_subscribe`; `eth_sendRawTransaction` judges `eth_sendRawTransaction`, `eth_sendRawTransactionConditional`, `eth_sendRawTransactionSync`, `eth_sendBundle`, `eth_sendPrivateTransaction`; `eth_getBalance` judges `eth_getBalance`, `eth_getProof`, `eth_getAccount`; `eth_getCode` judges `eth_getCode`; `eth_getStorageAt` judges `eth_getStorageAt`, `eth_getProof`. An absent `networks` means every network. A rule network must be an EVM (`eip155`) network. A rule applies to a call when the call is of its method (family) and on its networks. A matching `deny` rule refuses the call. If any `allow` rule applies for a method, the call must hold for at least one of them. With no applicable `allow` rule, the call passes. All conditions of a rule must hold. Method policies run first and a rule never widens them. `null` means no rules. While a rule applies, the relay refuses (`-32000`) a call it cannot read exactly: `params` that is not an array; a value not of the exact `0x` hex form (an empty `to` or a bare `0x` included); a method name that is not a string, or that spells a family method in another letter case or with look-alike characters; a tx object key that folds to `to`, `data`, `input` or `authorizationList` but is spelled otherwise; `input` and `data` that differ; a log filter with an unknown field; a raw transaction that does not decode or is over 1 MiB. Under an `eth_call` `allow` rule the relay also refuses: any state or block override, which is any non-null param from the first override slot on (`eth_call`, `eth_estimateGas` and `eth_createAccessList` from `params[2]`, `trace_call` from `params[3]`, which covers `params[3]` and `params[4]`, `debug_traceCall` from `params[3]` plus a `params[2]` tracing-option key that folds to `stateOverrides` or `blockOverrides`), so an empty `{}` override is refused too; a tx object key outside the call fields (`from`, `to`, `gas`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, `maxFeePerBlobGas`, `value`, `data`, `input`, `nonce`, `type`, `chainId`, `accessList`, `authorizationList`, `blobVersionedHashes`, `blobs`); a non-empty `authorizationList` (EIP-7702) on a tx object or a raw transaction; the override keys of the multi-call methods. A create (no `to`) fails every `to` allow and every `selector` allow, and trips no `to` or `selector` deny. While a rule applies, a multi-call request may carry at most 100 inner calls and 100 blocks or bundles; one inner call that fails refuses the whole request. A filter or a subscription made before a rule change stays live and keeps its old filter until it expires. Limits: at most 32 rules per key; 1 to 100 values per condition; at most 1000 values per key; 1 to 32 networks per rule; `maxLogBlockRange` 1 to 100000 or null; `maxStateBlockDepth` 0 to 100000000 or null. The API stores values lowercase, de-duplicated and sorted, and stores `chainId` as a decimal string. The API body limit of 100 KB binds before the 128 KiB column limit, so there is no separate document-size limit. `maxLogBlockRange` caps `eth_getLogs`, `eth_newFilter` and `eth_getFilterLogs`. With it set, `eth_getFilterLogs` is refused on a credit-exempt key and on any key the relay keeps no filter records for; use `eth_getLogs`. `maxStateBlockDepth` judges the block parameter of `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getAccount`, `eth_getStorageAt`, `eth_getProof`, `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `trace_callMany`, `eth_callMany`, `debug_traceCallMany`, `eth_callBundle`. The tags `latest`, `pending`, `safe` and `finalized` pass without a depth check, so `safe` and `finalized` are not bounded by the limit, even on a chain whose finality stalls. A block hash, or a numeric block while the head is unknown, is refused. `debug_traceBlockByNumber`, `debug_traceBlockByHash`, `trace_block`, `trace_replayBlockTransactions`, `debug_storageRangeAt`, `eth_getBlockByNumber`, `eth_getBlockByHash` read old state without it. To close them, deny those method names with a method policy.",
                    "required": [
                      "rules",
                      "maxLogBlockRange",
                      "maxStateBlockDepth"
                    ],
                    "properties": {
                      "rules": {
                        "type": "array",
                        "maxItems": 32,
                        "items": {
                          "type": "object",
                          "required": [
                            "effect",
                            "method",
                            "where"
                          ],
                          "properties": {
                            "effect": {
                              "type": "string",
                              "enum": [
                                "allow",
                                "deny"
                              ]
                            },
                            "method": {
                              "type": "string",
                              "enum": [
                                "eth_call",
                                "eth_getLogs",
                                "eth_sendRawTransaction",
                                "eth_getBalance",
                                "eth_getCode",
                                "eth_getStorageAt"
                              ]
                            },
                            "networks": {
                              "type": "array",
                              "minItems": 1,
                              "maxItems": 32,
                              "items": {
                                "type": "string"
                              },
                              "description": "Registered networks, as a chain id (`8453`) or a CAIP-2 key (`eip155:8453`). The API returns CAIP-2. Absent = every network."
                            },
                            "where": {
                              "type": "array",
                              "minItems": 1,
                              "description": "Conditions, each field at most once. A call matches the rule when every condition holds.",
                              "items": {
                                "type": "object",
                                "required": [
                                  "field",
                                  "in"
                                ],
                                "properties": {
                                  "field": {
                                    "type": "string",
                                    "enum": [
                                      "to",
                                      "selector",
                                      "address",
                                      "topic0",
                                      "topic1",
                                      "topic2",
                                      "topic3",
                                      "chainId"
                                    ]
                                  },
                                  "in": {
                                    "type": "array",
                                    "minItems": 1,
                                    "maxItems": 100,
                                    "items": {
                                      "type": "string"
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      },
                      "maxLogBlockRange": {
                        "type": "integer",
                        "nullable": true,
                        "minimum": 1,
                        "maximum": 100000,
                        "description": "Largest block span of an `eth_getLogs`, `eth_newFilter` or `eth_getFilterLogs`. The smaller of this and the tier cap applies. null = no key limit."
                      },
                      "maxStateBlockDepth": {
                        "type": "integer",
                        "nullable": true,
                        "minimum": 0,
                        "maximum": 100000000,
                        "description": "Largest distance from the chain head a state read may name. null = no limit."
                      }
                    }
                  },
                  "chainOverrides": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Per-chain replacements keyed by chain ID string. Each value is `null` (clear the chain: no origins, and the default method list applies) or a partial `{ allowedOrigins, methodList }` object (the deprecated `allowedMethods` also works, in its old meaning). An absent `methodList` leaves the chain's method list unchanged."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated key with resolved constraints.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projectKeyId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "projectId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string",
                      "description": "The `vk_…` token sent to the relay as `Authorization: Bearer`. Treat as a credential — surfaced here only for owner-readable list/get endpoints."
                    },
                    "limitScope": {
                      "type": "string",
                      "enum": [
                        "key",
                        "client"
                      ],
                      "description": "Which counter the limits use. `client` gives each client its own copy of this key's per-second, per-day and CU limits, and its own copy of the tier's requests-per-second ceiling. Only the account's credits-per-second limit and the project's daily request limit apply to all clients together. The billing class stays the key's. Has no effect on a key in `ip` rate-limit mode. Default `key`."
                    },
                    "trustedForwarders": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "maxItems": 8,
                      "description": "Exact addresses (IPv4 /32 or IPv6 /128, at most 8) of your own servers. A request from one of them may name its client in the `X-Valve-Client-IP` header. Used only with `limitScope: client`."
                    },
                    "paramRules": {
                      "type": "object",
                      "nullable": true,
                      "description": "Argument rules for the key: allow or deny a call by the values in its arguments (the `to` of an `eth_call`, the `address` and topics of an `eth_getLogs`, the decoded `to`, selector and `chainId` of an `eth_sendRawTransaction`), plus two key-wide limits. A rule judges every method of its family: `eth_call` judges `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `eth_callMany`, `debug_traceCallMany`, `trace_callMany`, `eth_callBundle`; `eth_getLogs` judges `eth_getLogs`, `eth_newFilter`, `eth_subscribe`; `eth_sendRawTransaction` judges `eth_sendRawTransaction`, `eth_sendRawTransactionConditional`, `eth_sendRawTransactionSync`, `eth_sendBundle`, `eth_sendPrivateTransaction`; `eth_getBalance` judges `eth_getBalance`, `eth_getProof`, `eth_getAccount`; `eth_getCode` judges `eth_getCode`; `eth_getStorageAt` judges `eth_getStorageAt`, `eth_getProof`. An absent `networks` means every network. A rule network must be an EVM (`eip155`) network. A rule applies to a call when the call is of its method (family) and on its networks. A matching `deny` rule refuses the call. If any `allow` rule applies for a method, the call must hold for at least one of them. With no applicable `allow` rule, the call passes. All conditions of a rule must hold. Method policies run first and a rule never widens them. `null` means no rules. While a rule applies, the relay refuses (`-32000`) a call it cannot read exactly: `params` that is not an array; a value not of the exact `0x` hex form (an empty `to` or a bare `0x` included); a method name that is not a string, or that spells a family method in another letter case or with look-alike characters; a tx object key that folds to `to`, `data`, `input` or `authorizationList` but is spelled otherwise; `input` and `data` that differ; a log filter with an unknown field; a raw transaction that does not decode or is over 1 MiB. Under an `eth_call` `allow` rule the relay also refuses: any state or block override, which is any non-null param from the first override slot on (`eth_call`, `eth_estimateGas` and `eth_createAccessList` from `params[2]`, `trace_call` from `params[3]`, which covers `params[3]` and `params[4]`, `debug_traceCall` from `params[3]` plus a `params[2]` tracing-option key that folds to `stateOverrides` or `blockOverrides`), so an empty `{}` override is refused too; a tx object key outside the call fields (`from`, `to`, `gas`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, `maxFeePerBlobGas`, `value`, `data`, `input`, `nonce`, `type`, `chainId`, `accessList`, `authorizationList`, `blobVersionedHashes`, `blobs`); a non-empty `authorizationList` (EIP-7702) on a tx object or a raw transaction; the override keys of the multi-call methods. A create (no `to`) fails every `to` allow and every `selector` allow, and trips no `to` or `selector` deny. While a rule applies, a multi-call request may carry at most 100 inner calls and 100 blocks or bundles; one inner call that fails refuses the whole request. A filter or a subscription made before a rule change stays live and keeps its old filter until it expires. Limits: at most 32 rules per key; 1 to 100 values per condition; at most 1000 values per key; 1 to 32 networks per rule; `maxLogBlockRange` 1 to 100000 or null; `maxStateBlockDepth` 0 to 100000000 or null. The API stores values lowercase, de-duplicated and sorted, and stores `chainId` as a decimal string. The API body limit of 100 KB binds before the 128 KiB column limit, so there is no separate document-size limit. `maxLogBlockRange` caps `eth_getLogs`, `eth_newFilter` and `eth_getFilterLogs`. With it set, `eth_getFilterLogs` is refused on a credit-exempt key and on any key the relay keeps no filter records for; use `eth_getLogs`. `maxStateBlockDepth` judges the block parameter of `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getAccount`, `eth_getStorageAt`, `eth_getProof`, `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `trace_callMany`, `eth_callMany`, `debug_traceCallMany`, `eth_callBundle`. The tags `latest`, `pending`, `safe` and `finalized` pass without a depth check, so `safe` and `finalized` are not bounded by the limit, even on a chain whose finality stalls. A block hash, or a numeric block while the head is unknown, is refused. `debug_traceBlockByNumber`, `debug_traceBlockByHash`, `trace_block`, `trace_replayBlockTransactions`, `debug_storageRangeAt`, `eth_getBlockByNumber`, `eth_getBlockByHash` read old state without it. To close them, deny those method names with a method policy.",
                      "required": [
                        "rules",
                        "maxLogBlockRange",
                        "maxStateBlockDepth"
                      ],
                      "properties": {
                        "rules": {
                          "type": "array",
                          "maxItems": 32,
                          "items": {
                            "type": "object",
                            "required": [
                              "effect",
                              "method",
                              "where"
                            ],
                            "properties": {
                              "effect": {
                                "type": "string",
                                "enum": [
                                  "allow",
                                  "deny"
                                ]
                              },
                              "method": {
                                "type": "string",
                                "enum": [
                                  "eth_call",
                                  "eth_getLogs",
                                  "eth_sendRawTransaction",
                                  "eth_getBalance",
                                  "eth_getCode",
                                  "eth_getStorageAt"
                                ]
                              },
                              "networks": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 32,
                                "items": {
                                  "type": "string"
                                },
                                "description": "Registered networks, as a chain id (`8453`) or a CAIP-2 key (`eip155:8453`). The API returns CAIP-2. Absent = every network."
                              },
                              "where": {
                                "type": "array",
                                "minItems": 1,
                                "description": "Conditions, each field at most once. A call matches the rule when every condition holds.",
                                "items": {
                                  "type": "object",
                                  "required": [
                                    "field",
                                    "in"
                                  ],
                                  "properties": {
                                    "field": {
                                      "type": "string",
                                      "enum": [
                                        "to",
                                        "selector",
                                        "address",
                                        "topic0",
                                        "topic1",
                                        "topic2",
                                        "topic3",
                                        "chainId"
                                      ]
                                    },
                                    "in": {
                                      "type": "array",
                                      "minItems": 1,
                                      "maxItems": 100,
                                      "items": {
                                        "type": "string"
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        },
                        "maxLogBlockRange": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 1,
                          "maximum": 100000,
                          "description": "Largest block span of an `eth_getLogs`, `eth_newFilter` or `eth_getFilterLogs`. The smaller of this and the tier cap applies. null = no key limit."
                        },
                        "maxStateBlockDepth": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 0,
                          "maximum": 100000000,
                          "description": "Largest distance from the chain head a state read may name. null = no limit."
                        }
                      }
                    },
                    "secretRequired": {
                      "type": "boolean",
                      "description": "When true, the relay additionally enforces the `secret` on each request."
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "constraints": {
                      "type": "object",
                      "description": "The key's effective constraint set. Top-level fields are the defaults; `chainOverrides` specifies per-chain replacements (a chain key with `null` values inherits the top-level defaults).",
                      "properties": {
                        "allowedOrigins": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Browser `Origin` allow-list. Empty array = unrestricted."
                        },
                        "methodList": {
                          "type": "array",
                          "nullable": true,
                          "items": {
                            "type": "string"
                          },
                          "description": "`null`: every method. `[]`: no method; on a chain override, no method on that chain. A list: only those methods. A chain list replaces the default on its chain; an absent chain value inherits the default. The linked method policies apply as well: a call must pass both."
                        },
                        "allowedMethods": {
                          "type": "array",
                          "deprecated": true,
                          "items": {
                            "type": "string"
                          },
                          "description": "Deprecated: read `methodList`. The old meaning, kept for older clients: always an array, and `[]` means every method. A key that allows no method also reads `[]` here."
                        },
                        "enabledNetworks": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Network allow-list as CAIP-2 keys (`eip155:8453`). Empty = every network."
                        },
                        "chainOverrides": {
                          "type": "object",
                          "additionalProperties": true,
                          "description": "Per-chain replacements, keyed by chain-ID string. Each value is `{ allowedOrigins, allowedMethods, methodList }`, with `methodList` and the deprecated `allowedMethods` as at the top level."
                        }
                      }
                    }
                  },
                  "required": [
                    "projectKeyId",
                    "projectId",
                    "name",
                    "value",
                    "secretRequired",
                    "createdAt",
                    "constraints"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "An unregistered network in `enabledNetworks`, an unknown chain ID in `chainOverrides`, a `limitScope` other than `key` or `client`, an invalid `trustedForwarders` entry (a range, an unspecified or loopback address, or more than 8), or an invalid `paramRules`: the gate is closed for a non-admin and the value is not `null` (\"Param rules are not available yet\"), a value breaks a limit (the error names the path, such as `rules.0.where.1.in.3`), or a rule names an unregistered, staged or non-EVM network (`rules.0.networks`). Also: `methodList` is `[]` before the empty list is available ('Allowing no method (methodList []) is not available yet...') or is not `null` or a list of method names; a list holds more than 1000 names; `allowedMethods` is not a list of method names; or one scope sends both `methodList` and `allowedMethods`. The same holds for `chainOverrides.<chainId>`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write or Redis sync failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "projects"
        ],
        "summary": "Revoke (soft-delete) a key",
        "description": "Sets `unlinkedAt`, removes the cached config from Redis. The relay drops the key on its next request.",
        "operationId": "revokeKey",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Key revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projectKeyId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "projectId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string",
                      "description": "The `vk_…` token sent to the relay as `Authorization: Bearer`. Treat as a credential — surfaced here only for owner-readable list/get endpoints."
                    },
                    "limitScope": {
                      "type": "string",
                      "enum": [
                        "key",
                        "client"
                      ],
                      "description": "Which counter the limits use. `client` gives each client its own copy of this key's per-second, per-day and CU limits, and its own copy of the tier's requests-per-second ceiling. Only the account's credits-per-second limit and the project's daily request limit apply to all clients together. The billing class stays the key's. Has no effect on a key in `ip` rate-limit mode. Default `key`."
                    },
                    "trustedForwarders": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "maxItems": 8,
                      "description": "Exact addresses (IPv4 /32 or IPv6 /128, at most 8) of your own servers. A request from one of them may name its client in the `X-Valve-Client-IP` header. Used only with `limitScope: client`."
                    },
                    "paramRules": {
                      "type": "object",
                      "nullable": true,
                      "description": "Argument rules for the key: allow or deny a call by the values in its arguments (the `to` of an `eth_call`, the `address` and topics of an `eth_getLogs`, the decoded `to`, selector and `chainId` of an `eth_sendRawTransaction`), plus two key-wide limits. A rule judges every method of its family: `eth_call` judges `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `eth_callMany`, `debug_traceCallMany`, `trace_callMany`, `eth_callBundle`; `eth_getLogs` judges `eth_getLogs`, `eth_newFilter`, `eth_subscribe`; `eth_sendRawTransaction` judges `eth_sendRawTransaction`, `eth_sendRawTransactionConditional`, `eth_sendRawTransactionSync`, `eth_sendBundle`, `eth_sendPrivateTransaction`; `eth_getBalance` judges `eth_getBalance`, `eth_getProof`, `eth_getAccount`; `eth_getCode` judges `eth_getCode`; `eth_getStorageAt` judges `eth_getStorageAt`, `eth_getProof`. An absent `networks` means every network. A rule network must be an EVM (`eip155`) network. A rule applies to a call when the call is of its method (family) and on its networks. A matching `deny` rule refuses the call. If any `allow` rule applies for a method, the call must hold for at least one of them. With no applicable `allow` rule, the call passes. All conditions of a rule must hold. Method policies run first and a rule never widens them. `null` means no rules. While a rule applies, the relay refuses (`-32000`) a call it cannot read exactly: `params` that is not an array; a value not of the exact `0x` hex form (an empty `to` or a bare `0x` included); a method name that is not a string, or that spells a family method in another letter case or with look-alike characters; a tx object key that folds to `to`, `data`, `input` or `authorizationList` but is spelled otherwise; `input` and `data` that differ; a log filter with an unknown field; a raw transaction that does not decode or is over 1 MiB. Under an `eth_call` `allow` rule the relay also refuses: any state or block override, which is any non-null param from the first override slot on (`eth_call`, `eth_estimateGas` and `eth_createAccessList` from `params[2]`, `trace_call` from `params[3]`, which covers `params[3]` and `params[4]`, `debug_traceCall` from `params[3]` plus a `params[2]` tracing-option key that folds to `stateOverrides` or `blockOverrides`), so an empty `{}` override is refused too; a tx object key outside the call fields (`from`, `to`, `gas`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, `maxFeePerBlobGas`, `value`, `data`, `input`, `nonce`, `type`, `chainId`, `accessList`, `authorizationList`, `blobVersionedHashes`, `blobs`); a non-empty `authorizationList` (EIP-7702) on a tx object or a raw transaction; the override keys of the multi-call methods. A create (no `to`) fails every `to` allow and every `selector` allow, and trips no `to` or `selector` deny. While a rule applies, a multi-call request may carry at most 100 inner calls and 100 blocks or bundles; one inner call that fails refuses the whole request. A filter or a subscription made before a rule change stays live and keeps its old filter until it expires. Limits: at most 32 rules per key; 1 to 100 values per condition; at most 1000 values per key; 1 to 32 networks per rule; `maxLogBlockRange` 1 to 100000 or null; `maxStateBlockDepth` 0 to 100000000 or null. The API stores values lowercase, de-duplicated and sorted, and stores `chainId` as a decimal string. The API body limit of 100 KB binds before the 128 KiB column limit, so there is no separate document-size limit. `maxLogBlockRange` caps `eth_getLogs`, `eth_newFilter` and `eth_getFilterLogs`. With it set, `eth_getFilterLogs` is refused on a credit-exempt key and on any key the relay keeps no filter records for; use `eth_getLogs`. `maxStateBlockDepth` judges the block parameter of `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getAccount`, `eth_getStorageAt`, `eth_getProof`, `eth_call`, `eth_estimateGas`, `eth_createAccessList`, `debug_traceCall`, `trace_call`, `trace_rawTransaction`, `eth_simulateV1`, `trace_callMany`, `eth_callMany`, `debug_traceCallMany`, `eth_callBundle`. The tags `latest`, `pending`, `safe` and `finalized` pass without a depth check, so `safe` and `finalized` are not bounded by the limit, even on a chain whose finality stalls. A block hash, or a numeric block while the head is unknown, is refused. `debug_traceBlockByNumber`, `debug_traceBlockByHash`, `trace_block`, `trace_replayBlockTransactions`, `debug_storageRangeAt`, `eth_getBlockByNumber`, `eth_getBlockByHash` read old state without it. To close them, deny those method names with a method policy.",
                      "required": [
                        "rules",
                        "maxLogBlockRange",
                        "maxStateBlockDepth"
                      ],
                      "properties": {
                        "rules": {
                          "type": "array",
                          "maxItems": 32,
                          "items": {
                            "type": "object",
                            "required": [
                              "effect",
                              "method",
                              "where"
                            ],
                            "properties": {
                              "effect": {
                                "type": "string",
                                "enum": [
                                  "allow",
                                  "deny"
                                ]
                              },
                              "method": {
                                "type": "string",
                                "enum": [
                                  "eth_call",
                                  "eth_getLogs",
                                  "eth_sendRawTransaction",
                                  "eth_getBalance",
                                  "eth_getCode",
                                  "eth_getStorageAt"
                                ]
                              },
                              "networks": {
                                "type": "array",
                                "minItems": 1,
                                "maxItems": 32,
                                "items": {
                                  "type": "string"
                                },
                                "description": "Registered networks, as a chain id (`8453`) or a CAIP-2 key (`eip155:8453`). The API returns CAIP-2. Absent = every network."
                              },
                              "where": {
                                "type": "array",
                                "minItems": 1,
                                "description": "Conditions, each field at most once. A call matches the rule when every condition holds.",
                                "items": {
                                  "type": "object",
                                  "required": [
                                    "field",
                                    "in"
                                  ],
                                  "properties": {
                                    "field": {
                                      "type": "string",
                                      "enum": [
                                        "to",
                                        "selector",
                                        "address",
                                        "topic0",
                                        "topic1",
                                        "topic2",
                                        "topic3",
                                        "chainId"
                                      ]
                                    },
                                    "in": {
                                      "type": "array",
                                      "minItems": 1,
                                      "maxItems": 100,
                                      "items": {
                                        "type": "string"
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        },
                        "maxLogBlockRange": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 1,
                          "maximum": 100000,
                          "description": "Largest block span of an `eth_getLogs`, `eth_newFilter` or `eth_getFilterLogs`. The smaller of this and the tier cap applies. null = no key limit."
                        },
                        "maxStateBlockDepth": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 0,
                          "maximum": 100000000,
                          "description": "Largest distance from the chain head a state read may name. null = no limit."
                        }
                      }
                    },
                    "secretRequired": {
                      "type": "boolean",
                      "description": "When true, the relay additionally enforces the `secret` on each request."
                    },
                    "unlinkedAt": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "revoked": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "projectKeyId",
                    "projectId",
                    "name",
                    "value",
                    "secretRequired",
                    "createdAt",
                    "revoked"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write or Redis invalidate failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/:keyId/secret": {
      "get": {
        "tags": [
          "projects"
        ],
        "summary": "Reveal a key's `secret` (when `secretRequired` is enabled)",
        "description": "Returns the key's stored `secret` UUID. Most keys do not require a secret (the `vk_…` token alone authenticates); this endpoint is the read path for keys with `secretRequired=true`, where the relay additionally requires the secret as a second factor on each request.",
        "operationId": "getKeySecret",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The secret (or null when not set).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "secret": {
                      "type": "string",
                      "format": "uuid",
                      "nullable": true
                    }
                  },
                  "required": [
                    "secret"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/:keyId/policies": {
      "get": {
        "tags": [
          "method-policies"
        ],
        "summary": "List method policies linked to a key",
        "description": "Each link carries the policy details + the per-link `chainId` (null means \"all chains\").",
        "operationId": "listKeyPolicies",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Array of link rows with embedded policy details.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "keyId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "policyId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "chainId": {
                        "type": "integer",
                        "nullable": true,
                        "description": "Null applies the policy across all chains."
                      },
                      "network": {
                        "type": "string",
                        "nullable": true,
                        "description": "The CAIP-2 key of `chainId` (`eip155:369`). Null applies the policy across all chains."
                      },
                      "createdAt": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "policy": {
                        "type": "object",
                        "properties": {
                          "policyId": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string",
                            "nullable": true
                          },
                          "rules": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "isSystem": {
                            "type": "boolean",
                            "description": "True for presets (e.g. \"all\", \"read-only\"); false for account-owned policies."
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "method-policies"
        ],
        "summary": "Link a method policy to a key",
        "description": "Adds a `key_method_policy` link row. The policy must be a system preset (any caller) or owned by the caller's account (`policy.accountId === accountId`). Re-syncs the resolved key config to Redis on success.",
        "operationId": "linkKeyPolicy",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "policyId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "chainId": {
                    "type": "integer",
                    "nullable": true,
                    "description": "Null to apply across all chains."
                  },
                  "network": {
                    "type": "string",
                    "description": "Instead of `chainId`: a chain id or CAIP-2 key (`eip155:369`). Must name an EVM network, and must agree with `chainId` when both are sent."
                  }
                },
                "required": [
                  "policyId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Created link row.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "`policyId` missing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Policy belongs to another account and is not a system preset.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Key or policy not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write or Redis sync failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/:keyId/policies/:linkId": {
      "delete": {
        "tags": [
          "method-policies"
        ],
        "summary": "Unlink a method policy from a key",
        "description": "Removes the link row by `linkId`. Re-syncs the resolved key config to Redis on success.",
        "operationId": "unlinkKeyPolicy",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "linkId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Link removed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "deleted": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "deleted"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Key or link not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write or Redis sync failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits": {
      "get": {
        "tags": [
          "credits"
        ],
        "summary": "Effective balance + deposit history",
        "description": "Effective balance = `ceiling + pending - spend` from the Redis three-value cache. Cold-cache path: when `ceiling` is null, the api recomputes from `credit_deposit` and trusts that as the answer (the next refresh sweep SETs it for subsequent reads). Default target is the caller's account; `?accountId=` switches target (admin or self).\n\nPaid credits never expire. A paid deposit (an x402 payment or an on-chain deposit) has `expiresAt: null`. A grant or trial keeps its expiry date.",
        "operationId": "getCredits",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Balance + deposit ledger.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "string",
                      "description": "Stringified non-negative integer (credits); never negative even if `spend > ceiling + pending`."
                    },
                    "tier": {
                      "type": "string",
                      "enum": [
                        "FULL",
                        "SLOW"
                      ],
                      "description": "The tier the relay gives this account now. FULL needs lifetime paid deposits of at least `tierRule.minPaid` AND a balance of at least `tierRule.minBalance`. It is judged on the same inputs the relay reads, so with a cold cache (no Redis ceiling yet) it can be SLOW while `balance` shows the Postgres value. The credits-per-second limit itself is relay config: read it from the relay's `X-RateLimit-Limit` header."
                    },
                    "tierReason": {
                      "type": "string",
                      "enum": [
                        "full",
                        "paid_under_minimum",
                        "balance_under_floor",
                        "paid_flag_missing"
                      ],
                      "description": "Why the account has its tier: `full`; `paid_under_minimum` (paid in under `tierRule.minPaid`; free, trial and admin-grant credits never count); `balance_under_floor` (paid in enough, balance under `tierRule.minBalance`); `paid_flag_missing` (the api has not published this account's paid status yet; it is SLOW until it does)."
                    },
                    "paidTotal": {
                      "type": "string",
                      "description": "Credits issued by every paid deposit (x402 payments and on-chain deposits) over the life of the account, spent or not."
                    },
                    "tierRule": {
                      "type": "object",
                      "description": "The thresholds of the tier rule, in credits.",
                      "properties": {
                        "minPaid": {
                          "type": "string",
                          "description": "Lifetime paid credits FULL needs: 1,000,000,000 ($1)."
                        },
                        "minBalance": {
                          "type": "string",
                          "description": "Balance FULL needs: 40,000,000 ($0.04)."
                        }
                      },
                      "required": [
                        "minPaid",
                        "minBalance"
                      ]
                    },
                    "tierRates": {
                      "type": "object",
                      "description": "The per-account rates of each tier, as strings: requests per second and credits per second. The api reads the same setting names as the relay (FULL_RATE_RPS, SLOW_RATE_RPS, FULL_CREDITS_PER_SEC, SLOW_CREDITS_PER_SEC) from its own environment. Production keeps both the same. The request rate applies to each key. The credits rate applies to the whole account.",
                      "properties": {
                        "full": {
                          "type": "object",
                          "properties": {
                            "rps": {
                              "type": "string"
                            },
                            "creditsPerSecond": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "rps",
                            "creditsPerSecond"
                          ]
                        },
                        "slow": {
                          "type": "object",
                          "properties": {
                            "rps": {
                              "type": "string"
                            },
                            "creditsPerSecond": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "rps",
                            "creditsPerSecond"
                          ]
                        }
                      },
                      "required": [
                        "full",
                        "slow"
                      ]
                    },
                    "deposits": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "depositId": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "txHash": {
                            "type": "string"
                          },
                          "chainId": {
                            "type": "integer",
                            "description": "0 for an admin grant."
                          },
                          "network": {
                            "type": "string",
                            "nullable": true,
                            "description": "The CAIP-2 key of the chain (`eip155:369`), or `*` for an admin grant. Null for a chain the registry does not hold."
                          },
                          "tokenAddress": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "string",
                            "description": "Token base-unit amount (stringified)."
                          },
                          "creditsIssued": {
                            "type": "string"
                          },
                          "creditsRemaining": {
                            "type": "string"
                          },
                          "rateTokenPerCredit": {
                            "type": "string"
                          },
                          "rateSource": {
                            "type": "string"
                          },
                          "expiresAt": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true,
                            "description": "Null for a paid deposit: paid credits never expire. A grant or trial has the date it expires."
                          },
                          "depositedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    }
                  },
                  "required": [
                    "balance",
                    "tier",
                    "tierReason",
                    "paidTotal",
                    "tierRule",
                    "tierRates",
                    "deposits"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access the requested account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Redis or database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "credits"
        ],
        "summary": "[Admin] Grant credits to an account",
        "description": "Admin-only credit grant. Inserts a `credit_deposit` row with a synthetic `txHash` (`admin:<ts>:<accountId>:<random id>`), `chainId=0` and `network=\"*\"` so the audit trail is intact even though no on-chain transfer occurred. Bumps Redis pending+ceiling. `expiresInDays` sets when the grant expires. Grants and trials expire; paid credits never do.",
        "operationId": "grantCredits",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "accountId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "amount": {
                    "type": "string",
                    "description": "Stringified bigint, in credits (1 USD = 10^9 credits)."
                  },
                  "expiresInDays": {
                    "type": "integer"
                  },
                  "reason": {
                    "type": "string"
                  }
                },
                "required": [
                  "accountId",
                  "amount",
                  "expiresInDays"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deposit row inserted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Zod validation failed (see body.error.issues).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write or Redis bump failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/ledger": {
      "get": {
        "tags": [
          "credits"
        ],
        "summary": "Every balance change, newest first",
        "description": "**Deprecated.** Use `GET /v1/credits/ledger/entries`. This route keeps its old shape for older clients. It is now built from the stored ledger entries, so its history is the ledger and sums to the balance.\n\nOne dated list of every change to the account balance: `deposit` (paid on-chain or x402 deposit, +), `grant` (any other credit row, such as an admin grant, an adjustment or a failed payment; `reason` is its label, +), `trial` (`prvx-trial:` row, +), `pending` (x402 credits granted before settlement, +), `expiry` (the credits billing removed when a grant or trial lapsed, −; paid credits never expire, so a paid deposit never has one), and `spend` (one row per UTC day: charged RPC credits plus bandwidth debits, −). Amounts are signed credits (1 USD = 10^9 credits) as strings.\n\n**Running balance.** The newest closed row's `balanceAfter` is the balance after that row. Today's spend row has `today: true` and `partial: true`. A row older than `spendHorizon` has `balanceAfter: null` and `beforeSpendHorizon: true`: no true figure exists for it.\n\n**Fixed drift fields.** The stored history is the ledger, so there is nothing to reconcile. `reconciled` is always `true`, `drift` is always `\"0\"`, every part of `driftParts` is `\"0\"`, `cacheSettling` is always `false` and `spendUnrolled` is always `\"0\"`. Clients should stop reading them. The new route has none of them.\n\n**Paging.** Default range: the 30 days before now. Longest range: 366 days. Pass `nextCursor` as `cursor` with the `from` and `to` the first page returned.",
        "deprecated": true,
        "operationId": "getCreditLedger",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Admin only: read another account's ledger. Default: the caller's own account. Any other caller gets 403."
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Start of the range. Default: 30 days before `to`."
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "End of the range. Default and maximum: now. Omit it on a first page: today's spend row is dated at the moment of the read, so a `to` from a client clock behind the server's leaves that row out. Send the `to` the first page returned on later pages."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "`nextCursor` from the previous page."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            },
            "description": "Rows per page. Default 100."
          }
        ],
        "responses": {
          "200": {
            "description": "One page of the ledger.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accountId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "from": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "to": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "balance": {
                      "type": "string",
                      "description": "The current balance, as `GET /v1/credits` returns it."
                    },
                    "pending": {
                      "type": "string",
                      "description": "x402 credits granted before settlement. The `pending` row carries them."
                    },
                    "reconciled": {
                      "type": "boolean",
                      "deprecated": true,
                      "description": "Fixed value: always `true`."
                    },
                    "drift": {
                      "type": "string",
                      "deprecated": true,
                      "description": "Fixed value: always `\"0\"`."
                    },
                    "driftParts": {
                      "type": "object",
                      "deprecated": true,
                      "description": "Fixed values: `floor`, `cache` and `deposits` are always `\"0\"`.",
                      "properties": {
                        "floor": {
                          "type": "string"
                        },
                        "cache": {
                          "type": "string"
                        },
                        "deposits": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "floor",
                        "cache",
                        "deposits"
                      ]
                    },
                    "cacheSettling": {
                      "type": "boolean",
                      "deprecated": true,
                      "description": "Fixed value: always `false`."
                    },
                    "spendUnrolled": {
                      "type": "string",
                      "deprecated": true,
                      "description": "Fixed value: always `\"0\"`."
                    },
                    "spendHorizon": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "Where the stored records start (`recordsFrom` of the new route). Rows older than this have no balance."
                    },
                    "spendAsOf": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "When today's open spend row was read. Null when there is none."
                    },
                    "entries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "deposit",
                              "grant",
                              "trial",
                              "pending",
                              "expiry",
                              "spend"
                            ]
                          },
                          "amount": {
                            "type": "string",
                            "description": "Signed credits."
                          },
                          "balanceAfter": {
                            "type": "string",
                            "nullable": true,
                            "description": "Null when `beforeSpendHorizon`."
                          },
                          "beforeSpendHorizon": {
                            "type": "boolean",
                            "description": "The row is older than `spendHorizon`, so no true balance exists for it."
                          },
                          "reason": {
                            "type": "string",
                            "description": "Grants and trials: the row's `rate_source`."
                          },
                          "txHash": {
                            "type": "string",
                            "description": "Deposits only: the on-chain hash (`:<logIndex>` may follow) or the `x402:` settlement key."
                          },
                          "chainId": {
                            "type": "integer"
                          },
                          "depositId": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "day": {
                            "type": "string",
                            "description": "Spend rows: the UTC day, `YYYY-MM-DD`."
                          },
                          "partial": {
                            "type": "boolean",
                            "description": "Spend rows: the day is not over, not fully rolled up, or cut by the spend horizon."
                          },
                          "today": {
                            "type": "boolean",
                            "description": "Spend rows: the day is today (UTC)."
                          },
                          "rpcCredits": {
                            "type": "string"
                          },
                          "bandwidthCredits": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "at",
                          "kind",
                          "amount",
                          "balanceAfter",
                          "beforeSpendHorizon"
                        ]
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true
                    }
                  },
                  "required": [
                    "accountId",
                    "from",
                    "to",
                    "balance",
                    "pending",
                    "reconciled",
                    "drift",
                    "driftParts",
                    "cacheSettling",
                    "spendUnrolled",
                    "spendHorizon",
                    "spendAsOf",
                    "entries",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad `from`, `to`, `cursor`, `limit` or `accountId` (not one UUID), or a range longer than 366 days.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No credentials, or an invalid, revoked or expired session token or signature.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access the requested account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Redis or database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/ledger/entries": {
      "get": {
        "tags": [
          "credits"
        ],
        "summary": "The stored ledger, newest first",
        "description": "One page of the account ledger, from stored entries. Each entry is one change to the balance, with the balance after it. Amounts are signed credits (1 USD = 10^9 credits) as strings.\n\n`kind` is `deposit` (a payment; `status` says `pending`, `settled` or `failed`), `deposit_failed`, `grant`, `trial`, `expiry`, `usage` (one row per closed UTC day: charged calls plus bandwidth) or `adjustment`.\n\n**First page.** A page with no `cursor` also carries `live`: the usage since the last closed day. It is not an entry and it has no cursor position.\n\n**Records start.** A row older than `recordsFrom` has `balanceAfter: null`: the usage around it is not on record. While the account's ledger is being built, `ready` is `false` and `entries` is empty.\n\n**Access.** An account reads its own ledger. An admin may pass `accountId` to read another account. Any other caller gets 403. The answer is never cached (`Cache-Control: no-store`).",
        "operationId": "getCreditLedgerEntries",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Admin only: read another account's ledger. Default: the caller's own account. Any other caller gets 403."
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Only rows at or after this time."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "`nextCursor` from the previous page."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            },
            "description": "Rows per page. Default 50."
          }
        ],
        "responses": {
          "200": {
            "description": "One page of the ledger.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ready": {
                      "type": "boolean",
                      "description": "False while the account's ledger is being built. `entries` is then empty."
                    },
                    "balance": {
                      "type": "string",
                      "description": "The current balance, as `GET /v1/credits` returns it."
                    },
                    "pending": {
                      "type": "string",
                      "description": "x402 credits granted before settlement."
                    },
                    "recordsFrom": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "Rows older than this show no balance. Null while the ledger is being built."
                    },
                    "live": {
                      "type": "object",
                      "nullable": true,
                      "description": "The usage since the last closed day. First page only.",
                      "properties": {
                        "from": {
                          "type": "string",
                          "description": "The UTC day the usage starts, `YYYY-MM-DD`."
                        },
                        "asOf": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "amount": {
                          "type": "string",
                          "description": "Signed credits."
                        },
                        "balanceAfter": {
                          "type": "string"
                        },
                        "detail": {
                          "type": "object",
                          "additionalProperties": true
                        }
                      },
                      "required": [
                        "from",
                        "asOf",
                        "amount",
                        "balanceAfter",
                        "detail"
                      ]
                    },
                    "entries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "kind": {
                            "type": "string",
                            "enum": [
                              "deposit",
                              "deposit_failed",
                              "grant",
                              "trial",
                              "expiry",
                              "usage",
                              "adjustment"
                            ]
                          },
                          "status": {
                            "type": "string",
                            "nullable": true,
                            "enum": [
                              "pending",
                              "settled",
                              "failed"
                            ],
                            "description": "On a `deposit` row only. Null on every other kind."
                          },
                          "amount": {
                            "type": "string",
                            "description": "Signed credits."
                          },
                          "balanceAfter": {
                            "type": "string",
                            "nullable": true,
                            "description": "Null for a row older than `recordsFrom`."
                          },
                          "day": {
                            "type": "string",
                            "nullable": true,
                            "description": "A `usage` row: the UTC day, `YYYY-MM-DD`."
                          },
                          "detail": {
                            "type": "object",
                            "additionalProperties": true
                          }
                        },
                        "required": [
                          "id",
                          "at",
                          "kind",
                          "status",
                          "amount",
                          "balanceAfter",
                          "day",
                          "detail"
                        ]
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true
                    }
                  },
                  "required": [
                    "ready",
                    "balance",
                    "pending",
                    "recordsFrom",
                    "live",
                    "entries",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad `from`, `cursor` or `limit`, or `accountId` is not one UUID.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No credentials, or an invalid, revoked or expired session token or signature.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Caller is not authorized to access the requested account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Redis or database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/deposits": {
      "get": {
        "tags": [
          "credits"
        ],
        "summary": "The signed-in account's deposits",
        "description": "One page of the account's deposits, newest first. Pending x402 authorizations come first (a settled one is listed once, as its deposit row), then the deposit rows. `credits` is what the deposit issued. `amount` is the exact token amount.\n\nThis route reads the signed-in account only. `accountId` for another account and `all=true` answer 400, for an admin too. The answer is never cached (`Cache-Control: no-store`).",
        "operationId": "getCreditDeposits",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "`nextCursor` from the previous page."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            },
            "description": "Rows per page. Default 50."
          }
        ],
        "responses": {
          "200": {
            "description": "One page of deposits.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deposits": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "pending",
                              "settled"
                            ]
                          },
                          "at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "txHash": {
                            "type": "string",
                            "nullable": true,
                            "description": "No `:<log index>` suffix. Null while pending. `x402:<auth>` for an x402 payment."
                          },
                          "chainId": {
                            "type": "integer"
                          },
                          "token": {
                            "type": "object",
                            "properties": {
                              "address": {
                                "type": "string"
                              },
                              "symbol": {
                                "type": "string",
                                "nullable": true
                              },
                              "decimals": {
                                "type": "integer",
                                "nullable": true
                              }
                            },
                            "required": [
                              "address",
                              "symbol",
                              "decimals"
                            ]
                          },
                          "amount": {
                            "type": "string",
                            "description": "The exact token amount. In base units when the token's decimals are unknown."
                          },
                          "credits": {
                            "type": "string",
                            "description": "Credits the deposit issued."
                          },
                          "tokensPerUsd": {
                            "type": "string"
                          },
                          "rateSource": {
                            "type": "string"
                          },
                          "creditsRemaining": {
                            "type": "string",
                            "nullable": true
                          },
                          "expiresAt": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          }
                        },
                        "required": [
                          "id",
                          "status",
                          "at",
                          "txHash",
                          "chainId",
                          "token",
                          "amount",
                          "credits",
                          "tokensPerUsd",
                          "rateSource",
                          "creditsRemaining",
                          "expiresAt"
                        ]
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true
                    }
                  },
                  "required": [
                    "deposits",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad `limit` or `cursor`, or `accountId` for another account, or `all=true`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No credentials, or an invalid, revoked or expired session token or signature.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/balance": {
      "get": {
        "tags": [
          "credits"
        ],
        "summary": "VK-keyed minimal balance read",
        "description": "Project-key (`vk_…`)-keyed minimal balance read for use by downstream meters (e.g. the firehose-payment-gateway preflight, see `probe-firehose.test.ts`). Distinct from `GET /v1/credits` which sits behind session-token auth and also returns the deposit ledger. Same three-value Redis computation: `ceiling + pending - spend`, floored at 0; cold-cache path recomputes `ceiling` from `credit_deposit` rows on the fly.",
        "operationId": "getCreditsBalance",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Effective balance + ceiling.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "creditsAvailable": {
                      "type": "string",
                      "description": "Stringified non-negative integer (credits); never negative."
                    },
                    "ceiling": {
                      "type": "string",
                      "description": "Stringified ceiling: the credits left in paid deposits (paid credits never expire) and in unexpired grants and trials, plus the RPC spend already drawn from them, before pending and spend. creditsAvailable is ceiling + pending - spend."
                    }
                  },
                  "required": [
                    "creditsAvailable",
                    "ceiling"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing or unknown x-api-key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Redis or database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pay/credits/topup": {
      "post": {
        "tags": [
          "credits",
          "x402"
        ],
        "summary": "Top up credits via x402 (alias of POST /v1/credits/topup)",
        "description": "Identical handler, identical request/response shape as `POST /v1/credits/topup`. Lives at this path so customers expecting every x402-credentialed endpoint to share the `/pay` prefix can discover it there. See the `/v1/credits/topup` entry for the full description (recipient allowlist, idempotency keying, error envelope).",
        "operationId": "topupCreditsViaPay",
        "security": [
          {
            "x402": []
          }
        ],
        "parameters": [
          {
            "name": "X-Payment",
            "in": "header",
            "required": true,
            "description": "Base64-encoded x402 PaymentPayload JSON.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "paymentRequirements": {
                    "type": "object",
                    "description": "x402 PaymentRequirements: { asset, network, amount, … }.",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "paymentRequirements"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The credits are granted. A retry of the same `X-Payment` answers from the stored attempt with `status`, `authId` and `creditsGranted` only.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "processing",
                        "settled"
                      ],
                      "description": "`processing` while the settle is in flight; `settled` once the payment settled."
                    },
                    "authId": {
                      "type": "string",
                      "description": "keccak256(chainId, from, nonce) — stable across retries."
                    },
                    "accountId": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Only on the first answer; a retry omits it."
                    },
                    "creditsGranted": {
                      "type": "string",
                      "description": "Stringified bigint, credits added to pending."
                    },
                    "rateTokenPerCredit": {
                      "type": "string",
                      "description": "Token base units per credit, from the quote (audit only). Only on the first answer."
                    }
                  },
                  "required": [
                    "status",
                    "authId",
                    "creditsGranted"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Missing X-Payment or signature, malformed payload, invalid body, a payment that does not match its quote, an amount above the token's hourly limit, or a facilitator envelope refusal.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "402": {
            "description": "No quote or an expired quote, `/verify` rejected the payment (`reason` is a code), or the authorization already failed or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "`authorization.to` is not in the `TOPUP_RECIPIENTS_<chainId>` allowlist.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The authorization is already used with a different signature, or it is final (settled or released) and the ledger refuses it again.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Small top-up window: one small top-up per address per window. `Retry-After` says when.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "The grant failed. Nothing was granted; resend the same `X-Payment`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "502": {
            "description": "The facilitator gave an answer the api cannot read. `Retry-After` is set; resend the same `X-Payment`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The facilitator is down, timed out or unreachable, or a database or Redis call failed (`Retry-After` is set; resend the same `X-Payment`). Also: top-ups are disabled for this chain (`TOPUP_RECIPIENTS_<chainId>` is unset).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/permit2/collect": {
      "post": {
        "tags": [
          "credits",
          "x402"
        ],
        "summary": "Collect a Permit2 signed wrap (x402 onramp into x402<TOKEN>)",
        "description": "Unauthenticated — the Permit2 signature IS the credential. Accepts a payer's Permit2 `PermitTransferFrom` authorizing the x402 wrapper to pull the underlying token into its wrapped form, so the operator can later submit `wrapWithPermit2` gaslessly (operator-timed). Validates: targetWrapper is registered + permit2-capable + non-native, signed cap >= requested amount, deadline in the future, and the signature recovers `owner` against the Permit2 EIP-712 domain (spender bound to the wrapper). Persisted SET NX by (chainId, owner, nonce) — a re-collect of a single-use Permit2 nonce is a replay (409). This is the step BEFORE the EIP-3009/7598 pay; it does not move funds itself.",
        "operationId": "collectPermit2Wrap",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "chainId": {
                    "type": "integer"
                  },
                  "owner": {
                    "type": "string",
                    "description": "Permit signer (the payer)."
                  },
                  "token": {
                    "type": "string",
                    "description": "Underlying ERC-20 being wrapped."
                  },
                  "targetWrapper": {
                    "type": "string",
                    "description": "The x402<TOKEN> wrapper (Permit2 spender)."
                  },
                  "amount": {
                    "type": "string",
                    "description": "Token-wei to wrap (<= permitted)."
                  },
                  "permitted": {
                    "type": "string",
                    "description": "Signed Permit2 cap (token-wei)."
                  },
                  "nonce": {
                    "type": "string",
                    "description": "Permit2 unordered nonce (single-use)."
                  },
                  "deadline": {
                    "type": "integer",
                    "description": "Unix seconds the permit is valid until."
                  },
                  "signature": {
                    "type": "string",
                    "description": "EIP-712 Permit2 signature."
                  }
                },
                "required": [
                  "chainId",
                  "owner",
                  "token",
                  "targetWrapper",
                  "amount",
                  "permitted",
                  "nonce",
                  "deadline",
                  "signature"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Permit collected + persisted pending; operator will time the wrap.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "pending"
                      ]
                    },
                    "owner": {
                      "type": "string"
                    },
                    "targetWrapper": {
                      "type": "string"
                    },
                    "nonce": {
                      "type": "string"
                    },
                    "deadline": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "status",
                    "owner",
                    "targetWrapper",
                    "nonce",
                    "deadline"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Malformed body, unregistered/native/non-permit2 wrapper, amount > permitted cap, expired deadline, or a signature that does not recover the owner.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "Replay — this (chainId, owner, nonce) was already collected (Permit2 nonces are single-use).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/quote": {
      "post": {
        "tags": [
          "credits",
          "x402"
        ],
        "summary": "Quote a credit top-up payable in a specific token (x402 forward quote)",
        "description": "Unauthenticated. The payer asks for a credit grant payable in `asset` on `chainId`; the server resolves the token's current rate (a stable 1:1 with USD, or a live PulseX reserve rate — failing **closed** with 503 on an untrusted/empty price), computes the exact token amount (rounded **up**, never under-charging), and returns an x402 `accepts` envelope bound by a TTL. The quote is persisted server-side keyed by its `nonce`, so the matching `POST /v1/credits/topup` grants the credits **fixed here** and enforces expiry from the stored `validBefore` (a client cannot extend the window). Each accepted token is priced **independently** — this is not a basket. No refunds: price drift inside the TTL is the operator's bounded risk, which is why TTLs are short.",
        "operationId": "quoteCredits",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "chainId": {
                    "type": "integer",
                    "description": "EVM chain id, e.g. 369."
                  },
                  "asset": {
                    "type": "string",
                    "description": "Registered token address the payer signs against (the token itself for EIP-3009-native, or its x402 wrapper)."
                  },
                  "usd": {
                    "type": "number",
                    "description": "Dollar amount to top up. Provide exactly one of `usd` or `credits`."
                  },
                  "credits": {
                    "type": "string",
                    "description": "Credits to buy at the 10^9-per-USD scale (digits only). Provide exactly one of `usd` or `credits`."
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "eip3009",
                      "eip2612",
                      "permit2"
                    ],
                    "description": "How the payer authorises the transfer. Default `eip3009`. `eip2612` and `permit2` need the settler contract and a token that lists the method. Plain USDC, DAI, PLSX and USDT accept only `eip2612` and `permit2`."
                  }
                },
                "required": [
                  "chainId",
                  "asset"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "x402 `accepts` envelope — turn into an EIP-3009 authorization with this `nonce`, `validBefore`, and `value = maxAmountRequired`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "scheme": {
                      "type": "string",
                      "enum": [
                        "exact"
                      ]
                    },
                    "network": {
                      "type": "string",
                      "description": "CAIP-2, e.g. `eip155:369`."
                    },
                    "asset": {
                      "type": "string"
                    },
                    "maxAmountRequired": {
                      "type": "string",
                      "description": "Token-wei to authorize (rounded up)."
                    },
                    "payTo": {
                      "type": "string",
                      "description": "Terminal recipient — no refunds."
                    },
                    "credits": {
                      "type": "string",
                      "description": "Credits granted on settle, fixed at quote time."
                    },
                    "validBefore": {
                      "type": "integer",
                      "description": "Unix seconds; the authorization's validBefore."
                    },
                    "nonce": {
                      "type": "string",
                      "description": "EIP-3009 nonce + quote id; sign with exactly this."
                    },
                    "extra": {
                      "type": "object",
                      "description": "Present for a permit method only: what the payer signs against.",
                      "properties": {
                        "assetTransferMethod": {
                          "type": "string",
                          "enum": [
                            "eip2612",
                            "permit2"
                          ]
                        },
                        "spender": {
                          "type": "string",
                          "description": "The settler contract that spends the permit."
                        },
                        "name": {
                          "type": "string",
                          "description": "The token's EIP-712 domain name."
                        },
                        "version": {
                          "type": "string",
                          "description": "The token's EIP-712 domain version."
                        }
                      }
                    }
                  },
                  "required": [
                    "scheme",
                    "network",
                    "asset",
                    "maxAmountRequired",
                    "payTo",
                    "credits",
                    "validBefore",
                    "nonce"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Malformed body, unknown/unregistered asset for the chain, a method the token does not accept or the facilitator has not enabled, or below `TOPUP_MIN_USD`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Token not quotable (no price config), pricing unavailable (chain unwired / untrusted rate), no treasury configured for the chain, or permit payments unavailable (no settler, or its treasury does not match).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/topup": {
      "post": {
        "tags": [
          "credits",
          "x402"
        ],
        "summary": "Top up credits via x402 (keyless, payment-bearing)",
        "description": "Unauthenticated x402 endpoint — the EIP-3009 `transferWithAuthorization` payload in `X-Payment` is the credential. Every top-up needs a quote from `POST /v1/credits/quote` (the quote applies the minimum and fixes the credits). Flow: validate header and body → check the per-chain `TOPUP_RECIPIENTS_<chainId>` allowlist on `authorization.to` → bind the payment to the stored quote → read the attempt for this authorization → for a small top-up, check the signer and claim its window → facilitator `/verify` (15 s timeout) → spend the hourly budget → grant the credits (account by signer, `pending_auth`, pending credits) in one transaction → facilitator `/settle` (10 s timeout; its answer never changes the response) → 202.\n\n**Retries are safe.** The `authId` is keccak256 over `(chainId, from, nonce)`. The same `X-Payment` again answers the same 202 body from the stored attempt and grants nothing twice: `status` is `processing` until the payment settles, then `settled`. The same authorization with a different signature answers 409.\n\n**Infra errors are never 402.** When the facilitator cannot answer, or a database or Redis call fails, the answer is 503 or 502 with `Retry-After`. Resend the same `X-Payment` after that many seconds. The recipient allowlist is the gate that prevents a caller from self-signing a `(from=me, to=me)` authorization to mint credits at valve's gas expense.",
        "operationId": "topupCredits",
        "security": [
          {
            "x402": []
          }
        ],
        "parameters": [
          {
            "name": "X-Payment",
            "in": "header",
            "required": true,
            "description": "Base64-encoded x402 PaymentPayload JSON.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "paymentRequirements": {
                    "type": "object",
                    "description": "x402 PaymentRequirements: { asset, network, amount, … }.",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "paymentRequirements"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The credits are granted. A retry of the same `X-Payment` answers from the stored attempt with `status`, `authId` and `creditsGranted` only.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "processing",
                        "settled"
                      ],
                      "description": "`processing` while the settle is in flight; `settled` once the payment settled."
                    },
                    "authId": {
                      "type": "string",
                      "description": "keccak256(chainId, from, nonce) — stable across retries."
                    },
                    "accountId": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Only on the first answer; a retry omits it."
                    },
                    "creditsGranted": {
                      "type": "string",
                      "description": "Stringified bigint, credits added to pending."
                    },
                    "rateTokenPerCredit": {
                      "type": "string",
                      "description": "Token base units per credit, from the quote (audit only). Only on the first answer."
                    }
                  },
                  "required": [
                    "status",
                    "authId",
                    "creditsGranted"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Missing X-Payment or signature, malformed payload, invalid body, a payment that does not match its quote, an amount above the token's hourly limit, or a facilitator envelope refusal.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "402": {
            "description": "No quote or an expired quote, `/verify` rejected the payment (`reason` is a code), or the authorization already failed or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "`authorization.to` is not in the `TOPUP_RECIPIENTS_<chainId>` allowlist.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The authorization is already used with a different signature, or it is final (settled or released) and the ledger refuses it again.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Small top-up window: one small top-up per address per window. `Retry-After` says when.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "The grant failed. Nothing was granted; resend the same `X-Payment`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "502": {
            "description": "The facilitator gave an answer the api cannot read. `Retry-After` is set; resend the same `X-Payment`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The facilitator is down, timed out or unreachable, or a database or Redis call failed (`Retry-After` is set; resend the same `X-Payment`). Also: top-ups are disabled for this chain (`TOPUP_RECIPIENTS_<chainId>` is unset).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/refresh/:accountId": {
      "post": {
        "tags": [
          "credits"
        ],
        "summary": "[Admin] Recompute the Redis ceiling for an account",
        "description": "Triggers a refresh of the Redis `ceiling` key from authoritative `credit_deposit` rows. Only the **leader** instance is permitted to SET the ceiling (single-writer rule); follower instances return 503 with a hint to retry against the leader. The leader is whichever api node currently holds the Redis lock taken at boot.",
        "operationId": "refreshCeiling",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ceiling refreshed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "refreshed": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "refreshed"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Follower instance; retry against the leader. The error includes the leader-instance hint in plaintext.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/tokens": {
      "post": {
        "tags": [
          "tokens"
        ],
        "summary": "Issue a fresh session token (vt_…)",
        "description": "Creates a `session_token` row, returning the bearer **once** in plaintext. The api stores only the SHA-256 hash; future requests carry the raw token in `Authorization: Bearer vt_…`. There is no read-back endpoint by design — losing the token means issuing a new one and revoking the old.",
        "operationId": "createSessionToken",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "description": "Human-readable identifier shown in the list endpoint."
                  },
                  "expiresInDays": {
                    "type": "integer",
                    "description": "Lifetime; commonly 30."
                  }
                },
                "required": [
                  "label",
                  "expiresInDays"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Token issued. The plaintext `token` is shown only here; save it.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string",
                      "description": "Bearer of the form `vt_…`. Save now; the api stores only the SHA-256."
                    },
                    "tokenId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "accountId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "token",
                    "tokenId",
                    "accountId",
                    "expiresAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Zod validation failed (see body.error.issues).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "tokens"
        ],
        "summary": "List active (non-revoked) session tokens",
        "description": "Returns metadata only — no plaintext token. Scoped to the caller's account. Includes `lastUsedAt` so the dashboard can show dormant tokens for cleanup.",
        "operationId": "listSessionTokens",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "Array of active token rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "tokenId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "accountId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "label": {
                        "type": "string"
                      },
                      "expiresAt": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "lastUsedAt": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                      },
                      "createdAt": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/tokens/:tokenId": {
      "delete": {
        "tags": [
          "tokens"
        ],
        "summary": "Revoke a session token (soft-delete via `revokedAt`)",
        "description": "Owners can revoke their own tokens. Admins can revoke any token — the `accountId` predicate is dropped from the WHERE clause for admin callers so ops can invalidate a leaked credential without the user being online. Idempotent: revoking an already-revoked token returns 200 (the underlying UPDATE matches 0 rows).",
        "operationId": "revokeSessionToken",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "tokenId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoke acknowledged.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "revoked": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "revoked"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/method-policies": {
      "get": {
        "tags": [
          "method-policies"
        ],
        "summary": "List policies available to the caller",
        "description": "Returns both system presets (e.g. `all`, `read-only`, identified by `isSystem: true`) and the caller's account-owned custom policies. The presets are the same set every account sees; custom policies are scoped to the caller.",
        "operationId": "listMethodPolicies",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "Array of policy rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "policyId": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "name": {
                        "type": "string"
                      },
                      "description": {
                        "type": "string",
                        "nullable": true
                      },
                      "rules": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "description": "JSON-RPC method names allowed by the policy."
                      },
                      "isSystem": {
                        "type": "boolean",
                        "description": "True for built-in presets (account-id null); false for caller-owned customs."
                      },
                      "createdAt": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "updatedAt": {
                        "type": "string",
                        "format": "date-time"
                      }
                    },
                    "required": [
                      "policyId",
                      "name",
                      "rules",
                      "isSystem",
                      "createdAt",
                      "updatedAt"
                    ]
                  }
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "method-policies"
        ],
        "summary": "Create a custom method policy",
        "description": "Creates an account-owned policy. `rules` is a JSON-RPC method name array; the api checks that each entry has the form `+eth_*` or `-debug_traceCall`. It does not check the method name against a list. The policy can subsequently be linked to keys via `POST /v1/keys/:keyId/policies`.",
        "operationId": "createMethodPolicy",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "rules": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "JSON-RPC method names."
                  }
                },
                "required": [
                  "name",
                  "rules"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created policy.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "policyId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string",
                      "nullable": true
                    },
                    "rules": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "JSON-RPC method names allowed by the policy."
                    },
                    "isSystem": {
                      "type": "boolean",
                      "description": "True for built-in presets (account-id null); false for caller-owned customs."
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "policyId",
                    "name",
                    "rules",
                    "isSystem",
                    "createdAt",
                    "updatedAt"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Missing `name`, or `rules` contains entries outside the accepted-method set.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/method-policies/:policyId": {
      "delete": {
        "tags": [
          "method-policies"
        ],
        "summary": "Delete a custom method policy",
        "description": "Removes a caller-owned policy and unlinks it from every key first (so a dangling `key_method_policy` row is impossible), in one transaction. After the commit it republishes every key that was linked to the policy, so the relays stop applying its rules. System presets (`isSystem: true`) cannot be deleted — attempting returns 403.",
        "operationId": "deleteMethodPolicy",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "policyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Policy deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "policyId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "deleted": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "policyId",
                    "name",
                    "deleted"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Policy is a system preset, or not owned by the caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Policy not found.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed, or the policy was deleted but a linked key was not republished (the error says how many; save each linked key again).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/summary": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "Request and credit totals: total + last 24h / 7d / 30d",
        "description": "Returns `requests` (calls received, refused ones included) and `credits` (what was charged, in nano-dollars) over four windows for the caller's keys. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero. Scope rules: default = caller's account; `?accountId=<uuid>` = that account (admin or self); `?all=true` = every account (admin only). Returns zeros if no keys are resolved, and `analyticsDisabled: true` (counters still present, all zero) if every resolved key has opted out of RPC-request logging via `dataRetentionDays: 0` — otherwise a quiet key and an opted-out key would both read as a flat-zero chart. Absent when any resolved key is still recording, even if its own count happens to be zero.",
        "operationId": "analyticsSummary",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "description": "Target account UUID; defaults to caller. Admin or self required.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "Set to `true` to aggregate every account (admin only).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Counters.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "requests": {
                      "type": "object",
                      "nullable": true,
                      "description": "Calls received in each window, including calls the relay refused (a rate limit, a policy, no credits). Null while the rollup is pending.",
                      "properties": {
                        "total": {
                          "type": "integer",
                          "description": "The 90-day retention window."
                        },
                        "last24h": {
                          "type": "integer"
                        },
                        "last7d": {
                          "type": "integer"
                        },
                        "last30d": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "total",
                        "last24h",
                        "last7d",
                        "last30d"
                      ]
                    },
                    "credits": {
                      "type": "object",
                      "nullable": true,
                      "description": "Credits charged in each window: refused calls cost nothing and count 0. A credit is a nano-dollar. Null while the rollup is pending.",
                      "properties": {
                        "total": {
                          "type": "number",
                          "description": "The 90-day retention window."
                        },
                        "last24h": {
                          "type": "number"
                        },
                        "last7d": {
                          "type": "number"
                        },
                        "last30d": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "total",
                        "last24h",
                        "last7d",
                        "last30d"
                      ]
                    },
                    "asOf": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "When the rollup job last rewrote the partial hour. Null before its first full run. An old value means the job has stalled and every figure is stale."
                    },
                    "since": {
                      "type": "object",
                      "description": "Per window: the real start of the data when it is later than the window start, else null. A figure with a non-null `since` covers only the time from that instant.",
                      "properties": {
                        "total": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                        },
                        "last24h": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                        },
                        "last7d": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                        },
                        "last30d": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true,
                          "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                        }
                      }
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "analyticsDisabled": {
                      "type": "boolean",
                      "description": "Present and true only when every key in scope has recording disabled (dataRetentionDays: 0). Never set for a mixed set of keys."
                    }
                  },
                  "required": [
                    "requests",
                    "credits",
                    "asOf"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller asked for `?all=true`, or no access to the target account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/timeseries": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "Time-bucketed request and credit totals",
        "description": "Buckets the hourly rollup by `date_bin(<bucket>, hour, 2000-01-01T00:00Z)` over the selected period. Bucket size is derived from the period: 24h → 1h, 7d → 6h, 30d → 1 day. Returns `{ buckets: [{ time, requests, credits, partial }] }`. `partial` is true for a bucket that holds an hour that has not closed yet. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero. Empty `buckets` if no keys are resolved, and `analyticsDisabled: true` if every resolved key has opted out of RPC-request logging (`dataRetentionDays: 0`) rather than merely having no traffic this period.",
        "operationId": "analyticsTimeseries",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "description": "Target account UUID; defaults to caller. Admin or self required.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "Set to `true` to aggregate every account (admin only).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          },
          {
            "name": "period",
            "in": "query",
            "required": false,
            "description": "Rolling window. Defaults to `24h`.",
            "schema": {
              "type": "string",
              "enum": [
                "24h",
                "7d",
                "30d"
              ]
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "description": "Filter to a single project (caller must own it).",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Time buckets.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "buckets": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "time": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Start of the bucket, ISO 8601 UTC."
                          },
                          "requests": {
                            "type": "integer",
                            "description": "Calls received, including calls the relay refused."
                          },
                          "credits": {
                            "type": "number",
                            "description": "What those calls were charged, in nano-dollars. A refused call counts 0."
                          },
                          "partial": {
                            "type": "boolean",
                            "description": "True when the bucket holds an hour that has not closed. Its figures will still grow."
                          }
                        },
                        "required": [
                          "time",
                          "requests",
                          "credits",
                          "partial"
                        ]
                      }
                    },
                    "since": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "analyticsDisabled": {
                      "type": "boolean",
                      "description": "Present and true only when every key in scope has recording disabled (dataRetentionDays: 0). Never set for a mixed set of keys."
                    }
                  },
                  "required": [
                    "buckets"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller asked for `?all=true`, or no access to the target account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/chains": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "Request and credit totals grouped by chain ID",
        "description": "Groups by chain ID over the selected period, ordered by requests. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero. Useful for finding which chains a customer's traffic actually lands on, and for sizing-conversations. `analyticsDisabled: true` if every resolved key has opted out of RPC-request logging (`dataRetentionDays: 0`) rather than merely having no traffic this period.",
        "operationId": "analyticsChains",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "description": "Target account UUID; defaults to caller. Admin or self required.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "Set to `true` to aggregate every account (admin only).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          },
          {
            "name": "period",
            "in": "query",
            "required": false,
            "description": "Rolling window. Defaults to `24h`.",
            "schema": {
              "type": "string",
              "enum": [
                "24h",
                "7d",
                "30d"
              ]
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "description": "Filter to a single project (caller must own it).",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Chain-keyed counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "chains": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "chainId": {
                            "type": "integer"
                          },
                          "network": {
                            "type": "string",
                            "description": "The CAIP-2 key of `chainId` (`eip155:369`)."
                          },
                          "name": {
                            "type": "string"
                          },
                          "requests": {
                            "type": "integer",
                            "description": "Calls received, including calls the relay refused."
                          },
                          "credits": {
                            "type": "number",
                            "description": "What those calls were charged, in nano-dollars. A refused call counts 0."
                          }
                        },
                        "required": [
                          "chainId",
                          "network",
                          "name",
                          "requests",
                          "credits"
                        ]
                      }
                    },
                    "since": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "analyticsDisabled": {
                      "type": "boolean",
                      "description": "Present and true only when every key in scope has recording disabled (dataRetentionDays: 0). Never set for a mixed set of keys."
                    }
                  },
                  "required": [
                    "chains"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller asked for `?all=true`, or no access to the target account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/methods": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "Top JSON-RPC methods by usage",
        "description": "Groups by JSON-RPC method, ORDER BY requests DESC, limit 1-100 (default 20). Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero. `analyticsDisabled: true` if every resolved key has opted out of RPC-request logging (`dataRetentionDays: 0`) rather than merely having no traffic this period.",
        "operationId": "analyticsMethods",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "description": "Target account UUID; defaults to caller. Admin or self required.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "Set to `true` to aggregate every account (admin only).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          },
          {
            "name": "period",
            "in": "query",
            "required": false,
            "description": "Rolling window. Defaults to `24h`.",
            "schema": {
              "type": "string",
              "enum": [
                "24h",
                "7d",
                "30d"
              ]
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "description": "Filter to a single project (caller must own it).",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Row cap (1-100; default 20).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Method-keyed counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "methods": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "method": {
                            "type": "string"
                          },
                          "requests": {
                            "type": "integer",
                            "description": "Calls received, including calls the relay refused."
                          },
                          "credits": {
                            "type": "number",
                            "description": "What those calls were charged, in nano-dollars. A refused call counts 0."
                          }
                        },
                        "required": [
                          "method",
                          "requests",
                          "credits"
                        ]
                      }
                    },
                    "since": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "analyticsDisabled": {
                      "type": "boolean",
                      "description": "Present and true only when every key in scope has recording disabled (dataRetentionDays: 0). Never set for a mixed set of keys."
                    }
                  },
                  "required": [
                    "methods"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller asked for `?all=true`, or no access to the target account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/chain-methods": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "Top JSON-RPC methods inside each chain",
        "description": "For each chain, the five busiest JSON-RPC methods by name and one `other` count for the rest, ORDER BY chain requests DESC. One read, scoped to the caller's keys. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero. `analyticsDisabled: true` if every resolved key has opted out of RPC-request logging (`dataRetentionDays: 0`) rather than merely having no traffic this period.",
        "operationId": "analyticsChainMethods",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "accountId",
            "in": "query",
            "required": false,
            "description": "Target account UUID; defaults to caller. Admin or self required.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "Set to `true` to aggregate every account (admin only).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          },
          {
            "name": "period",
            "in": "query",
            "required": false,
            "description": "Rolling window. Defaults to `24h`.",
            "schema": {
              "type": "string",
              "enum": [
                "24h",
                "7d",
                "30d"
              ]
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "description": "Filter to a single project (caller must own it).",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Chain-keyed method counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "chains": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "chainId": {
                            "type": "integer"
                          },
                          "network": {
                            "type": "string",
                            "description": "The CAIP-2 key of `chainId` (`eip155:369`)."
                          },
                          "name": {
                            "type": "string"
                          },
                          "requests": {
                            "type": "integer",
                            "description": "All requests on the chain: the named methods plus `other`."
                          },
                          "methods": {
                            "type": "array",
                            "description": "Up to five methods, busiest first.",
                            "items": {
                              "type": "object",
                              "properties": {
                                "method": {
                                  "type": "string"
                                },
                                "requests": {
                                  "type": "integer"
                                },
                                "credits": {
                                  "type": "string",
                                  "description": "Whole credits, cut toward zero, as a decimal string. A credit is a nano-dollar."
                                }
                              },
                              "required": [
                                "method",
                                "requests",
                                "credits"
                              ]
                            }
                          },
                          "other": {
                            "type": "integer",
                            "description": "Requests from every method outside the top five."
                          },
                          "otherCredits": {
                            "type": "string",
                            "description": "Credits charged for those requests, as a decimal string."
                          }
                        },
                        "required": [
                          "chainId",
                          "network",
                          "name",
                          "requests",
                          "methods",
                          "other",
                          "otherCredits"
                        ]
                      }
                    },
                    "since": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "optedOut": {
                      "type": "object",
                      "description": "Present when keys with request logging off had traffic in the window. The breakdown leaves it out: those keys keep no chain or method.",
                      "properties": {
                        "requests": {
                          "type": "integer"
                        },
                        "credits": {
                          "type": "string",
                          "description": "Whole credits, cut toward zero, as a decimal string."
                        }
                      },
                      "required": [
                        "requests",
                        "credits"
                      ]
                    },
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "analyticsDisabled": {
                      "type": "boolean",
                      "description": "Present and true only when every key in scope has recording disabled (dataRetentionDays: 0). Never set for a mixed set of keys."
                    }
                  },
                  "required": [
                    "chains"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller asked for `?all=true`, or no access to the target account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/top-keys": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "[Admin] Top `vk_` keys by usage across the fleet",
        "description": "Global leaderboard of project keys, ordered by requests. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero. Admin-only by design — leaking key IDs across tenants would be a privacy issue. Limit 1-100 (default 20).",
        "operationId": "analyticsTopKeys",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "required": false,
            "description": "Rolling window. Defaults to `24h`.",
            "schema": {
              "type": "string",
              "enum": [
                "24h",
                "7d",
                "30d"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Row cap (1-100; default 20).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "KeyId-keyed counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "keyId": {
                            "type": "string",
                            "format": "uuid",
                            "description": "The project key (`project_key_id`)."
                          },
                          "requests": {
                            "type": "integer",
                            "description": "Calls received, including calls the relay refused."
                          },
                          "credits": {
                            "type": "number",
                            "description": "What those calls were charged, in nano-dollars. A refused call counts 0."
                          }
                        },
                        "required": [
                          "keyId",
                          "requests",
                          "credits"
                        ]
                      }
                    },
                    "since": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    }
                  },
                  "required": [
                    "keys"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/usage": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "The account's usage, split by key, chain or provider",
        "description": "The signed-in account's charged credits in one window, split by `key`, `chain` or `provider`. Each member has requests, credits, per-request cost, share, error rate and the change against the previous window; a provider also has its latency. Bandwidth is its own member. Members past `limit` fold into `other`. `series` is the chart: credits by member in time buckets. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero.\n\n**Rounding.** Credits are floored to whole credits one row at a time, so the members' credits can add up to as much as (rows − 1) credits below the total. **The previous window** has its own real start. When the data starts late, that start moves to the next midnight, and `change` is null when the data does not cover the previous window. `GET /v1/analytics/spend-rate` is at or above this split's total by up to (members − 1) credits. The two are never equal by promise.\n\nThis route reads the signed-in account only. `accountId` for another account and `all=true` answer 400, for an admin too. The body is cached for 60 seconds per account and query (`Cache-Control: private, max-age=60`).",
        "operationId": "analyticsUsage",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "split",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "key",
                "chain",
                "provider"
              ]
            },
            "description": "How to split the usage."
          },
          {
            "name": "period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "24h",
                "7d",
                "30d"
              ]
            },
            "description": "Rolling window. Default `30d`."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            },
            "description": "Members before the rest fold into `other`. Default 10."
          }
        ],
        "responses": {
          "200": {
            "description": "The split, or `{ pending: true }` while the traffic rollup holds nothing yet.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "split": {
                      "type": "string",
                      "enum": [
                        "key",
                        "chain",
                        "provider"
                      ]
                    },
                    "period": {
                      "type": "string",
                      "enum": [
                        "24h",
                        "7d",
                        "30d"
                      ]
                    },
                    "from": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "to": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "previousFrom": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "bucket": {
                      "type": "string",
                      "description": "The chart bucket width, such as `1 hour`."
                    },
                    "since": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "asOf": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "When the rollup job last rewrote the partial hour. Null before its first full run. An old value means the job has stalled and every figure is stale."
                    },
                    "members": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "A key id, a CAIP-2 chain key, a provider id, or `bandwidth`."
                          },
                          "name": {
                            "type": "string"
                          },
                          "note": {
                            "type": "string",
                            "nullable": true,
                            "description": "A key's project name, with \", revoked\" for a revoked key."
                          },
                          "requests": {
                            "type": "string",
                            "nullable": true,
                            "description": "Null for Bandwidth."
                          },
                          "loggedRequests": {
                            "type": "string",
                            "nullable": true
                          },
                          "errors": {
                            "type": "string",
                            "nullable": true
                          },
                          "credits": {
                            "type": "string",
                            "description": "Charged credits, floored."
                          },
                          "perRequest": {
                            "type": "string",
                            "nullable": true
                          },
                          "share": {
                            "type": "string",
                            "nullable": true,
                            "description": "A percent, cut to 2 decimals."
                          },
                          "shareOfRequests": {
                            "type": "string",
                            "nullable": true,
                            "description": "Provider split only."
                          },
                          "errorRate": {
                            "type": "string",
                            "nullable": true
                          },
                          "latencyMs": {
                            "type": "string",
                            "nullable": true,
                            "description": "Provider split only."
                          },
                          "latencySamples": {
                            "type": "string",
                            "nullable": true,
                            "description": "Provider split only."
                          },
                          "previousCredits": {
                            "type": "string",
                            "nullable": true
                          },
                          "previousPerDay": {
                            "type": "string",
                            "nullable": true
                          },
                          "change": {
                            "type": "string",
                            "nullable": true,
                            "description": "A percent, cut to 1 decimal."
                          },
                          "perDay": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "note",
                          "requests",
                          "credits",
                          "perDay"
                        ]
                      }
                    },
                    "other": {
                      "type": "object",
                      "nullable": true,
                      "additionalProperties": true,
                      "description": "The members past `limit`, as one row with a `count`."
                    },
                    "series": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "time": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "partial": {
                            "type": "boolean"
                          },
                          "credits": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "Credits by member id."
                          }
                        },
                        "required": [
                          "time",
                          "partial",
                          "credits"
                        ]
                      }
                    }
                  },
                  "required": [
                    "pending"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Missing or bad `split`, `period` or `limit`, or `accountId` for another account, or `all=true`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No credentials, or an invalid, revoked or expired session token or signature.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/spend-rate": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "The account's spend rate over 24 hours, 7 days and 30 days",
        "description": "The credits the signed-in account spent in each of three windows, and the average credits a day. Spend is the credits charged to the account's keys, revoked keys too, plus bandwidth. A window that starts late carries `since`, and its rate divides by its real length. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero.\n\n**Rounding.** This total is at or above the `GET /v1/analytics/usage` total by up to (members − 1) credits, because the split floors each member and this route floors one sum. The two are never promised equal.\n\nThis route reads the signed-in account only. `accountId` for another account and `all=true` answer 400, for an admin too. The body is cached for 60 seconds per account (`Cache-Control: private, max-age=60`).",
        "operationId": "analyticsSpendRate",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "The three windows, or `{ pending: true }` while the traffic rollup holds nothing yet.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "asOf": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "When the rollup job last rewrote the partial hour. Null before its first full run. An old value means the job has stalled and every figure is stale."
                    },
                    "until": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real end of the data when the rollup job has stalled (its watermark lags the last closed hour by more than one hour), else null. Every window in the response ends at it."
                    },
                    "windows": {
                      "type": "object",
                      "description": "Keyed by `24h`, `7d` and `30d`.",
                      "additionalProperties": {
                        "type": "object",
                        "properties": {
                          "from": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "to": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "since": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true,
                            "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                          },
                          "credits": {
                            "type": "string",
                            "description": "Whole credits spent in the window."
                          },
                          "perDay": {
                            "type": "string",
                            "description": "Credits a day over the real length of the window, cut toward zero."
                          }
                        },
                        "required": [
                          "from",
                          "to",
                          "since",
                          "credits",
                          "perDay"
                        ]
                      }
                    }
                  },
                  "required": [
                    "pending"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`accountId` for another account, or `all=true`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No credentials, or an invalid, revoked or expired session token or signature.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics/keys": {
      "get": {
        "tags": [
          "analytics"
        ],
        "summary": "The account's keys with last use and spend",
        "description": "One row a key of the signed-in account: the key prefix (never the full value), status, the networks it allows (`null` for all), its last use, and requests and credits over 24 hours, 7 days and 30 days. Keys sort by creation time, then id. `cursor` is a key id of the account: the next page starts after it. Read from an hourly rollup, so windows are hour-aligned: a window starts at the top of the hour and can hold up to one hour more than its name. The current hour is PARTIAL — it holds what the rollup job saw at `asOf`. The rollup covers one contiguous range of hours. When a window starts before it, `since` gives the real start; when the rollup job has stalled, `until` gives the real end. While the rollup holds nothing yet, the response carries `pending: true` and no figures — never a zero.\n\nA `projectId`, `keyId` or `cursor` that is not the account's answers 404, the same as one that does not exist. This route reads the signed-in account only. `accountId` for another account and `all=true` answer 400, for an admin too. The body is cached for 60 seconds per account and query (`Cache-Control: private, max-age=60`).",
        "operationId": "analyticsKeys",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "projectId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Only the keys of this project of the account."
          },
          {
            "name": "keyId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Only this one key of the account. A key of another account answers 404."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "`nextCursor` from the previous page: a key id."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            },
            "description": "Keys per page. Default 50."
          }
        ],
        "responses": {
          "200": {
            "description": "The keys, or `{ pending: true }` while the traffic rollup holds nothing yet.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pending": {
                      "type": "boolean",
                      "description": "Present and true only while the rollup holds nothing yet. Figures are then null or empty: usage is not counted yet, which is not the same as zero."
                    },
                    "keys": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          },
                          "prefix": {
                            "type": "string",
                            "description": "The first 7 characters of the key value, then an ellipsis."
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "active",
                              "revoked"
                            ]
                          },
                          "chains": {
                            "type": "array",
                            "nullable": true,
                            "items": {
                              "type": "string"
                            },
                            "description": "CAIP-2 networks the key allows. Null for all chains."
                          },
                          "lastUsed": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          },
                          "lastUsedGrain": {
                            "type": "string",
                            "nullable": true,
                            "enum": [
                              "hour",
                              "day"
                            ]
                          },
                          "windows": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "object",
                              "properties": {
                                "requests": {
                                  "type": "string"
                                },
                                "credits": {
                                  "type": "string"
                                }
                              },
                              "required": [
                                "requests",
                                "credits"
                              ]
                            },
                            "description": "Keyed by `24h`, `7d` and `30d`."
                          },
                          "perDay": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "Credits a day, keyed by `24h`, `7d` and `30d`."
                          },
                          "exposure": {
                            "type": "object",
                            "description": "The facts behind a key exposure warning. Credits are decimal strings.",
                            "properties": {
                              "publicUse": {
                                "type": "boolean",
                                "description": "The key has client scope, or requires neither a secret nor a JWT."
                              },
                              "originRestricted": {
                                "type": "boolean",
                                "description": "The key has a live origin constraint, on the default scope or on any chain."
                              },
                              "dailyLimit": {
                                "type": "boolean",
                                "description": "The key has a per-day request limit or a per-day compute-unit limit."
                              },
                              "lastHourCredits": {
                                "type": "string",
                                "description": "Credits spent in the last full hour."
                              },
                              "avgHourCredits7d": {
                                "type": "string",
                                "description": "Credits an hour over the 7 days before the last full hour, cut to whole credits."
                              },
                              "ageHours": {
                                "type": "integer",
                                "minimum": 0,
                                "description": "Whole hours since the key was made. A spend jump is flagged only for a key at least 24 hours old."
                              }
                            },
                            "required": [
                              "publicUse",
                              "originRestricted",
                              "dailyLimit",
                              "lastHourCredits",
                              "avgHourCredits7d",
                              "ageHours"
                            ]
                          }
                        },
                        "required": [
                          "id",
                          "name",
                          "prefix",
                          "status",
                          "chains",
                          "lastUsed",
                          "lastUsedGrain",
                          "windows",
                          "perDay",
                          "exposure"
                        ]
                      }
                    },
                    "nextCursor": {
                      "type": "string",
                      "nullable": true
                    },
                    "since": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "The real start of the data when it is later than the window start (a new key, a short retention, or coverage that starts late). Null when the data covers the whole window."
                    },
                    "asOf": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true,
                      "description": "When the rollup job last rewrote the partial hour. Null before its first full run. An old value means the job has stalled and every figure is stale."
                    }
                  },
                  "required": [
                    "pending"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad `projectId`, `cursor` or `limit`, or `accountId` for another account, or `all=true`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No credentials, or an invalid, revoked or expired session token or signature.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "The project or the cursor is not one of the account's keys.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/provider/status": {
      "get": {
        "tags": [
          "provider"
        ],
        "summary": "Provider verification + endpoint health, by domain or all",
        "description": "Without `?domain=<host>`: returns every provider registered by the caller. With `?domain=<host>`: returns just the one matching provider. Each row carries the verification status, the resolved endpoint set, and the relay's in-flight sync state for that provider's endpoints.",
        "operationId": "getProviderStatus",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "domain",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Single provider object when `?domain=` is given; array of providers otherwise. (The single/array union is a path-specific quirk inherited from the original surface; a future v2 may split this into two paths.)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "No provider matches the `?domain=` given. With no `?domain=`, a caller with no provider gets 200 and an empty array.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/provider/sync": {
      "get": {
        "tags": [
          "provider"
        ],
        "summary": "Relay config-rollout sync state (eRPC restart cadence)",
        "description": "Inspects the in-memory eRPC sync state: `configHash`, optional `pendingHash`, and the cooldown timer (`nextEligibleAt`, `secondsUntilEligible`) that gates the next eRPC restart. Used by the dashboard to render \"your changes go live in N seconds\".",
        "operationId": "getProviderSync",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "Sync state snapshot.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "unknown",
                        "synced",
                        "pending"
                      ]
                    },
                    "message": {
                      "type": "string"
                    },
                    "lastRestartAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "configHash": {
                      "type": "string"
                    },
                    "pendingHash": {
                      "type": "string",
                      "nullable": true
                    },
                    "nextEligibleAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "secondsUntilEligible": {
                      "type": "integer"
                    },
                    "providerEndpoints": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  },
                  "required": [
                    "status"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Sync state read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/provider/pubkey": {
      "get": {
        "tags": [
          "provider"
        ],
        "summary": "Derive the domain-specific public key (for DNSSEC TXT cfg)",
        "description": "Returns the public key the operator should use to encrypt their provider config before publishing it in their DNSSEC TXT record. The key is derived from a per-row `verificationToken`, a domain-specific HKDF, and a versioned `keyDerivationVersion` (bumping the version is how we roll keys). Requires the provider to be `POST /register`'d first.",
        "operationId": "getProviderPubkey",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "domain",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public key.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "domain": {
                      "type": "string"
                    },
                    "publicKey": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "domain",
                    "publicKey"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`domain` query parameter missing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Provider not registered — call `POST /v1/provider/register` first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "`PROVIDER_CONFIG_KEY` env not set on the api — operator config issue.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/provider/register": {
      "post": {
        "tags": [
          "provider"
        ],
        "summary": "Register a domain (returns the verification token)",
        "description": "Creates the provider row; the returned `verificationToken` is the secret the operator mixes into their HKDF when encrypting their config. Domain format is RFC-1035-ish (lowercase letters/digits, separator dots, no trailing dot). One live row per (account, domain). A pending (unverified) registration blocks no one: several accounts may hold one for a domain, and the first to verify through DNSSEC wins (migration 0086).",
        "operationId": "registerProvider",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "domain": {
                    "type": "string"
                  }
                },
                "required": [
                  "domain"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registered.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "providerId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "domain": {
                      "type": "string"
                    },
                    "verificationToken": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "providerId",
                    "domain",
                    "verificationToken"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`domain` missing or fails the format check.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "This account already holds the domain, or another account holds it verified.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/provider": {
      "delete": {
        "tags": [
          "provider"
        ],
        "summary": "Soft-delete this account's provider for a domain, pending or verified",
        "description": "Deactivates every endpoint under the provider, then soft-deletes the provider row. Another account's row for the domain is untouched. The DNSSEC TXT record stays in place — re-registering the same domain mints a fresh verificationToken; the old TXT is then ignored.",
        "operationId": "deleteProvider",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "domain",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Soft-deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "providerId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "domain": {
                      "type": "string"
                    },
                    "deleted": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "deletedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "providerId",
                    "domain",
                    "deleted"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`domain` query parameter missing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Provider not registered for this account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/provider/verify": {
      "post": {
        "tags": [
          "provider"
        ],
        "summary": "Pull config from DNSSEC TXT, decrypt, probe endpoints, persist",
        "description": "The verification trip: (1) DNSSEC-fetch the `_valve.<domain>` TXT record; (2) decrypt + parse + validate the cfg; (3) probe every endpoint in the config (HTTP/WS); (4) persist the provider row + endpoint rows for the probes that succeeded, and retire every other account's pending registration of the domain. `payout.token` must be on the closed list for `payout.network` (`payoutTokensForChain` in @valve/types: on 369, bridged USDC, DAI, PLSX, USDT); any other token is refused with 422. With no TXT record at all the 422 error is `TXT record not found`. Returns 422 if config validation fails or if every probe fails (with a `details` array of (url, transport, error) tuples for the operator to debug). Partial success (some probes failed) returns 200 with a `failedProbes` field listing the ones that didn't.",
        "operationId": "verifyProvider",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "domain": {
                    "type": "string"
                  }
                },
                "required": [
                  "domain"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Provider verified (partial probe failures are surfaced under `failedProbes`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "`domain` missing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Provider not registered — call `POST /v1/provider/register` first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "Another account holds the domain verified, or an endpoint URL belongs to another provider.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "422": {
            "description": "No TXT record, DNSSEC failed, config validation failed, or every endpoint probe failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "DNSSEC fetch, decrypt, or persistence failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "`PROVIDER_CONFIG_KEY` env not set on the api.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/provider/setup-check": {
      "get": {
        "tags": [
          "provider"
        ],
        "summary": "Live setup progress for a pending provider (owner only)",
        "description": "Runs the verifier's checks (txt, dnssec, decrypt, endpoints) and saves nothing. A result is cached for 60 s per registration; `refresh=1` asks for a fresh run, at most one per 10 s per registration. Another account, a verified provider and an unknown domain all get 404.",
        "operationId": "providerSetupCheck",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "parameters": [
          {
            "name": "domain",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "refresh",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The checks, in verifier order, and whether all pass.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "`domain` query parameter missing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No pending provider for this domain on this account.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "A fresh run within 10 s; see Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "`PROVIDER_CONFIG_KEY` env not set on the api.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/system/health": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "[Admin] Api process health — Postgres + Redis liveness",
        "description": "Pings Postgres (SELECT 1) and Redis (PING) in parallel, captures per-backend latency, and returns an aggregate `status` (`healthy` = both up; `degraded` = one up; `unhealthy` = both down). Always returns 200 — the response body carries the status.",
        "operationId": "systemHealth",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "Health snapshot.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "healthy",
                        "degraded",
                        "unhealthy"
                      ]
                    },
                    "postgres": {
                      "type": "object",
                      "properties": {
                        "connected": {
                          "type": "boolean"
                        },
                        "latencyMs": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "connected",
                        "latencyMs"
                      ]
                    },
                    "redis": {
                      "type": "object",
                      "properties": {
                        "connected": {
                          "type": "boolean"
                        },
                        "latencyMs": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "connected",
                        "latencyMs"
                      ]
                    },
                    "chains": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      },
                      "description": "Reserved; currently always empty."
                    },
                    "uptime": {
                      "type": "integer",
                      "description": "Seconds since the api process started."
                    }
                  },
                  "required": [
                    "status",
                    "postgres",
                    "redis",
                    "uptime"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/system/chains": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "[Admin] Canonical chain registry (the file the gateway routes from)",
        "description": "Returns the parsed contents of `config/chains.json` — the same data structure the relay loads at boot and the root manifest derives from. Mostly useful for debugging the operator-side question \"did my chain edit actually land in this api's view?\" against a deployed instance.",
        "operationId": "systemChains",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "Chain registry array.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "chainId": {
                        "type": "integer",
                        "description": "The EVM chain id, read from `network`."
                      },
                      "network": {
                        "type": "string",
                        "description": "The CAIP-2 network key (`eip155:369`)."
                      },
                      "name": {
                        "type": "string"
                      },
                      "architecture": {
                        "type": "string"
                      },
                      "testnet": {
                        "type": "boolean"
                      }
                    },
                    "required": [
                      "chainId",
                      "network",
                      "name",
                      "architecture",
                      "testnet"
                    ]
                  }
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Failed to read chains.json from disk.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/system/sync": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "[Admin] Relay sync snapshot proxy",
        "description": "Proxies the relay's own `/health` over loopback (5 s timeout). On any failure — transient relay restart, network blip, timeout — returns a degraded snapshot `{ lastSyncAt: null, configHash: null, providerCount: 0, endpointCount: 0 }` so the dashboard renders something instead of a spinner.",
        "operationId": "systemSync",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "Relay snapshot (degraded shape on failure — fields will be null/zero).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/system/pending-providers": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "[Admin] Providers that registered and never verified",
        "description": "Oldest first, at most 100, each with its age and the setup checks of `GET /v1/provider/setup-check` (same 60 s cache and 10 s limit per registration). Saves nothing. A row whose check is rate-limited has `checks: null`; with no `PROVIDER_CONFIG_KEY` every row has `serverNotConfigured: true`. Several accounts may hold a pending row for one domain (migration 0086).",
        "operationId": "systemPendingProviders",
        "security": [
          {
            "sessionToken": []
          },
          {
            "walletAccessUntil": [],
            "walletAccessSignature": []
          }
        ],
        "responses": {
          "200": {
            "description": "Pending providers.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          },
          "403": {
            "description": "Non-admin caller.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Listing failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/methods": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "List common JSON-RPC methods",
        "description": "Returns the common JSON-RPC method names. The key editor uses this list for its method picker. It is not the full list: the gateway also accepts methods that are not here, such as `msgboard_*` and more `ots_*` methods.",
        "operationId": "listMethods",
        "responses": {
          "200": {
            "description": "Array of method-name strings.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "example": [
                    "eth_chainId",
                    "eth_blockNumber",
                    "debug_traceTransaction"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/stats": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "Public gateway counters",
        "description": "Public stats for landing-page consumption. Exposes a trailing-24h request counter and a current requests-per-second rate, both derived from per-minute Redis buckets. 10-second in-process cache. Both fields are `null` on a degraded read (instead of 5xx) so consumers can render a placeholder.",
        "operationId": "getStats",
        "responses": {
          "200": {
            "description": "Counters; values may be `null` if the read was degraded.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "requestsToday": {
                      "type": "integer",
                      "nullable": true,
                      "description": "Requests in the trailing 24 hours; `null` on read failure."
                    },
                    "requestsPerSecond": {
                      "type": "number",
                      "nullable": true,
                      "description": "Current requests/sec, averaged over the trailing 5 complete minutes; `null` on read failure."
                    }
                  },
                  "required": [
                    "requestsToday",
                    "requestsPerSecond"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/llms.txt": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "The llms.txt index of valve.city",
        "description": "The plain-text index for LLMs (the llmstxt.org convention): the products, the docs, the live chains and the payment links. The api builds the chain text from the same rows as `GET /v1/networks`, so a chain that goes live shows here with no web build. Cached for 300 seconds.",
        "operationId": "getLlmsTxt",
        "responses": {
          "200": {
            "description": "The index as Markdown text.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/llms-full.txt": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "The llms.txt index with the full implementation guide",
        "description": "The llms.txt index, then the quick start, the supported chains, the auth schemes, the REST endpoints and the guide part of this API reference, in one plain-text file. It holds no key, not even the public demo key. Cached for 300 seconds.",
        "operationId": "getLlmsFullTxt",
        "responses": {
          "200": {
            "description": "The full text as Markdown.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/networks": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "The live networks, and who serves each",
        "description": "Public, no auth. Every network open to all keys, EVM and non-EVM, in file order. A staged network is not listed. `servedBy` is \"Served by Valve nodes\", \"Public providers; paid keys also fall back to a paid provider\", \"Public providers\", or \"Paid keys only\". It names no paid provider.",
        "operationId": "listLiveNetworks",
        "responses": {
          "200": {
            "description": "The live networks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "networks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "network": {
                            "type": "string",
                            "description": "CAIP-2 key, such as `eip155:369`."
                          },
                          "chainId": {
                            "type": "integer",
                            "nullable": true,
                            "description": "The EVM chain id, or null for a non-EVM network."
                          },
                          "name": {
                            "type": "string"
                          },
                          "testnet": {
                            "type": "boolean"
                          },
                          "servedBy": {
                            "type": "string"
                          },
                          "slug": {
                            "type": "string",
                            "description": "The name in kebab case, such as `op-mainnet`."
                          },
                          "nativeCurrency": {
                            "type": "object",
                            "nullable": true,
                            "properties": {
                              "name": {
                                "type": "string"
                              },
                              "symbol": {
                                "type": "string"
                              },
                              "decimals": {
                                "type": "integer"
                              }
                            },
                            "required": [
                              "name",
                              "symbol",
                              "decimals"
                            ]
                          },
                          "explorer": {
                            "type": "object",
                            "nullable": true,
                            "properties": {
                              "name": {
                                "type": "string"
                              },
                              "url": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "name",
                              "url"
                            ]
                          },
                          "iconUrl": {
                            "type": "string",
                            "nullable": true,
                            "description": "`https://gib.show/image/<chainId>`, or null for a non-EVM network."
                          },
                          "ownNode": {
                            "type": "boolean",
                            "description": "Valve runs nodes for the network."
                          },
                          "webSocket": {
                            "type": "boolean",
                            "description": "The relay serves WebSocket on the network."
                          },
                          "walletRpcUrl": {
                            "type": "string",
                            "nullable": true
                          },
                          "snapshot": {
                            "type": "object",
                            "nullable": true,
                            "properties": {
                              "rethChain": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "rethChain"
                            ]
                          },
                          "substreams": {
                            "type": "object",
                            "nullable": true,
                            "properties": {
                              "endpoint": {
                                "type": "string"
                              }
                            },
                            "required": [
                              "endpoint"
                            ]
                          },
                          "pricing": {
                            "type": "object",
                            "properties": {
                              "baseCredits": {
                                "type": "object",
                                "additionalProperties": {
                                  "type": "integer"
                                },
                                "description": "The methods whose base price differs from the fallback price."
                              },
                              "rangeCreditsPerKblock": {
                                "type": "integer"
                              },
                              "paidCaps": {
                                "type": "object",
                                "additionalProperties": {
                                  "type": "integer"
                                },
                                "description": "The paid cap of each method that has one."
                              }
                            },
                            "required": [
                              "baseCredits",
                              "rangeCreditsPerKblock",
                              "paidCaps"
                            ]
                          }
                        },
                        "required": [
                          "network",
                          "chainId",
                          "name",
                          "testnet",
                          "servedBy",
                          "slug",
                          "nativeCurrency",
                          "explorer",
                          "iconUrl",
                          "ownNode",
                          "webSocket",
                          "walletRpcUrl",
                          "snapshot",
                          "substreams",
                          "pricing"
                        ]
                      }
                    },
                    "fallbackCredits": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "integer",
                        "minimum": 0
                      },
                      "description": "The price in credits of each priced method on a chain whose row has no `pricing.baseCredits` entry and no `pricing.paidCaps` entry for it."
                    }
                  },
                  "required": [
                    "networks",
                    "fallbackCredits"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/health/networks": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "Per-chain health (REST proxy for /ws/health)",
        "description": "REST fallback for callers that cannot maintain a WebSocket. Returns the relay's current view of per-chain upstream health. Proxied from `relay:/health`; returns 502 if the relay is unreachable.",
        "operationId": "getNetworkHealth",
        "responses": {
          "200": {
            "description": "Health snapshot keyed by chain.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "502": {
            "description": "Relay unreachable; transient.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/passthrough": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "Requests served by public RPC providers and by our own nodes, by day",
        "description": "Public, no auth. For each closed UTC day: the requests served by public RPC providers, paid fallbacks, our own nodes, the cache and unattributed upstreams. Aggregates only: the response names no provider and holds no claim state, credit or dollar figure. A provider reads its own rows, with what it earned, on the signed `GET /v1/provider/status`. No account, project, key, method or payout address is in the response. Cached for 5 minutes.",
        "operationId": "getPassthrough",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 365
            },
            "description": "How many closed days to return, ending yesterday (UTC). Default 30."
          }
        ],
        "responses": {
          "200": {
            "description": "Request counts by class for each closed day.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "since": {
                      "type": "string",
                      "nullable": true,
                      "description": "First day with a passthrough row (YYYY-MM-DD)."
                    },
                    "latestClosedDay": {
                      "type": "string",
                      "nullable": true,
                      "description": "The last day that is snapshotted. If it is before yesterday (UTC), the days after it are not yet computed and are absent from `days`."
                    },
                    "shareBps": {
                      "type": "integer",
                      "description": "The policy share a public provider earns of the paid value we pass to it, in basis points."
                    },
                    "days": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "day": {
                            "type": "string",
                            "description": "A UTC day, YYYY-MM-DD."
                          },
                          "status": {
                            "type": "string",
                            "description": "The state of the day's payout snapshot."
                          },
                          "requests": {
                            "type": "object",
                            "description": "Requests the day served, by class. Counts only.",
                            "properties": {
                              "public": {
                                "type": "integer",
                                "description": "Served by public RPC providers, all providers together."
                              },
                              "paid": {
                                "type": "integer",
                                "description": "Served by paid fallback providers."
                              },
                              "own": {
                                "type": "integer",
                                "description": "Served by our own nodes."
                              },
                              "cache": {
                                "type": "integer",
                                "description": "Served from the cache."
                              },
                              "unattributed": {
                                "type": "integer",
                                "description": "Served by an upstream we could not attribute."
                              }
                            },
                            "required": [
                              "public",
                              "paid",
                              "own",
                              "cache",
                              "unattributed"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "day",
                          "status",
                          "requests"
                        ],
                        "additionalProperties": false
                      }
                    }
                  },
                  "required": [
                    "since",
                    "latestClosedDay",
                    "shareBps",
                    "days"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "`days` is not a whole number from 1 to 365.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Database read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/capabilities": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "Valve verified capabilities for a chain",
        "description": "Returns the capabilities Valve verifies on its own endpoint for a chain (archive depth, trace/debug methods, logs, filters, otterscan, txpool, msgboard, batch). Backs the learn.valve.city/rpc spec sheet. A background job probes only valve.city endpoints every ~10 minutes and shares one copy per chain; a request only reads it and never causes a probe. Success sends `Cache-Control: public, max-age=600, stale-while-revalidate=3600`. Before the first copy exists the answer is 503 with `ready: false` and `Cache-Control: no-store`.",
        "operationId": "getCapabilities",
        "parameters": [
          {
            "name": "chainId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "enum": [
                1,
                369,
                943,
                11155111,
                8453,
                42161,
                10,
                137,
                56,
                43114,
                4663,
                146,
                99901
              ]
            },
            "description": "Chain to probe. One of 1, 369, 943, 11155111, 8453, 42161, 10, 137, 56, 43114, 4663, 146, 99901. Testnets are included."
          }
        ],
        "responses": {
          "200": {
            "description": "Valve capabilities for the chain.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "chainId": {
                      "type": "integer"
                    },
                    "network": {
                      "type": "string",
                      "description": "The CAIP-2 key of `chainId` (`eip155:369`)."
                    },
                    "capabilityKeys": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Ordered capability column keys, as rendered by the learn page."
                    },
                    "endpoints": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      },
                      "description": "Per-endpoint probe results (reachable/unsupported/inconclusive per capability), each tagged with its source (valve)."
                    }
                  },
                  "required": [
                    "chainId",
                    "network",
                    "capabilityKeys",
                    "endpoints"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`chainId` missing or not one of 1, 369, 943, 11155111, 8453, 42161, 10, 137, 56, 43114, 4663, 146, 99901.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "No copy exists yet (the background job has not finished its first round). Retry shortly.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/capabilities/check": {
      "post": {
        "tags": [
          "system"
        ],
        "summary": "Probe one user-supplied RPC endpoint",
        "description": "Runs the same capability probe against a single caller-provided URL — the \"check your own node\" flow on learn.valve.city/rpc. The URL is SSRF-guarded: only publicly-routable http(s) endpoints are accepted. The URL may hold a private key, so the server never logs or stores it, and only a caller who submits the same URL gets the result. The server stores the result under a salted hash of the URL for 10 minutes. A repeat check in that time returns the stored result with its `checkedAt` time and makes no probe. A new probe is limited to 5 per 10 seconds per client and 10 per second across all clients; a refusal is 429 with `Retry-After`.",
        "operationId": "checkCapabilities",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "The RPC endpoint to probe."
                  },
                  "chainId": {
                    "type": "integer",
                    "description": "Chain the endpoint is expected to serve."
                  }
                },
                "required": [
                  "url",
                  "chainId"
                ]
              },
              "example": {
                "url": "https://rpc.example.org",
                "chainId": 369
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Probe result for the endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "chainId": {
                      "type": "integer"
                    },
                    "network": {
                      "type": "string",
                      "description": "The CAIP-2 key of `chainId` (`eip155:369`)."
                    },
                    "capabilityKeys": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "endpoint": {
                      "type": "object",
                      "additionalProperties": true,
                      "description": "Per-capability probe result, source: \"user\", with the `checkedAt` time of the probe."
                    }
                  },
                  "required": [
                    "chainId",
                    "network",
                    "capabilityKeys",
                    "endpoint"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Missing/invalid `url` or `chainId`, or the URL failed the SSRF guard.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached. Retry after the `Retry-After` seconds.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/substreams/endpoints": {
      "get": {
        "tags": [
          "substreams"
        ],
        "summary": "List substreams gRPC endpoints",
        "description": "Returns per-chain substreams gRPC gateway endpoints, with availability + advertised block features. Endpoints expose `sf.substreams.rpc.v2.Stream/Blocks` (substreams) and `sf.firehose.v2.Stream/Blocks` (raw firehose) on the same hostname; the meter byte-counts both into `firehose.stream` pricing (see GET /v1/substreams/pricing). Auth is via the standard vk_… bearer in gRPC metadata — same key as /rpc. `available: false` rows are reserved/queued — pricing exists but the box is not yet serving.",
        "operationId": "listSubstreamsEndpoints",
        "responses": {
          "200": {
            "description": "Substreams endpoint registry.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "endpoints": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "chainId": {
                            "type": "integer",
                            "example": 943
                          },
                          "network": {
                            "type": "string",
                            "example": "eip155:943",
                            "description": "The CAIP-2 key of `chainId`."
                          },
                          "endpoint": {
                            "type": "string",
                            "example": "evm-943-substreams.valve.city:443"
                          },
                          "protocol": {
                            "type": "string",
                            "enum": [
                              "grpc+tls"
                            ]
                          },
                          "available": {
                            "type": "boolean"
                          },
                          "blockFeatures": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "example": [
                              "extended",
                              "balance_changes",
                              "storage_changes",
                              "code_changes",
                              "nonce_changes"
                            ]
                          }
                        },
                        "required": [
                          "chainId",
                          "network",
                          "endpoint",
                          "protocol",
                          "available",
                          "blockFeatures"
                        ]
                      }
                    },
                    "notes": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "endpoints",
                    "notes"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/substreams/pricing": {
      "get": {
        "tags": [
          "substreams"
        ],
        "summary": "Per-byte streaming rate, per chain",
        "description": "Returns the live `shared.method_pricing` rows for substreams + firehose. `creditsPerByte` is the fractional rate (Postgres numeric, returned as a string for precision); `usdPerGb` is a JavaScript number convenience — 1 USD = 1e9 credits, 1 GB = 1e9 bytes, so the two are numerically equal. Rates can change at any time; call this before quoting downstream. Debits land in `api.bandwidth_debit` grouped by streamId.",
        "operationId": "getSubstreamsPricing",
        "responses": {
          "200": {
            "description": "Per-chain pricing rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pricing": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "chainId": {
                            "type": "integer",
                            "example": 943
                          },
                          "network": {
                            "type": "string",
                            "example": "eip155:943",
                            "description": "The CAIP-2 key of `chainId`, or `*` for the default row (chain 0)."
                          },
                          "method": {
                            "type": "string",
                            "example": "firehose.stream"
                          },
                          "unit": {
                            "type": "string",
                            "enum": [
                              "byte",
                              "request"
                            ]
                          },
                          "creditsPerByte": {
                            "type": "string",
                            "nullable": true,
                            "description": "Postgres numeric as string; null for non-byte-priced rows.",
                            "example": "0.500000000000000000"
                          },
                          "usdPerGb": {
                            "type": "number",
                            "nullable": true,
                            "example": 0.5
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        },
                        "required": [
                          "chainId",
                          "network",
                          "method",
                          "unit",
                          "creditsPerByte",
                          "usdPerGb",
                          "updatedAt"
                        ]
                      }
                    },
                    "notes": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "pricing",
                    "notes"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Failed to read pricing from the database.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pay/supported": {
      "get": {
        "tags": [
          "x402"
        ],
        "summary": "List the chain/token/network triples this facilitator accepts",
        "description": "Returns one `kinds[]` array. Each entry advertises a (x402Version, scheme, network, tokens) tuple. The facilitator emits per-chain entries in BOTH shapes the ecosystem speaks: `x402Version: 2` + CAIP-2 `network` (canonical post-1.2 SDK), and `x402Version: 1` + named alias (V1-shaped clients). Clients filter on whichever pair their generation knows; unknown shapes are silently ignored. `scheme` is always `\"exact\"` — only EIP-3009 `transferWithAuthorization` is supported on this facilitator. The `extra.tokens` array carries the per-chain wrapper-token registry (symbol, address, decimals); use this to learn which ERC-20 the facilitator will accept for that chain.",
        "operationId": "paySupported",
        "responses": {
          "200": {
            "description": "Per-chain supported kinds.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "kinds": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "x402Version": {
                            "type": "integer",
                            "enum": [
                              1,
                              2
                            ],
                            "description": "1 (named-network shape) or 2 (CAIP-2 shape)."
                          },
                          "scheme": {
                            "type": "string",
                            "enum": [
                              "exact"
                            ],
                            "description": "Always `\"exact\"` — EIP-3009 only."
                          },
                          "network": {
                            "type": "string",
                            "description": "CAIP-2 (eip155:1) or named alias (mainnet, pulsechain) per the x402Version."
                          },
                          "extra": {
                            "type": "object",
                            "properties": {
                              "settlementModel": {
                                "type": "string",
                                "enum": [
                                  "async-batched",
                                  "sync"
                                ],
                                "description": "Whether /settle enqueues (async-batched) or blocks until on-chain (sync)."
                              },
                              "maxSettleLatencyMs": {
                                "type": "integer",
                                "description": "Upper bound the operator commits to from /settle enqueue to on-chain inclusion."
                              },
                              "tokens": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "symbol": {
                                      "type": "string",
                                      "description": "Project-friendly symbol (PRVX, wPLSX, …)."
                                    },
                                    "address": {
                                      "type": "string",
                                      "description": "0x-checksummed ERC-20 address on this chain."
                                    },
                                    "decimals": {
                                      "type": "integer"
                                    }
                                  },
                                  "required": [
                                    "symbol",
                                    "address",
                                    "decimals"
                                  ]
                                }
                              }
                            },
                            "required": [
                              "settlementModel",
                              "maxSettleLatencyMs",
                              "tokens"
                            ]
                          }
                        },
                        "required": [
                          "x402Version",
                          "scheme",
                          "network",
                          "extra"
                        ]
                      }
                    }
                  },
                  "required": [
                    "kinds"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pay/verify": {
      "post": {
        "tags": [
          "x402"
        ],
        "summary": "Pre-flight verify an EIP-3009 authorization (no on-chain action)",
        "description": "Validates a `transferWithAuthorization` payload BEFORE the caller decides to /settle. Recovers the signer from the EIP-712 signature, checks balance + nonce + circuit + per-signer cap, and returns either `{isValid: true, payer, network}` or `{isValid: false, invalidReason}`. Successful verify reserves the nonce (so a follow-up /settle for the same authorization is idempotent).\n\nStatus-code conventions:\n- `200` + `{isValid: true}` — payment is valid; safe to /settle.\n- `200` + `{isValid: false, invalidReason}` — envelope parsed; payment invalid for a canonical reason (SDK clients dispatch on `invalidReason`).\n- `400` — envelope unparseable (no canonical code).\n- `402` — per-signer unsettled cap reached; retry after the in-flight settles land.\n- `503` — circuit breaker open; respect `Retry-After`.\n- `500` — unexpected internal failure (canonical code `unexpected_verify_error`).",
        "operationId": "payVerify",
        "security": [
          {
            "x402": []
          }
        ],
        "requestBody": {
          "required": true,
          "description": "x402 verify request: `{x402Version, paymentPayload, paymentRequirements}`. Both flat and SDK-nested `paymentPayload.payload.authorization` shapes are accepted.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "x402Version": {
                    "type": "integer",
                    "enum": [
                      1,
                      2
                    ]
                  },
                  "paymentPayload": {
                    "type": "object",
                    "description": "EIP-3009 authorization + signature.",
                    "additionalProperties": true
                  },
                  "paymentRequirements": {
                    "type": "object",
                    "description": "{ asset, network, …}.",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "paymentPayload",
                  "paymentRequirements"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verify decision (valid OR canonical-invalid).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "isValid": {
                      "type": "boolean"
                    },
                    "payer": {
                      "type": "string",
                      "description": "Recovered signer address; present on `isValid: true`."
                    },
                    "network": {
                      "type": "string",
                      "description": "Echo of the request `network` (or canonical alias)."
                    },
                    "invalidReason": {
                      "type": "string",
                      "description": "Canonical x402 invalid code; present on `isValid: false`."
                    },
                    "invalidReasonMessage": {
                      "type": "string",
                      "description": "Human-readable elaboration of `invalidReason`."
                    }
                  },
                  "required": [
                    "isValid"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Envelope unparseable (missing/wrong-typed fields, no canonical code).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "402": {
            "description": "Per-signer unsettled cap reached; retry after settle drains.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Unexpected internal failure (canonical code `unexpected_verify_error`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Circuit breaker open for this chain/token; honor `Retry-After`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pay/settle": {
      "post": {
        "tags": [
          "x402"
        ],
        "summary": "Enqueue settle of an already-verified EIP-3009 authorization",
        "description": "Accepts the same envelope as /verify and enqueues an on-chain `transferWithAuthorization` call. Settlement is async-batched in the current deployment: the response returns `transaction: null` and the caller polls `GET /pay/settle/{authId}` until `txHash` populates (typical < 30s on PulseChain).\n\nThe `authId` returned in the GET shape is `keccak256(chainId, from, nonce)` — deterministic, so a duplicate /settle for an already-enqueued authorization is idempotent against the queue.\n\nStatus-code conventions parallel /verify: `200` + `{success: true|false, errorReason}`; `400` for truly malformed envelopes; `500` for internal throws.",
        "operationId": "paySettle",
        "security": [
          {
            "x402": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "x402Version": {
                    "type": "integer",
                    "enum": [
                      1,
                      2
                    ]
                  },
                  "paymentPayload": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "paymentRequirements": {
                    "type": "object",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "paymentPayload",
                  "paymentRequirements"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Settle enqueue decision.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "transaction": {
                      "type": "string",
                      "nullable": true,
                      "description": "On-chain tx hash (sync mode) or `null` (async-batched)."
                    },
                    "network": {
                      "type": "string"
                    },
                    "payer": {
                      "type": "string"
                    },
                    "errorReason": {
                      "type": "string",
                      "description": "Canonical x402 settle code on `success: false`."
                    },
                    "errorReasonMessage": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "success"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Envelope missing fields or unparseable.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Unexpected internal failure (canonical code `unexpected_settle_error`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pay/settle/{authId}": {
      "get": {
        "tags": [
          "x402"
        ],
        "summary": "Look up the on-chain status of a previously enqueued settle",
        "description": "Poll target for the async-batched settle mode. Returns the on-chain tx hash once the settle lands, or a canonical `errorCode` (mapped via `toCanonicalSettleCode`) if the on-chain call reverted. The `canonicalErrorCode` field is the x402-vocabulary synonym of the internal `errorCode` — clients should dispatch on `canonicalErrorCode`; the raw `errorCode` is kept for ops queries.",
        "operationId": "paySettleStatus",
        "parameters": [
          {
            "name": "authId",
            "in": "path",
            "required": true,
            "description": "`keccak256(chainId, from, nonce)` — returned by /settle and stable across retries.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Settlement record.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "txHash": {
                      "type": "string",
                      "nullable": true,
                      "description": "`null` until the on-chain call confirms."
                    },
                    "settledAt": {
                      "type": "string",
                      "format": "date-time",
                      "description": "When the worker enqueued the on-chain call (NOT block timestamp)."
                    },
                    "errorCode": {
                      "type": "string",
                      "nullable": true,
                      "description": "Internal error vocabulary; null on success."
                    },
                    "canonicalErrorCode": {
                      "type": "string",
                      "nullable": true,
                      "description": "x402-canonical synonym of `errorCode` — clients dispatch on this."
                    }
                  },
                  "required": [
                    "settledAt"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No settlement found for this authId (never enqueued, or recently purged).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          },
          "500": {
            "description": "Lookup failed (canonical code `unexpected_settle_error`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pay/health": {
      "get": {
        "tags": [
          "x402"
        ],
        "summary": "Per-chain operator health (gas balance, settle backlog, circuit state)",
        "description": "Operator-facing summary intended for status pages and monitoring rather than integrators. Each `chains[]` entry reports the settle-key gas balance (wei), the unsettled backlog count + oldest- admitted-age, the per-chain circuit breaker state, and the (blockNumber, at) of the most recent successful settle. Keyless — same reachability constraints as the rest of /pay.",
        "operationId": "payHealth",
        "responses": {
          "200": {
            "description": "Per-chain health.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "chains": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "chainId": {
                            "type": "integer"
                          },
                          "settleKeyGasBalanceWei": {
                            "type": "string",
                            "description": "Stringified wei balance of the per-chain settle signing key."
                          },
                          "unsettledBacklog": {
                            "type": "object",
                            "properties": {
                              "count": {
                                "type": "integer"
                              },
                              "oldestAdmittedAgeSec": {
                                "type": "integer",
                                "description": "Age (in seconds) of the oldest admitted-but-unsettled item."
                              }
                            },
                            "required": [
                              "count",
                              "oldestAdmittedAgeSec"
                            ]
                          },
                          "circuitBreaker": {
                            "type": "object",
                            "properties": {
                              "state": {
                                "type": "string",
                                "enum": [
                                  "closed",
                                  "open"
                                ]
                              }
                            },
                            "required": [
                              "state"
                            ]
                          },
                          "lastSettleBlockNumber": {
                            "type": "integer",
                            "nullable": true
                          },
                          "lastSettleAt": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          }
                        },
                        "required": [
                          "chainId",
                          "settleKeyGasBalanceWei",
                          "unsettledBacklog",
                          "circuitBreaker"
                        ]
                      }
                    }
                  },
                  "required": [
                    "chains"
                  ]
                }
              }
            }
          }
        }
      }
    }
  }
}