Skip to main content

x402 utils to use LibertAI services

Project description

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

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

libertai_x402-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

libertai_x402-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file libertai_x402-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for libertai_x402-0.1.0.tar.gz
Algorithm Hash digest
SHA256 758ff2a938ac8bc46f2d7a3a2f3ff93657fe0288ea8c1271f8eafe553ed6bd77
MD5 99f6030846d0f100b2a8fa467f00175a
BLAKE2b-256 ad80f62ad68cc5867798d3243bf2f303fd822ca955343a17c9694157294be2b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for libertai_x402-0.1.0.tar.gz:

Publisher: x402-pypi.yml on Libertai/libertai-agents

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

File details

Details for the file libertai_x402-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for libertai_x402-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20928a1cbb4396c3f2fc4d435cda49ff199c64caa48526933a4daf5e9ef15e0c
MD5 b42560b87930a5cc1b04700d2c3af18e
BLAKE2b-256 a8f756849b8cb881ddb307f1db38113e1ff328a6793a6eb772aae85a04feac07

See more details on using hashes here.

Provenance

The following attestation bundles were made for libertai_x402-0.1.0-py3-none-any.whl:

Publisher: x402-pypi.yml on Libertai/libertai-agents

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