agent-intent-x402 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - name: Install
20
+ run: python -m pip install -e ".[dev]"
21
+ - name: Lint
22
+ run: ruff check .
23
+ - name: Test
24
+ run: pytest -q
25
+
26
+ build:
27
+ runs-on: ubuntu-latest
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+ - uses: actions/setup-python@v5
31
+ with:
32
+ python-version: "3.12"
33
+ - name: Build
34
+ run: |
35
+ python -m pip install build twine
36
+ python -m build
37
+ python -m twine check dist/*
@@ -0,0 +1,31 @@
1
+ name: Release
2
+
3
+ # Publishes to PyPI on version-tag push, e.g. `git tag v0.1.0 && git push origin v0.1.0`.
4
+ #
5
+ # Setup: add a repository secret named PYPI_API_TOKEN
6
+ # (Settings -> Secrets and variables -> Actions -> New repository secret)
7
+ # Value: a PyPI API token scoped to the `agent-intent-x402` project.
8
+
9
+ on:
10
+ push:
11
+ tags:
12
+ - "v*"
13
+
14
+ jobs:
15
+ release:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.12"
22
+ - name: Build distributions
23
+ run: |
24
+ python -m pip install build twine
25
+ python -m build
26
+ python -m twine check dist/*
27
+ - name: Publish to PyPI
28
+ env:
29
+ TWINE_USERNAME: __token__
30
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
31
+ run: python -m twine upload dist/*
@@ -0,0 +1,20 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .mypy_cache/
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ venv/
15
+ env/
16
+
17
+ # Editor / OS
18
+ .vscode/
19
+ .idea/
20
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JarvisClaw
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-intent-x402
3
+ Version: 0.2.0
4
+ Summary: Pay-per-request access to any service for AI agents, over the open x402 protocol. Declare an intent, discover a provider, and settle on-chain with a single signature.
5
+ Project-URL: Homepage, https://github.com/api-jarvisclaw/agent-intent-x402
6
+ Project-URL: Documentation, https://github.com/api-jarvisclaw/agent-intent-x402#readme
7
+ Project-URL: Repository, https://github.com/api-jarvisclaw/agent-intent-x402
8
+ Project-URL: Issues, https://github.com/api-jarvisclaw/agent-intent-x402/issues
9
+ Project-URL: Protocol, https://github.com/api-jarvisclaw/agent-intent-protocol
10
+ Project-URL: x402, https://x402.org
11
+ Author-email: JarvisClaw <dev@jarvisclaw.ai>
12
+ License: MIT
13
+ License-File: LICENSE
14
+ Keywords: agent,ai,eip-3009,http-402,intent,llm,payments,usdc,x402
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Internet :: WWW/HTTP
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: eth-account>=0.11.0
26
+ Requires-Dist: httpx>=0.24.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest-httpx>=0.21.0; extra == 'dev'
29
+ Requires-Dist: pytest>=7.0; extra == 'dev'
30
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # agent-intent-x402
34
+
35
+ Pay-per-request access to any service, for AI agents — over the open
36
+ [x402](https://x402.org) protocol.
37
+
38
+ Declare *what* you want, discover *who* provides it, and pay for the
39
+ request on-chain with a single signature. No accounts, no API keys, no
40
+ platform lock-in. Your agent carries a wallet; the service quotes a
41
+ price with HTTP `402 Payment Required`; the client signs and settles.
42
+ Because payment speaks the open x402 standard, the same client works
43
+ against any compliant gateway.
44
+
45
+ ```bash
46
+ pip install agent-intent-x402
47
+ ```
48
+
49
+ ## Quick start
50
+
51
+ Give the client a wallet and it settles `402` challenges automatically —
52
+ sign the payment, retry the request, return the result.
53
+
54
+ ```python
55
+ from agent_intent_x402 import AIPClient, Wallet, IntentType
56
+
57
+ wallet = Wallet(private_key="0x...") # your agent's EVM key
58
+
59
+ with AIPClient(wallet=wallet, endpoint="https://api.example.com") as client:
60
+ # Resolve an intent to the best-ranked provider. If the gateway
61
+ # answers 402, the wallet pays and the call transparently retries.
62
+ result = client.resolve(
63
+ IntentType.CHAT_COMPLETION,
64
+ constraints={"max_price_usd": 0.01},
65
+ preferences={"optimize_for": "cost"},
66
+ )
67
+ best = result.best_match
68
+ print(f"{best.provider_id} · {best.model} · score={best.score}")
69
+ ```
70
+
71
+ The private key can also be supplied via the `AIP_WALLET_KEY`
72
+ environment variable, in which case `Wallet()` needs no arguments.
73
+
74
+ ## How payment works
75
+
76
+ x402 turns HTTP `402 Payment Required` into a usable payment step:
77
+
78
+ 1. The client makes a normal request.
79
+ 2. If payment is due, the gateway replies `402` with the accepted terms
80
+ (amount, asset, recipient, network) in the body.
81
+ 3. The wallet signs an [EIP-3009](https://eips.ethereum.org/EIPS/eip-3009)
82
+ `TransferWithAuthorization` for those exact terms — an EIP-712 typed
83
+ signature, no gas, no on-chain transaction from your side.
84
+ 4. The client retries with a `PAYMENT-SIGNATURE` header. The gateway
85
+ verifies and settles on-chain, then serves the response.
86
+
87
+ Payments default to USDC on Base (`eip155:8453`); the network and asset
88
+ come from the gateway's `402` terms, so the wallet always signs exactly
89
+ what it is asked to pay.
90
+
91
+ ## Resolve, then execute
92
+
93
+ `resolve` returns ranked matches so you can inspect price and score
94
+ before committing. `execute` resolves *and* runs the intent in one call,
95
+ proxying the provider response back:
96
+
97
+ ```python
98
+ response = client.execute(
99
+ IntentType.CHAT_COMPLETION,
100
+ payload={"messages": [{"role": "user", "content": "Hello"}]},
101
+ preferences={"optimize_for": "quality"},
102
+ )
103
+ ```
104
+
105
+ ## Natural-language intents
106
+
107
+ Let the gateway interpret a free-form request. It may resolve directly
108
+ or reply with a clarifying question for a multi-turn exchange:
109
+
110
+ ```python
111
+ reply = client.resolve_natural("I need to transcribe an audio file cheaply")
112
+ if reply.get("status") == "clarify":
113
+ print(reply["message"]) # follow-up question
114
+ else:
115
+ print(reply["matches"]) # resolved providers
116
+ ```
117
+
118
+ ## Discovery
119
+
120
+ ```python
121
+ # Every intent type the gateway understands.
122
+ client.list_intent_types()
123
+
124
+ # Providers available for a given intent.
125
+ client.discover(intent_type=IntentType.IMAGE_GENERATION)
126
+
127
+ # The full provider catalogue.
128
+ client.list_providers()
129
+ ```
130
+
131
+ ## Intent types
132
+
133
+ `chat_completion`, `image_generation`, `video_generation`,
134
+ `text_to_speech`, `web_search`, `knowledge_search`,
135
+ `prompt_optimization`, `document_processing`, `utility`,
136
+ `code_execution`, `data_analysis`, `translation`, `code_generation`.
137
+
138
+ ## Errors
139
+
140
+ All exceptions derive from `AIPError`:
141
+
142
+ - `AIPConnectionError` — the request never reached the gateway.
143
+ - `AIPAuthError` — `401`/`403`, missing or invalid credentials.
144
+ - `AIPPaymentRequiredError` — `402`, payment required and no wallet was
145
+ configured (or the payment was rejected).
146
+ - `AIPAPIError` — any other non-2xx response (`status_code`, `detail`, `body`).
147
+
148
+ `WalletError` is raised when a `402` challenge cannot be signed (missing
149
+ key, malformed terms).
150
+
151
+ ## Protocol
152
+
153
+ The intent wire format and endpoint contract are defined in the
154
+ [Agent Intent Protocol specification](https://github.com/api-jarvisclaw/agent-intent-protocol).
155
+ The payment layer follows the open [x402](https://x402.org) protocol.
156
+
157
+ ## License
158
+
159
+ MIT
@@ -0,0 +1,127 @@
1
+ # agent-intent-x402
2
+
3
+ Pay-per-request access to any service, for AI agents — over the open
4
+ [x402](https://x402.org) protocol.
5
+
6
+ Declare *what* you want, discover *who* provides it, and pay for the
7
+ request on-chain with a single signature. No accounts, no API keys, no
8
+ platform lock-in. Your agent carries a wallet; the service quotes a
9
+ price with HTTP `402 Payment Required`; the client signs and settles.
10
+ Because payment speaks the open x402 standard, the same client works
11
+ against any compliant gateway.
12
+
13
+ ```bash
14
+ pip install agent-intent-x402
15
+ ```
16
+
17
+ ## Quick start
18
+
19
+ Give the client a wallet and it settles `402` challenges automatically —
20
+ sign the payment, retry the request, return the result.
21
+
22
+ ```python
23
+ from agent_intent_x402 import AIPClient, Wallet, IntentType
24
+
25
+ wallet = Wallet(private_key="0x...") # your agent's EVM key
26
+
27
+ with AIPClient(wallet=wallet, endpoint="https://api.example.com") as client:
28
+ # Resolve an intent to the best-ranked provider. If the gateway
29
+ # answers 402, the wallet pays and the call transparently retries.
30
+ result = client.resolve(
31
+ IntentType.CHAT_COMPLETION,
32
+ constraints={"max_price_usd": 0.01},
33
+ preferences={"optimize_for": "cost"},
34
+ )
35
+ best = result.best_match
36
+ print(f"{best.provider_id} · {best.model} · score={best.score}")
37
+ ```
38
+
39
+ The private key can also be supplied via the `AIP_WALLET_KEY`
40
+ environment variable, in which case `Wallet()` needs no arguments.
41
+
42
+ ## How payment works
43
+
44
+ x402 turns HTTP `402 Payment Required` into a usable payment step:
45
+
46
+ 1. The client makes a normal request.
47
+ 2. If payment is due, the gateway replies `402` with the accepted terms
48
+ (amount, asset, recipient, network) in the body.
49
+ 3. The wallet signs an [EIP-3009](https://eips.ethereum.org/EIPS/eip-3009)
50
+ `TransferWithAuthorization` for those exact terms — an EIP-712 typed
51
+ signature, no gas, no on-chain transaction from your side.
52
+ 4. The client retries with a `PAYMENT-SIGNATURE` header. The gateway
53
+ verifies and settles on-chain, then serves the response.
54
+
55
+ Payments default to USDC on Base (`eip155:8453`); the network and asset
56
+ come from the gateway's `402` terms, so the wallet always signs exactly
57
+ what it is asked to pay.
58
+
59
+ ## Resolve, then execute
60
+
61
+ `resolve` returns ranked matches so you can inspect price and score
62
+ before committing. `execute` resolves *and* runs the intent in one call,
63
+ proxying the provider response back:
64
+
65
+ ```python
66
+ response = client.execute(
67
+ IntentType.CHAT_COMPLETION,
68
+ payload={"messages": [{"role": "user", "content": "Hello"}]},
69
+ preferences={"optimize_for": "quality"},
70
+ )
71
+ ```
72
+
73
+ ## Natural-language intents
74
+
75
+ Let the gateway interpret a free-form request. It may resolve directly
76
+ or reply with a clarifying question for a multi-turn exchange:
77
+
78
+ ```python
79
+ reply = client.resolve_natural("I need to transcribe an audio file cheaply")
80
+ if reply.get("status") == "clarify":
81
+ print(reply["message"]) # follow-up question
82
+ else:
83
+ print(reply["matches"]) # resolved providers
84
+ ```
85
+
86
+ ## Discovery
87
+
88
+ ```python
89
+ # Every intent type the gateway understands.
90
+ client.list_intent_types()
91
+
92
+ # Providers available for a given intent.
93
+ client.discover(intent_type=IntentType.IMAGE_GENERATION)
94
+
95
+ # The full provider catalogue.
96
+ client.list_providers()
97
+ ```
98
+
99
+ ## Intent types
100
+
101
+ `chat_completion`, `image_generation`, `video_generation`,
102
+ `text_to_speech`, `web_search`, `knowledge_search`,
103
+ `prompt_optimization`, `document_processing`, `utility`,
104
+ `code_execution`, `data_analysis`, `translation`, `code_generation`.
105
+
106
+ ## Errors
107
+
108
+ All exceptions derive from `AIPError`:
109
+
110
+ - `AIPConnectionError` — the request never reached the gateway.
111
+ - `AIPAuthError` — `401`/`403`, missing or invalid credentials.
112
+ - `AIPPaymentRequiredError` — `402`, payment required and no wallet was
113
+ configured (or the payment was rejected).
114
+ - `AIPAPIError` — any other non-2xx response (`status_code`, `detail`, `body`).
115
+
116
+ `WalletError` is raised when a `402` challenge cannot be signed (missing
117
+ key, malformed terms).
118
+
119
+ ## Protocol
120
+
121
+ The intent wire format and endpoint contract are defined in the
122
+ [Agent Intent Protocol specification](https://github.com/api-jarvisclaw/agent-intent-protocol).
123
+ The payment layer follows the open [x402](https://x402.org) protocol.
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,57 @@
1
+ """agent-intent-x402 — pay-per-request access for AI agents over x402.
2
+
3
+ Declare *what* you want, discover *who* provides it, and pay for the
4
+ request on-chain with a single signature — no accounts, no API keys, no
5
+ platform lock-in. Payment speaks the open `x402 <https://x402.org>`_
6
+ protocol, so the same client works against any compliant gateway.
7
+
8
+ from agent_intent_x402 import AIPClient, IntentType, Wallet
9
+
10
+ # A wallet lets the client answer HTTP 402 challenges automatically.
11
+ wallet = Wallet(private_key="0x...")
12
+ with AIPClient(wallet=wallet) as client:
13
+ result = client.resolve(IntentType.CHAT_COMPLETION)
14
+ print(result.best_match.provider_id)
15
+ """
16
+
17
+ from .client import DEFAULT_ENDPOINT, AIPClient
18
+ from .errors import (
19
+ AIPAPIError,
20
+ AIPAuthError,
21
+ AIPConnectionError,
22
+ AIPError,
23
+ AIPPaymentRequiredError,
24
+ )
25
+ from .models import (
26
+ Constraints,
27
+ IntentType,
28
+ Match,
29
+ OptimizeFor,
30
+ Preferences,
31
+ Pricing,
32
+ Provider,
33
+ ResolveResult,
34
+ )
35
+ from .wallet import Wallet, WalletError
36
+
37
+ __version__ = "0.2.0"
38
+
39
+ __all__ = [
40
+ "AIPClient",
41
+ "DEFAULT_ENDPOINT",
42
+ "Wallet",
43
+ "WalletError",
44
+ "AIPError",
45
+ "AIPAPIError",
46
+ "AIPAuthError",
47
+ "AIPConnectionError",
48
+ "AIPPaymentRequiredError",
49
+ "IntentType",
50
+ "OptimizeFor",
51
+ "Constraints",
52
+ "Preferences",
53
+ "Pricing",
54
+ "Match",
55
+ "ResolveResult",
56
+ "Provider",
57
+ ]