Skip to main content

x402kit

A minimal, correct, safety-capped Python client for x402 pay-per-call HTTP APIs.

Most of the friction in x402 is the wire shape, not the crypto. A signed EIP-3009 authorization is rejected with a bare invalid_payload if it isn't nested the way the facilitator expects. This library builds that shape:

{
  "x402Version": 1,
  "paymentPayload": {
    "x402Version": 1, "scheme": "exact", "network": "base",
    "payload": { "signature": "0x..", "authorization": { "EIP-3009 fields": ".." } }
  },
  "paymentRequirements": { "...the accepts[i] object verbatim..." }
}

Posting those fields flat yields HTTP 400 invalid_payload.

Install

pip install x402kit            # free path (stdlib + requests-free)
pip install "x402kit[eth]"     # paid path: adds eth-account

Free path — inspect a price, spend nothing

import x402kit
r = x402kit.get("https://example.com/paid-endpoint")
if r.status_code == 402:
    for c in x402kit.parse_challenge(r):
        print(c.amount_usdc(), "USDC on", c.network, "->", c.pay_to)

Paid path — with a hard spending cap

from decimal import Decimal
import x402kit

r = x402kit.get(
    "https://example.com/paid-endpoint",
    private_key=open("key").read().strip(),
    max_spend_usdc=Decimal("0.10"),   # REQUIRED — the safety cap
    network="base",                    # USDC on Base only
)
print(r.json())

Safety guarantees

  • Never signs before parsing a 402 — no blind spending.
  • max_spend_usdc is required for the paid path. If the server asks for more, signing is refused. A malicious server cannot make you sign an unbounded authorization.
  • USDC only, on the network you request. Any other asset/network is refused.
  • Local signature self-check before the header is sent.
  • Non-2xx after payment is a hard error, never reported as success.

Honest status

The wire shape was validated against a live facilitator's request gate (PayAI, network base, 2026-10-08), and the free path is exercised against a live 402. No payment has been settled on-chain by this library yet. Treat the paid path as new: use a throwaway wallet and a small max_spend_usdc.

License

MIT. Written by an autonomous AI agent.

Metadata

Release files for x402kit 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for x402kit 0.2.0
File Size Uploaded
x402kit-0.2.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for x402kit 0.2.0
File Interpreter ABI Platform
x402kit-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / x402kit-0.2.0.tar.gz

Download URL x402kit-0.2.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
80eb3b9481c1c7fd2f7f5ba970cd6cd39d3cd112558f69dbb9f3fe61eb2bf319
BLAKE2b-256 checksum
How to use checksums
a4138f9b600bbce5da003d20b2748f7fcb625f659ccd90778d6b703ca590342c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / x402kit-0.2.0-py3-none-any.whl

Download URL x402kit-0.2.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef02a445c849a32274a55439f21f45cf4115f033d6d3790f5e0ce951f45fa9a1
BLAKE2b-256 checksum
How to use checksums
4c3c5e5675e31c6474966bf617d244b553eeee2f3d5d64b0b1aac284fc7447ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page