
x402Router
OpenRouter-compatible AI inference gateway where humans and agents pay per call using x402.
Demo
About
x402Router is an OpenRouter-compatible AI inference gateway for agents and humans who do not want accounts, API keys, or monthly plans. You connect a Hedera wallet, authorize a session once, and inference calls are paid directly from that wallet. The wallet address becomes the identity, while models and sessions are represented as ENSv2 names inside the gateway. The gateway routes Claude and Gemini through one OpenAI-compatible API, so OpenCode, Cursor, and existing SDKs can work without changes. The model catalogue is not hardcoded in the source. Every model is an ENSv2 name. For example, `claude-opus-5.router402.eth` stores its price, context window, upstream model ID, settlement terms, and endpoint as text records in a Permissioned Resolver. The gateway resolves these records at runtime. Changing a price therefore becomes an on-chain transaction instead of a deployment, and registering an agent becomes a registry operation instead of a pull request. Every inference request is priced before it runs. The gateway token-counts the prompt and calculates a quote for the prompt plus a bounded completion using the published model rate and a small margin. The upstream request is then capped at exactly the budget that was authorized. This means callers are never charged for tokens they did not authorize and do not get unexpected overages. Reasoning models are handled separately because thinking and output cannot always share the same limit. In one test, a 256-token budget resulted in 245 tokens being spent on reasoning and only 7 tokens reaching the final answer. x402Router therefore quotes the thinking allowance separately and accounts for it explicitly. The quoted price comes directly from the ENS record, and the HTTP 402 response identifies the record used for the quote, allowing the caller to verify the price against the registry instead of blindly trusting the gateway. Payments are handled through x402. An unpaid request returns HTTP 402 with the payment requirements and a complete quote breakdown. The client signs a Hedera transfer using its session key and retries the request. Blocky402 verifies and settles the payment on Hedera before the gateway returns the inference result. A session is also a name. Opening a session registers a name such as `s7fj2k.keys.router402.eth` in our hierarchical ENSv2 registry. The registry stores the owner and expiry and provides on-chain revocation through `unregister()`. Revocation is therefore a public, ordered fact that can be checked independently of the gateway database. Session names are deliberately non-transferable. The session owner receives `ROLE_UNREGISTER`, but not `ROLE_CAN_TRANSFER_ADMIN` or `ROLE_RENEW`. A session key therefore cannot transfer the session to another party or extend its own lifetime. For ECDSA-backed Hedera accounts, the ENS name is registered to the account's EVM alias, allowing the caller to revoke the session on Sepolia without connecting a separate Ethereum wallet. Every request checks the registry rather than relying only on a database row. Each settlement is published to a public Hedera Consensus Service topic, creating a tamper-evident payment history that can be independently verified. The demo supports settlement in HBAR and HTS tokens with a custom fee schedule. The service is also exposed through an x402 Bazaar listing, `/.well-known/agent.json`, and `/v1/discovery`, with each agent's ENS name included so other agents can discover and call the service programmatically. For harnesses that cannot sign x402 payments themselves, x402Router provides an encrypted and revocable access URL that allows an agent to pay automatically within the limits of its session. This is intentionally restricted to testnet. The core design is simple: ENS provides the naming, discovery, identity, and policy layer, while Hedera provides the payment and settlement layer.
How it's made
x402Router is an OpenRouter-compatible AI inference gateway for agents and humans who do not want accounts, API keys, or monthly plans. You connect a Hedera wallet, authorize a session once, and inference calls are paid directly from that wallet. The wallet address becomes the identity, while models and sessions are represented as ENSv2 names inside the gateway. The gateway routes Claude and Gemini through one OpenAI-compatible API, so OpenCode, Cursor, and existing SDKs can work without changes. The model catalogue is not hardcoded in the source. Every model is an ENSv2 name. For example, `claude-opus-5.router402.eth` stores its price, context window, upstream model ID, settlement terms, and endpoint as text records in a Permissioned Resolver. The gateway resolves these records at runtime. Changing a price therefore becomes an on-chain transaction instead of a deployment, and registering an agent becomes a registry operation instead of a pull request. Every inference request is priced before it runs. The gateway token-counts the prompt and calculates a quote for the prompt plus a bounded completion using the published model rate and a small margin. The upstream request is then capped at exactly the budget that was authorized. This means callers are never charged for tokens they did not authorize and do not get unexpected overages. Reasoning models are handled separately because thinking and output cannot always share the same limit. In one test, a 256-token budget resulted in 245 tokens being spent on reasoning and only 7 tokens reaching the final answer. x402Router therefore quotes the thinking allowance separately and accounts for it explicitly. The quoted price comes directly from the ENS record, and the HTTP 402 response identifies the record used for the quote, allowing the caller to verify the price against the registry instead of blindly trusting the gateway. Payments are handled through x402. An unpaid request returns HTTP 402 with the payment requirements and a complete quote breakdown. The client signs a Hedera transfer using its session key and retries the request. Blocky402 verifies and settles the payment on Hedera before the gateway returns the inference result. A session is also a name. Opening a session registers a name such as `s7fj2k.keys.router402.eth` in our hierarchical ENSv2 registry. The registry stores the owner and expiry and provides on-chain revocation through `unregister()`. Revocation is therefore a public, ordered fact that can be checked independently of the gateway database. Session names are deliberately non-transferable. The session owner receives `ROLE_UNREGISTER`, but not `ROLE_CAN_TRANSFER_ADMIN` or `ROLE_RENEW`. A session key therefore cannot transfer the session to another party or extend its own lifetime. For ECDSA-backed Hedera accounts, the ENS name is registered to the account's EVM alias, allowing the caller to revoke the session on Sepolia without connecting a separate Ethereum wallet. Every request checks the registry rather than relying only on a database row. Each settlement is published to a public Hedera Consensus Service topic, creating a tamper-evident payment history that can be independently verified. The demo supports settlement in HBAR and HTS tokens with a custom fee schedule. The service is also exposed through an x402 Bazaar listing, `/.well-known/agent.json`, and `/v1/discovery`, with each agent's ENS name included so other agents can discover and call the service programmatically. For harnesses that cannot sign x402 payments themselves, x402Router provides an encrypted and revocable access URL that allows an agent to pay automatically within the limits of its session. This is intentionally restricted to testnet. The core design is simple: ENS provides the naming, discovery, identity, and policy layer, while Hedera provides the payment and settlement layer.