Skip to main content

Reference implementation of the x402 payment protocol for AI Agents

Project description

open402

HTTP 402 payment protocol for machine-to-machine commerce — reference implementation in Python

Installation

pip install open402

Zero dependencies — pure Python protocol types, header parsing, and version negotiation.

Usage

Parse a 402 Response

from open402 import X402PaymentChallenge, parse_www_authenticate

# Parse the WWW-Authenticate header from a 402 response
challenge = parse_www_authenticate(
    'x402 chain="solana" token="USDC" amount="0.05" address="SolAddr..."'
)
# challenge.chain == "solana"
# challenge.token == "USDC"
# challenge.amount == "0.05"
# challenge.address == "SolAddr..."

Build an Authorization Header

from open402 import build_authorization

header_value = build_authorization(tx_hash="5abc...def")
# "x402 5abc...def"

Version Negotiation

from open402 import negotiate_version

result = negotiate_version(client_version="v1.0", server_versions=["v1.0", "v0.9"])
# result == "v1.0"

Protocol Flow

Client                                  Server
  │                                       │
  │── GET /api/resource ────────────────▶│
  │                                       │
  │◀── 402 Payment Required ─────────────│
  │    WWW-Authenticate: x402 ...         │
  │                                       │
  │ [Parse challenge → Pay on-chain]      │
  │                                       │
  │── GET /api/resource ────────────────▶│
  │   Authorization: x402 <tx_hash>       │
  │                                       │
  │◀── 200 OK ───────────────────────────│

Compatible with the Coinbase x402 standard.

Part of Ag402

open402 is the protocol layer of the Ag402 project. Use it standalone for protocol parsing, or with ag402-core for the full payment engine.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open402-0.1.9.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

open402-0.1.9-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file open402-0.1.9.tar.gz.

File metadata

  • Download URL: open402-0.1.9.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for open402-0.1.9.tar.gz
Algorithm Hash digest
SHA256 e31256a38330e1ffdd5e771999f7c16d0f2668f26c9927e1c5b0bd9b7a6321e6
MD5 4000607649098df502aabfa92e3b2ad6
BLAKE2b-256 227a43d4de293f990114e44947e5333365d93d7f054bc5df48f9a1bfdf8e2a6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for open402-0.1.9.tar.gz:

Publisher: publish.yml on AetherCore-Dev/ag402

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file open402-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: open402-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for open402-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 80b1cf0c5968a8d50b8d0cd49975711fd6bcb250006015b5dcfe6238764ea61d
MD5 83a9279f64dca5eca93d1a2cc5fa8581
BLAKE2b-256 35c328b866d1b1c96c131eeb380d2f3219fabb5e32b91ea5b3722e0079024e0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for open402-0.1.9-py3-none-any.whl:

Publisher: publish.yml on AetherCore-Dev/ag402

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page