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
- Makes the request normally
- If the server responds with
402, readsPaymentRequirementsfrom the response body - Signs an EIP-712 typed data message (Permit or TransferWithAuthorization on Base) using the provided private key
- Retries the request with the signed payment in the
X-PAYMENTheader
License
MIT
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
758ff2a938ac8bc46f2d7a3a2f3ff93657fe0288ea8c1271f8eafe553ed6bd77
|
|
| MD5 |
99f6030846d0f100b2a8fa467f00175a
|
|
| BLAKE2b-256 |
ad80f62ad68cc5867798d3243bf2f303fd822ca955343a17c9694157294be2b8
|
Provenance
The following attestation bundles were made for libertai_x402-0.1.0.tar.gz:
Publisher:
x402-pypi.yml on Libertai/libertai-agents
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libertai_x402-0.1.0.tar.gz -
Subject digest:
758ff2a938ac8bc46f2d7a3a2f3ff93657fe0288ea8c1271f8eafe553ed6bd77 - Sigstore transparency entry: 1114859531
- Sigstore integration time:
-
Permalink:
Libertai/libertai-agents@68cac7269a62d9ffc66ca96aaee3a9bc9d8c2bb2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Libertai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
x402-pypi.yml@68cac7269a62d9ffc66ca96aaee3a9bc9d8c2bb2 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20928a1cbb4396c3f2fc4d435cda49ff199c64caa48526933a4daf5e9ef15e0c
|
|
| MD5 |
b42560b87930a5cc1b04700d2c3af18e
|
|
| BLAKE2b-256 |
a8f756849b8cb881ddb307f1db38113e1ff328a6793a6eb772aae85a04feac07
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libertai_x402-0.1.0-py3-none-any.whl -
Subject digest:
20928a1cbb4396c3f2fc4d435cda49ff199c64caa48526933a4daf5e9ef15e0c - Sigstore transparency entry: 1114859534
- Sigstore integration time:
-
Permalink:
Libertai/libertai-agents@68cac7269a62d9ffc66ca96aaee3a9bc9d8c2bb2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Libertai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
x402-pypi.yml@68cac7269a62d9ffc66ca96aaee3a9bc9d8c2bb2 -
Trigger Event:
workflow_dispatch
-
Statement type: