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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file open402-0.1.2.tar.gz.
File metadata
- Download URL: open402-0.1.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afa0bd91b010d337407a85745fc95697afb447b16188d54add548be95e7dc5db
|
|
| MD5 |
c811096edd48f34d9b7b63d0ea0263e1
|
|
| BLAKE2b-256 |
04679abf42251129f98d6b23d0e7a4f83b63e9b123f27b8b470acf2f617f1eb6
|
Provenance
The following attestation bundles were made for open402-0.1.2.tar.gz:
Publisher:
publish.yml on AetherCore-Dev/ag402
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
open402-0.1.2.tar.gz -
Subject digest:
afa0bd91b010d337407a85745fc95697afb447b16188d54add548be95e7dc5db - Sigstore transparency entry: 983309724
- Sigstore integration time:
-
Permalink:
AetherCore-Dev/ag402@da21e90369131615efdaccd5fbabe1d7fa28da22 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/AetherCore-Dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@da21e90369131615efdaccd5fbabe1d7fa28da22 -
Trigger Event:
release
-
Statement type:
File details
Details for the file open402-0.1.2-py3-none-any.whl.
File metadata
- Download URL: open402-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60bc94ca221336779c3ae67b0167c18a01537eabf494a83d2c35584b8285c2fc
|
|
| MD5 |
a7655299a854346e313af408a20c3f16
|
|
| BLAKE2b-256 |
d402c8a817d54ae389e9e876acae8a5a62ee41ec9813b5a6e743a56b7a8c14ae
|
Provenance
The following attestation bundles were made for open402-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on AetherCore-Dev/ag402
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
open402-0.1.2-py3-none-any.whl -
Subject digest:
60bc94ca221336779c3ae67b0167c18a01537eabf494a83d2c35584b8285c2fc - Sigstore transparency entry: 983309726
- Sigstore integration time:
-
Permalink:
AetherCore-Dev/ag402@da21e90369131615efdaccd5fbabe1d7fa28da22 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/AetherCore-Dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@da21e90369131615efdaccd5fbabe1d7fa28da22 -
Trigger Event:
release
-
Statement type: