Skip to main content

libertai-x402

x402 utilities that handle payments automatically for LibertAI services

Install

pip install libertai-x402

Usage with OpenAI SDK

import asyncio
from openai import AsyncOpenAI
from libertai_x402 import create_payment_client

async def main():
    http_client = create_payment_client("0x...")

    client = AsyncOpenAI(
        base_url="https://api.libertai.io/v1",
        api_key="x402",
        http_client=http_client,
    )

    response = await client.chat.completions.create(
        model="qwen3.5-27b",
        messages=[{"role": "user", "content": "Hello!"}],
    )

    print(response.choices[0].message.content)

asyncio.run(main())

Set api_key to "x402" — the wrapper strips this dummy value before sending requests. Real API keys (any other value) are preserved.

Usage with httpx

import asyncio
from libertai_x402 import create_payment_client

async def main():
    async with create_payment_client("0x...") as client:
        resp = await client.post(
            "https://api.libertai.io/v1/chat/completions",
            json={
                "model": "qwen3.5-27b",
                "messages": [{"role": "user", "content": "Hello!"}],
            },
        )
        print(resp.json())

asyncio.run(main())

How it works

  1. Makes the request normally
  2. If the server responds with 402, reads PaymentRequirements from the response body
  3. Signs an EIP-712 typed data message (Permit or TransferWithAuthorization on Base) using the provided private key
  4. Retries the request with the signed payment in the X-PAYMENT header

License

MIT

Metadata

Release files for libertai-x402 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 libertai-x402 0.1.0
File Size Uploaded
libertai_x402-0.1.0.tar.gz 4.0 kB Details

Built distribution (wheel)

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

Total release size: 9.3 kB

Release files / libertai_x402-0.1.0.tar.gz

Download URL libertai_x402-0.1.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
758ff2a938ac8bc46f2d7a3a2f3ff93657fe0288ea8c1271f8eafe553ed6bd77
BLAKE2b-256 checksum
How to use checksums
ad80f62ad68cc5867798d3243bf2f303fd822ca955343a17c9694157294be2b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 17, 2026.

Transparency log

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

Download URL libertai_x402-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20928a1cbb4396c3f2fc4d435cda49ff199c64caa48526933a4daf5e9ef15e0c
BLAKE2b-256 checksum
How to use checksums
a8f756849b8cb881ddb307f1db38113e1ff328a6793a6eb772aae85a04feac07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 17, 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