Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.mag3nt.com/llms.txt

Use this file to discover all available pages before exploring further.

Overview

mag3nt supports three open payment protocols. Each serves a different use case:
ProtocolBest forDirection
x402Paying for API access (HTTP 402 flows)Bidirectional
AP2Agent-to-agent payments with mandatesBidirectional
MPPMicropayment streaming (pay-per-token)Bidirectional

x402 — HTTP 402 Payment Protocol

When an API returns HTTP 402 Payment Required, your agent can pay using x402:
// 1. Agent calls an API, gets 402
// 2. Pay via mag3nt
const payment = await mag3nt.x402.x402Pay({
  cardId: "sx_...",
  cardToken: "tok_...",
  amount: 0.50,
  merchant: "weather-api.com",
  merchantAddress: "0xABC...",
  resourceUrl: "https://weather-api.com/forecast",
});

// 3. Retry the original request with payment headers
const response = await fetch("https://weather-api.com/forecast", {
  headers: payment.headers,
});

Receive x402 payments

If you’re building an API that accepts x402:
const receipt = await mag3nt.x402.x402Receive({
  paymentHeader: req.headers["x-payment"],
  resourceUrl: "https://your-api.com/data",
  amount: 0.10,
});

AP2 — Agent-to-Agent Protocol

For recurring agent-to-agent payments with spending mandates:
// Create a mandate: "Agent B can spend up to $10/day from my card"
const mandate = await mag3nt.ap2.ap2CreateMandate({
  cardId: "sx_...",
  cardToken: "tok_...",
  maxAmount: 10,
  period: "daily",
  grantee: "0xAgentB...",
});

// Agent B executes payments against the mandate
const payment = await mag3nt.ap2.ap2Execute({
  mandateId: mandate.mandateId,
  amount: 2.50,
  description: "Data processing fee",
});

MPP — Micropayment Protocol

For streaming micropayments (pay-per-token, pay-per-API-call):

One-time micropayment

const payment = await mag3nt.mpp.mppPay({
  cardId: "sx_...",
  cardToken: "tok_...",
  amount: 0.01,
  merchantCardId: "sx_merchant...",
});

Payment streams

Open a continuous payment channel:
// Open stream with $5 budget
const stream = await mag3nt.mpp.mppStreamsOpen({
  payerCardId: "sx_payer...",
  payerCardToken: "tok_...",
  receiverCardId: "sx_receiver...",
  budget: 5.0,
});

// Send micro-payments as resources are consumed
await mag3nt.mpp.mppStreamsTick({
  streamId: stream.stream.id,
  amount: 0.001,
  resource: "token-generation",
});

// Check running totals
const status = await mag3nt.mpp.mppStreamsGet(stream.stream.id);
console.log(`Spent: ${status.stream.totalSettled} / ${status.stream.budget}`);

// Close when done
await mag3nt.mpp.mppStreamsClose({ streamId: stream.stream.id });

Choosing a protocol

Most agents should start with x402. It’s the simplest — your agent pays for API access just like a human pays for a subscription, but per-request.
  • x402: Your agent calls third-party APIs that require payment
  • AP2: Your agent delegates spending to other agents
  • MPP: Your agent consumes or provides streaming services (LLM inference, real-time data)