agent-intent-x402
Pay-per-request access to any service, for AI agents — over the open x402 protocol.
Declare what you want, discover who provides it, and pay for the
request on-chain with a single signature. No accounts, no API keys, no
platform lock-in. Your agent carries a wallet; the service quotes a
price with HTTP 402 Payment Required; the client signs and settles.
Because payment speaks the open x402 standard, the same client works
against any compliant gateway.
pip install agent-intent-x402
Quick start
Give the client a wallet and it settles 402 challenges automatically —
sign the payment, retry the request, return the result.
from agent_intent_x402 import AIPClient, Wallet, IntentType
wallet = Wallet(private_key="0x...") # your agent's EVM key
with AIPClient(wallet=wallet, endpoint="https://api.example.com") as client:
# Resolve an intent to the best-ranked provider. If the gateway
# answers 402, the wallet pays and the call transparently retries.
result = client.resolve(
IntentType.CHAT_COMPLETION,
constraints={"max_price_usd": 0.01},
preferences={"optimize_for": "cost"},
)
best = result.best_match
print(f"{best.provider_id} · {best.model} · score={best.score}")
The private key can also be supplied via the AIP_WALLET_KEY
environment variable, in which case Wallet() needs no arguments.
How payment works
x402 turns HTTP 402 Payment Required into a usable payment step:
- The client makes a normal request.
- If payment is due, the gateway replies
402with the accepted terms (amount, asset, recipient, network) in the body. - The wallet signs an EIP-3009
TransferWithAuthorizationfor those exact terms — an EIP-712 typed signature, no gas, no on-chain transaction from your side. - The client retries with a
PAYMENT-SIGNATUREheader. The gateway verifies and settles on-chain, then serves the response.
Payments default to USDC on Base (eip155:8453); the network and asset
come from the gateway's 402 terms, so the wallet always signs exactly
what it is asked to pay.
Resolve, then execute
resolve returns ranked matches so you can inspect price and score
before committing. execute resolves and runs the intent in one call,
proxying the provider response back:
response = client.execute(
IntentType.CHAT_COMPLETION,
payload={"messages": [{"role": "user", "content": "Hello"}]},
preferences={"optimize_for": "quality"},
)
Natural-language intents
Let the gateway interpret a free-form request. It may resolve directly or reply with a clarifying question for a multi-turn exchange:
reply = client.resolve_natural("I need to transcribe an audio file cheaply")
if reply.get("status") == "clarify":
print(reply["message"]) # follow-up question
else:
print(reply["matches"]) # resolved providers
Discovery
# Every intent type the gateway understands.
client.list_intent_types()
# Providers available for a given intent.
client.discover(intent_type=IntentType.IMAGE_GENERATION)
# The full provider catalogue.
client.list_providers()
Intent types
chat_completion, image_generation, video_generation,
text_to_speech, web_search, knowledge_search,
prompt_optimization, document_processing, utility,
code_execution, data_analysis, translation, code_generation.
Errors
All exceptions derive from AIPError:
AIPConnectionError— the request never reached the gateway.AIPAuthError—401/403, missing or invalid credentials.AIPPaymentRequiredError—402, payment required and no wallet was configured (or the payment was rejected).AIPAPIError— any other non-2xx response (status_code,detail,body).
WalletError is raised when a 402 challenge cannot be signed (missing
key, malformed terms).
Protocol
The intent wire format and endpoint contract are defined in the Agent Intent Protocol specification. The payment layer follows the open x402 protocol.
License
MIT
Metadata
Release files for agent-intent-x402 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| agent_intent_x402-0.2.0.tar.gz | 14.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agent_intent_x402-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.5 kB
Release files / agent_intent_x402-0.2.0.tar.gz
| Download URL | agent_intent_x402-0.2.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5219a90a49b88050baed5b1e4a2425d342d11945552a534d6c9f3757c1dbdafd
|
|
BLAKE2b-256 checksum How to use checksums |
c5a46221f0ad875df85242d5b818d8b050f81994673034acde44b7c3936359cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / agent_intent_x402-0.2.0-py3-none-any.whl
| Download URL | agent_intent_x402-0.2.0-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
55c8b2a3cbc38fbfb81ee657433b6a587d8efd04e67f2471d7b5d7d9812bf22c
|
|
BLAKE2b-256 checksum How to use checksums |
73fb1b945aded8204ef1e56d33237a913e96e99e604f467f8abbd2062978df4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for agent-intent-x402 0.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.