Skip to main content

Kite x402 Wrapper for Python

Wrap an HTTP API with x402 payments settled on Kite, using Python, FastAPI, and the official x402 SDK. Every request under /v1/* is payment protected; /healthz remains free.

The wrapper preserves the critical order:

verify payment -> call upstream -> settle only when upstream status is below 400

Install

Python 3.10 or newer is required.

The 0.1.0 PyPI release is prepared but is not published yet. Until the release is published, use the repository installation below.

git clone https://github.com/Tools-touch/KiteAI-X402-Wrapper.git
cd KiteAI-X402-Wrapper
uv sync --extra dev
cp .env.example .env
kite-x402-wrapper

After the PyPI release is published, the installed-package form is:

python -m pip install kite-x402-wrapper
cp .env.example .env
kite-x402-wrapper

For development from this repository:

uv sync --extra dev
cp .env.example .env
uv run kite-x402-wrapper

Then request a paid route:

curl -i "http://localhost:8080/v1/v1/forecast?latitude=52.52&longitude=13.41&current=temperature_2m"

An unpaid request returns HTTP 402 with a PAYMENT-REQUIRED header. The wrapper strips the first /v1 prefix before proxying, so the example above reaches https://api.open-meteo.com/v1/forecast.

Configuration

Variable Default Purpose
PAY_TO required Public EVM address receiving payments
KITE_NETWORK mainnet mainnet or testnet
UPSTREAM_URL required Fixed upstream HTTP(S) origin
UPSTREAM_AUTH_HEADER Authorization Optional upstream credential header
UPSTREAM_AUTH_VALUE empty Optional credential value, never returned to callers
PRICE_USD 0.001 Positive decimal USD price, at most 6 fractional digits
SERVICE_DESCRIPTION generic description Text included in the 402 requirements
FACILITATOR_URL Pieverse /v2 endpoint HTTPS x402 facilitator base URL
PORT 8080 Listening port

Start on Kite testnet. The wrapper uses pieUSD on eip155:2368; mainnet uses USDC.e on eip155:2366. The package never needs a wallet private key.

Use as a library

from kite_x402_wrapper import Settings, create_app

settings = Settings.from_env()
app = create_app(settings)

The application factory accepts an HTTPX client and payment components as optional injected dependencies. Tests can therefore verify proxy and settlement behavior without real funds or external services.

Safety properties

  • A missing or invalid payment never reaches the upstream.
  • Upstream responses with status 400 or higher are not settled.
  • Upstream connection failures return 502 and are not settled.
  • Payment headers are removed before proxying.
  • Upstream credentials replace caller-provided values and are never returned.
  • The proxy target stays on the configured upstream origin.
  • Amount conversion uses Decimal, never binary floating point.

Because settlement happens after the handler finishes, responses are buffered in memory by the official x402 FastAPI middleware. This template is intended for ordinary API payloads, not unbounded downloads or streaming endpoints.

Quality checks

uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytest --cov=kite_x402_wrapper
uv build
uv run twine check dist/*

Public deployment and paid acceptance

Kite Passport calls services from its own servers. Real paid testing requires a public HTTPS origin; localhost and browser-gated tunnels are not sufficient. Use a small, short-lived Passport sandbox session and verify the returned PAYMENT-RESPONSE transaction reference. Never fabricate paid-call evidence.

License

Apache-2.0.

Metadata

Release files for kite-x402-wrapper 0.1.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 kite-x402-wrapper 0.1.0
File Size Uploaded
kite_x402_wrapper-0.1.0.tar.gz 313.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kite-x402-wrapper 0.1.0
File Interpreter ABI Platform
kite_x402_wrapper-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 329.0 kB

Release files / kite_x402_wrapper-0.1.0.tar.gz

Download URL kite_x402_wrapper-0.1.0.tar.gz
Size 313.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4af95200b42b3f5fdc7d7834affab79925ffa6f250e36d1a6403e8c27b16127a
BLAKE2b-256 checksum
How to use checksums
96d970b4e7f7b8fcce5ebfc8f8d4a28a5fd7b9a6e25473afc1605daa1f824a3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.

Transparency log

Release files / kite_x402_wrapper-0.1.0-py3-none-any.whl

Download URL kite_x402_wrapper-0.1.0-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51a9a4dbed066d3cf16a9288246ab701b40e72b7dd0c4d0a05e84468f870d6c4
BLAKE2b-256 checksum
How to use checksums
a5696c80efafc6bab1fd17e76f44720e502b683e14346b7fd9ceba66a636591f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.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