How to integrate an existing backend with the Key0 standalone service — token validation, internal endpoints, and resource-scoped access control.
A backend service that works alongside the Key0 standalone service. Instead of embedding Key0 into your app, you keep your existing API and expose a few internal endpoints that the standalone Key0 service calls during the payment lifecycle. Your protected routes validate tokens issued by either Key0 (native JWT) or your own system (custom API keys).
Agent Key0 Service Your Backend | | | |-- request access ------->| | |<--- X402Challenge -------| | | | | | ... pays USDC ... | | | | | |-- payment proof -------->| | | |-- POST /internal/issue ----->| Issue API key (remote mode) | |<-------- { token } ----------| | |-- POST /internal/payment --->| Notify payment received |<--- AccessGrant ---------| | | | | |-- GET /api/photos/1 ----------------------------------->| Bearer token |<--- photo data ------------------------------------------|
The Key0 standalone service owns the A2A protocol, agent discovery, and on-chain payment verification. Your backend owns the business logic: validating resources, issuing credentials, and serving protected content.
These endpoints are called by the Key0 standalone service, not by agents directly. They must be secured with a shared secret via the X-Internal-Auth header.
Endpoint
Method
Auth
Purpose
/internal/issue-token
POST
Body-level trust
Issue a custom API key when Key0 runs in remote token mode
/internal/payment-received
POST
X-Internal-Auth
Webhook notification after successful on-chain payment verification
/internal/issue-token is only called when Key0 is configured with tokenMode: "remote". In native mode, Key0 issues JWTs directly and this endpoint is never hit.
A simple header check gates all internal endpoints. The Key0 standalone service sends this header automatically when calling your backend. In production, consider running these endpoints on a separate internal port or behind a network-level firewall.
When Key0 runs in remote token mode, it calls this endpoint after verifying payment. You issue whatever credential makes sense for your system — an API key, a signed URL, or a session token. The response is passed through to the agent in the AccessGrant.
The response must include token (the credential string) and tokenType (typically "Bearer"). expiresAt is optional but recommended so agents know when to refresh.
Fires after payment is verified and credentials are issued. Use it for analytics, inventory updates, or triggering downstream workflows. The request body contains the full AccessGrant including the transaction hash and block explorer URL.
The backend integration requires the Key0 standalone service running alongside it. See the Standalone quickstart for setup instructions. Make sure its INTERNAL_AUTH_SECRET and KEY0_ACCESS_TOKEN_SECRET match the values in your backend .env.