@key0ai/key0/hono:
key0App(opts)— a Hono sub-app that serves agent discovery and the x402 payment endpoint.honoValidateAccessToken({ secret })— middleware that validates Bearer JWTs issued by Key0.
Installation
Routes
When you mountkey0App, the following routes are registered:
| Method | Path | Description |
|---|---|---|
| GET | /.well-known/agent.json | A2A agent card (discovery) |
| GET | /discover | Plan catalog (all plans and pricing) |
| POST | /x402/access | Unified x402 HTTP payment endpoint |
Setup
Configure the seller
Define your
SellerConfig with wallet address, network, agent identity, and pricing plans.Create stores and adapter
Provide the required
IChallengeStore, ISeenTxStore, and IPaymentAdapter instances.Mount the sub-app
Import Your agent card is now available at
key0App from @key0ai/key0/hono and mount it on your main Hono app.GET /.well-known/agent.json and the payment endpoint at POST /x402/access.Accessing the decoded token
AfterhonoValidateAccessToken succeeds, the decoded JWT payload is available via c.get("key0Token"). The payload contains:
| Field | Type | Description |
|---|---|---|
sub | string | The original request ID |
jti | string | The challenge ID |
resourceId | string | The resource that was paid for |
planId | string | The plan the client purchased |
txHash | string | The on-chain transaction hash |
| Scenario | HTTP Status | Error Code |
|---|---|---|
| Missing/malformed header | 401 | INVALID_REQUEST |
| Expired token | 401 | CHALLENGE_EXPIRED |
| Invalid signature | 401 | INVALID_REQUEST |
| Internal error | 500 | INTERNAL_ERROR |
Full example
API reference
key0App(opts)
Creates a Hono sub-app with agent card discovery and the x402 payment endpoint.
| Field | Type | Description |
|---|---|---|
config | SellerConfig | Seller configuration (wallet, plans) |
adapter | IPaymentAdapter | On-chain payment verification adapter |
store | IChallengeStore | Challenge state storage |
seenTxStore | ISeenTxStore | Double-spend prevention storage |
honoValidateAccessToken(config)
Returns Hono middleware that validates a Bearer token from the Authorization header.
| Field | Type | Description |
|---|---|---|
secret | string | The JWT secret used to sign tokens |
Pay-Per-Request Routes
key0App returns the Hono app and a payPerRequest(routeId, opts?) factory. Use it as Hono middleware on individual routes to gate them behind micro-payments — no JWT issued, payment settles inline.
PAYMENT-SIGNATURE header the middleware returns 402 with x402 payment requirements. After settlement, the PaymentInfo is available via c.get("key0Payment").
For standalone gateway mode, add proxyTo to SellerConfig — see the Express integration for the full proxy configuration reference.
Next Steps
SellerConfig Reference
Complete reference for every configuration option.
Paying for Access
How clients discover, pay, and call your protected endpoints.
Express Integration
Full A2A JSON-RPC support is available on Express only.
x402 HTTP Flow
Full protocol reference for the payment flow.

