- Discovery: publish your AI Agent Card at
/.well-known/agent.json. - Streaming and re-subscribe: set
capabilities.streaming: trueformessage/streamandtasks/resubscribe. - Authentication: credentials are sent in HTTP headers (e.g.,
payment-signature: <token>), not in the JSON‑RPC payload. - Authorization/charging: the agent emits a final event with
metadata.creditsUsed; Nevermined validates and burns credits accordingly.
Architecture
Features
The libraries provide ana2a module that enables seamless integration into new or existing A2A agents, including payment-signature authentication, asynchronous task management, and push notification support. Main features:
- Payment Signature Authentication: The server extracts access tokens from the
payment-signatureheader and injects them into the task context. - Credits Validation: Validates that the user has sufficient credits before executing a task.
- Credits Burning/Redemption: Redeem the credits specified in the result after successful execution.
- Multi-Plan Support: Agent cards can advertise multiple plans via
planIds, allowing consumers to choose which plan to subscribe to. - Scheme Auto-Detection: Resolves
nvm:erc4337ornvm:card-delegationfrom plan metadata automatically - Push Notifications: Supports the A2A standard flow for push notification configuration and delivery.
- Asynchronous Task Handling: Supports intermediate and final state events, compatible with polling and streaming.
- Unified SDK: Provides both agent and client integration.
Quickstart
If you already have a Google A2A agent, or you are building a new one, add the Payments Library to your agent and obtain an API key:1
1. Get Your API Key
To interact with the Nevermined API, you need an API key. Follow the Get Your API Key guide to create one.
2
2. Install and Initialize the Payments Library
Install the Payments Library and initialize the
Payments client with your API key.- TypeScript
- Python
Initialize the Payments Library
- TypeScript
- Python
A2A Server
The A2A server handles both
nvm:erc4337 and nvm:card-delegation schemes automatically.
The scheme is resolved from plan metadata — no server-side code changes are needed for fiat plans.Add the Payment Extension to the Agent Card
Because your AI agent charges for requests, add a payment extension to your agent card. Add a payment extension undercapabilities.extensions carrying Nevermined metadata:
Single Plan
Multiple Plans
When your agent supports multiple plans, useplanIds (array) instead of planId (string):
Provide either
planId or planIds, not both. When multiple plans are configured, the 402 Payment Required response includes all plans in accepts[], allowing consumers to choose.- The
urlmust match exactly the URL registered in Nevermined for the agent/plan. - The final streaming event must include
metadata.creditsUsedwith the consumed cost.
Define the Payment Agent Card in Your A2A Agent
- TypeScript
- Python
Start the A2A Server
The agent is initialized using the Nevermined Payments Library and the A2A protocol.Using the Decorator (Simple)
The@a2a_requires_payment decorator is the quickest way to create a payment-protected A2A agent in Python:
- TypeScript
- Python
Using PaymentsA2AServer (Advanced)
For more control over the executor and event lifecycle:
A2A Client
The client interacts with the agent using JSON-RPC requests. It discovers available plans from the agent card, purchases a plan, obtains an access token, and sends messages.Discovering Plans from the Agent Card
- TypeScript
- Python
Sending a Task
After purchasing access to the payment plan associated with the AI agent, a client can generate an access token and start sending tasks:The TypeScript example below targets a crypto plan. For a fiat plan, create the delegation with the card provider (
provider: 'stripe', currency: 'usd') and pass scheme: 'nvm:card-delegation' to getX402AccessToken — or use the PaymentsClient (Python tab), which resolves the scheme for you. See Which payment type does this plan need?.- TypeScript
- Python