402
MPP·CoDi

Machine Payments Protocol × CoDi × pey

HTTP 402, paid in pesos.

The first Mexican real-time rail on MPP. An agent calls your API, gets a 402 with a CoDi QR, a human taps Pagar in their bank app, and the agent gets 200 plus a receipt with the Banxico tracking key.

Pay $1.00 MXN for a taco recipe →or let an agent do it: POST /mcp · GET /openapi.json
1Request
GET /api/taco

An agent, a script or this page.

2402 Challenge
Payment method="codi"

Amount in MXN + a CoDi QR from pey (and a push, if asked).

3Human approves
Pagar ✓

Scan or tap in any CoDi bank app. 2-3 s per pey call.

4200 + Receipt
Payment-Receipt: eyJ…

pey transaction id + clave de rastreo.

5
CoDi payments verified
$10.00
collected
1
open sessions
1
calls paid from balance

Try it: paid endpoints

🌮Receta de tacos con IA

One-time charge. A human pays once, the agent gets the recipe.

GET /api/taco
charge $1.00session $1.00/call
💱Tipo de cambio USD/MXN

Per-call price on a prepaid balance: one CoDi tap, then no human in the loop.

GET /api/tipo-de-cambio
session $0.10/call
🎸Corrido personalizado

POST with a body: the challenge is bound to the body digest (RFC 9530).

POST /api/corrido
charge $2.00

Session deposit: $5.00 per top-up. CoDi through pey has no refunds, so unspent balance stays with the merchant (disclosed in the challenge as refundable: false).

🇲🇽

Pick an endpoint to see the handshake.

This page is an MPP client: it reads the 402, shows the QR, polls with the credential.

Pay from code

import { fetchWithCodi, printPrompt } from "@pey/mpp-codi/client";

const res = await fetchWithCodi("https://pey-mpp.exe.xyz/api/taco", {}, {
  onQr: printPrompt,          // QR in the terminal (or your UI)
  phone: "5512345678",        // optional: also push to the payer's bank app
  wait: { timeoutMs: 300_000 }, // bounded: the human has 5 minutes
});
if (res.ok) console.log(res.value.receipt?.trackingKey, await res.value.response.json());
bun apps/mpp-codi/src/client/demo.ts https://pey-mpp.exe.xyz/api/taco --simulate

What follows the spec

  • Challenges per draft-httpauth-payment-01: JCS + base64url, HMAC-SHA256 id binding (passes the draft's test vectors), RFC 3339 expiry.
  • charge intent: amount in centavos, currency mxn, single-use challenges, atomic redemption, a payment redeems once.
  • session intent modeled on draft-lightning-session-00: open / bearer / topUp / close.
  • RFC 9457 problems, RFC 9530 body digests, Accept-Payment, Idempotency-Key, no-store / private caching.
  • MCP binding at POST /mcp (-32042 / -32043, org.paymentauth/* _meta) and discovery at /openapi.json (mppx validate: 31/31).