Skip to main content
This guide explains how to integrate the Nevermined Payments Python SDK with A2A (Agent-to-Agent) protocol servers.

Overview

A2A (Agent-to-Agent) is a protocol that enables AI agents to communicate with each other using JSON-RPC. The Nevermined SDK provides A2A integration to:
  • Build A2A servers with payment validation
  • Automatically verify x402 tokens on incoming requests
  • Handle credit redemption for agent tasks

Building Agent Cards

With a Single Plan

With Multiple Plans

When your agent supports multiple plans (e.g. a basic and a premium tier), use planIds instead of planId:
Note: Provide either planId or planIds, not both. planIds must be a non-empty list.

Agent Card Structure

The agent card includes a payment extension:

Using the @a2a_requires_payment Decorator

The simplest way to create a payment-protected A2A agent:
The decorator handles:
  • Payment middleware (verify/settle) automatically
  • Publishing task status events with creditsUsed metadata
  • Credit burning on task completion

AgentResponse

Starting an A2A Server (Advanced)

For more control, use PaymentsA2AServer.start() directly:

Server Configuration Options

Request Validation

The A2A server automatically validates payments on every POST request:
  1. Extracts Bearer token from Authorization header
  2. Reads planId or planIds from the agent card’s payment extension
  3. Verifies permissions via build_payment_required_for_plans()
  4. Rejects requests with 402 if validation fails, including a base64-encoded payment-required header
When multiple plans are configured, the 402 response includes all plans in accepts[], allowing the client to choose which plan to purchase.

Client Usage

Discovering Plans from the Agent Card

Consumers can fetch the agent card to discover available plans:

Ordering a Plan and Sending Messages

Hooks

Add custom logic at request lifecycle points:

Error Handling

Next Steps

x402 Protocol

Deep dive into x402 payment protocol

Request Validation

Manual validation patterns