conduit-btc 0.8.4__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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Conduit
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,163 @@
1
+ Metadata-Version: 2.4
2
+ Name: conduit-btc
3
+ Version: 0.8.4
4
+ Summary: Self-hosted, non-custodial Bitcoin Lightning payments for autonomous AI agents — your node, your keys, your rules.
5
+ Author: Jake Knowles
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Jake1848/conduit
8
+ Project-URL: Documentation, https://github.com/Jake1848/conduit
9
+ Project-URL: Repository, https://github.com/Jake1848/conduit
10
+ Project-URL: Issues, https://github.com/Jake1848/conduit/issues
11
+ Keywords: bitcoin,lightning,ai-agents,payments,lnd,self-hosted,non-custodial
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Topic :: Office/Business :: Financial
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: httpx>=0.27
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=8.0; extra == "dev"
28
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
29
+ Requires-Dist: ruff>=0.4; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # conduit-btc
33
+
34
+ Python SDK for **Conduit** — self-hosted, non-custodial Bitcoin Lightning
35
+ payment infrastructure for autonomous AI agents.
36
+
37
+ **Your node, your keys, your rules.** Conduit is software tooling that you run
38
+ on your own infrastructure, against your own LND node, with your own keys. It
39
+ never touches your funds — it's a thin client for *your* Conduit instance.
40
+
41
+ ```bash
42
+ pip install conduit-btc
43
+ ```
44
+
45
+ > The importable package is `conduit`:
46
+ >
47
+ > ```python
48
+ > from conduit import Agent
49
+ > ```
50
+
51
+ ## Quickstart
52
+
53
+ Point the SDK at the Conduit instance you deployed (a 5-minute Docker deploy
54
+ against your own LND node), create an agent, and send a payment:
55
+
56
+ ```python
57
+ import conduit
58
+ from conduit import Agent
59
+
60
+ # Connect to YOUR self-hosted Conduit instance
61
+ conduit.api_key = "ck_live_..." # an API key from your instance
62
+ conduit.base_url = "https://conduit.example.com" # your Conduit URL
63
+
64
+ # Create an autonomous wallet with an optional spending policy
65
+ agent = Agent.create(name="compute-router-7", daily_limit=50_000)
66
+
67
+ agent.policy.attach(
68
+ max_per_hour=10_000,
69
+ allowlist=["02beef..."],
70
+ )
71
+
72
+ # Send a Lightning payment
73
+ receipt = agent.pay(
74
+ to="compute-node-7@lnd.example.com",
75
+ sats=150,
76
+ memo="dataset query",
77
+ )
78
+
79
+ print(receipt.hash, receipt.settled_in_ms)
80
+ print(receipt.fee_sats, receipt.platform_fee_sats)
81
+ ```
82
+
83
+ ## Client-centric API (`ConduitClient`)
84
+
85
+ Prefer a single client object with explicit methods over the `Agent`
86
+ active-record style? `ConduitClient` wraps the same retrying, idempotent HTTP
87
+ client and adds operator funding (`credit_agent`) — from `pip install` to a
88
+ settled payment in a few lines:
89
+
90
+ ```python
91
+ from conduit import ConduitClient
92
+
93
+ client = ConduitClient(base_url="https://conduit.example.com", api_key="ck_live_...")
94
+
95
+ agent = client.create_agent("compute-router-7")
96
+ client.credit_agent(agent.id, sats=10_000) # operator funds the agent
97
+
98
+ receipt = client.send_payment(agent.id, dest_pubkey="02beef...", sats=500)
99
+ print(receipt.status, receipt.platform_fee_sats) # 'settled', 2
100
+
101
+ print(client.get_balance(agent.id).available) # spendable sats
102
+ for tx in client.list_transactions(agent.id):
103
+ print(tx.direction, tx.amount_sats, tx.status)
104
+ ```
105
+
106
+ Both styles talk to the same instance — use whichever you prefer.
107
+
108
+ ## Platform fee on receipts
109
+
110
+ Every payment receipt includes a **`platform_fee_sats`** field — the per-transaction
111
+ platform fee in satoshis configured by the operator who deployed the instance.
112
+ It is **separate** from `fee_sats` (the LND routing fee):
113
+
114
+ - `fee_sats` — the Lightning Network routing fee paid to route the payment.
115
+ - `platform_fee_sats` — the operator's usage-based revenue, charged on top, kept
116
+ on settle, and refunded in full if the payment fails.
117
+
118
+ The fee is configured on your instance via `PLATFORM_FEE_PERCENT` (default `0.5`%),
119
+ `PLATFORM_FEE_MIN_SATS` (default `1`), and `PLATFORM_FEE_MAX_SATS` (default `1000`).
120
+
121
+ ```python
122
+ receipt = agent.pay(to="...", sats=10_000)
123
+ print(receipt.amount_sats) # 10000
124
+ print(receipt.fee_sats) # LND routing fee
125
+ print(receipt.platform_fee_sats) # your platform's per-tx revenue
126
+ ```
127
+
128
+ ## Configuration
129
+
130
+ The SDK reads `CONDUIT_API_KEY` and `CONDUIT_API_URL` (default
131
+ `https://api.conduit.energy`, the hosted demo console) from the environment.
132
+ Set `CONDUIT_API_URL` to the URL of your own Conduit deployment.
133
+
134
+ ```bash
135
+ export CONDUIT_API_KEY=ck_live_xxxxxxxxxxxxx
136
+ export CONDUIT_API_URL=https://conduit.example.com
137
+ ```
138
+
139
+ or explicitly in code:
140
+
141
+ ```python
142
+ import conduit
143
+ conduit.api_key = "ck_live_..."
144
+ conduit.base_url = "https://conduit.example.com"
145
+ ```
146
+
147
+ ## Errors
148
+
149
+ ```python
150
+ from conduit import PolicyViolation, InsufficientBalance, PaymentFailed
151
+
152
+ try:
153
+ agent.pay(to=..., sats=...)
154
+ except PolicyViolation as e:
155
+ print(e.code, e.message) # e.g. "DAILY_LIMIT_EXCEEDED"
156
+ ```
157
+
158
+ See the full error code list in the API docs.
159
+
160
+ ## Links
161
+
162
+ - Repository: <https://github.com/Jake1848/conduit>
163
+ - License: MIT
@@ -0,0 +1,132 @@
1
+ # conduit-btc
2
+
3
+ Python SDK for **Conduit** — self-hosted, non-custodial Bitcoin Lightning
4
+ payment infrastructure for autonomous AI agents.
5
+
6
+ **Your node, your keys, your rules.** Conduit is software tooling that you run
7
+ on your own infrastructure, against your own LND node, with your own keys. It
8
+ never touches your funds — it's a thin client for *your* Conduit instance.
9
+
10
+ ```bash
11
+ pip install conduit-btc
12
+ ```
13
+
14
+ > The importable package is `conduit`:
15
+ >
16
+ > ```python
17
+ > from conduit import Agent
18
+ > ```
19
+
20
+ ## Quickstart
21
+
22
+ Point the SDK at the Conduit instance you deployed (a 5-minute Docker deploy
23
+ against your own LND node), create an agent, and send a payment:
24
+
25
+ ```python
26
+ import conduit
27
+ from conduit import Agent
28
+
29
+ # Connect to YOUR self-hosted Conduit instance
30
+ conduit.api_key = "ck_live_..." # an API key from your instance
31
+ conduit.base_url = "https://conduit.example.com" # your Conduit URL
32
+
33
+ # Create an autonomous wallet with an optional spending policy
34
+ agent = Agent.create(name="compute-router-7", daily_limit=50_000)
35
+
36
+ agent.policy.attach(
37
+ max_per_hour=10_000,
38
+ allowlist=["02beef..."],
39
+ )
40
+
41
+ # Send a Lightning payment
42
+ receipt = agent.pay(
43
+ to="compute-node-7@lnd.example.com",
44
+ sats=150,
45
+ memo="dataset query",
46
+ )
47
+
48
+ print(receipt.hash, receipt.settled_in_ms)
49
+ print(receipt.fee_sats, receipt.platform_fee_sats)
50
+ ```
51
+
52
+ ## Client-centric API (`ConduitClient`)
53
+
54
+ Prefer a single client object with explicit methods over the `Agent`
55
+ active-record style? `ConduitClient` wraps the same retrying, idempotent HTTP
56
+ client and adds operator funding (`credit_agent`) — from `pip install` to a
57
+ settled payment in a few lines:
58
+
59
+ ```python
60
+ from conduit import ConduitClient
61
+
62
+ client = ConduitClient(base_url="https://conduit.example.com", api_key="ck_live_...")
63
+
64
+ agent = client.create_agent("compute-router-7")
65
+ client.credit_agent(agent.id, sats=10_000) # operator funds the agent
66
+
67
+ receipt = client.send_payment(agent.id, dest_pubkey="02beef...", sats=500)
68
+ print(receipt.status, receipt.platform_fee_sats) # 'settled', 2
69
+
70
+ print(client.get_balance(agent.id).available) # spendable sats
71
+ for tx in client.list_transactions(agent.id):
72
+ print(tx.direction, tx.amount_sats, tx.status)
73
+ ```
74
+
75
+ Both styles talk to the same instance — use whichever you prefer.
76
+
77
+ ## Platform fee on receipts
78
+
79
+ Every payment receipt includes a **`platform_fee_sats`** field — the per-transaction
80
+ platform fee in satoshis configured by the operator who deployed the instance.
81
+ It is **separate** from `fee_sats` (the LND routing fee):
82
+
83
+ - `fee_sats` — the Lightning Network routing fee paid to route the payment.
84
+ - `platform_fee_sats` — the operator's usage-based revenue, charged on top, kept
85
+ on settle, and refunded in full if the payment fails.
86
+
87
+ The fee is configured on your instance via `PLATFORM_FEE_PERCENT` (default `0.5`%),
88
+ `PLATFORM_FEE_MIN_SATS` (default `1`), and `PLATFORM_FEE_MAX_SATS` (default `1000`).
89
+
90
+ ```python
91
+ receipt = agent.pay(to="...", sats=10_000)
92
+ print(receipt.amount_sats) # 10000
93
+ print(receipt.fee_sats) # LND routing fee
94
+ print(receipt.platform_fee_sats) # your platform's per-tx revenue
95
+ ```
96
+
97
+ ## Configuration
98
+
99
+ The SDK reads `CONDUIT_API_KEY` and `CONDUIT_API_URL` (default
100
+ `https://api.conduit.energy`, the hosted demo console) from the environment.
101
+ Set `CONDUIT_API_URL` to the URL of your own Conduit deployment.
102
+
103
+ ```bash
104
+ export CONDUIT_API_KEY=ck_live_xxxxxxxxxxxxx
105
+ export CONDUIT_API_URL=https://conduit.example.com
106
+ ```
107
+
108
+ or explicitly in code:
109
+
110
+ ```python
111
+ import conduit
112
+ conduit.api_key = "ck_live_..."
113
+ conduit.base_url = "https://conduit.example.com"
114
+ ```
115
+
116
+ ## Errors
117
+
118
+ ```python
119
+ from conduit import PolicyViolation, InsufficientBalance, PaymentFailed
120
+
121
+ try:
122
+ agent.pay(to=..., sats=...)
123
+ except PolicyViolation as e:
124
+ print(e.code, e.message) # e.g. "DAILY_LIMIT_EXCEEDED"
125
+ ```
126
+
127
+ See the full error code list in the API docs.
128
+
129
+ ## Links
130
+
131
+ - Repository: <https://github.com/Jake1848/conduit>
132
+ - License: MIT
@@ -0,0 +1,64 @@
1
+ """Conduit — Bitcoin Lightning payments for autonomous AI agents.
2
+
3
+ from conduit import Agent, Policy
4
+
5
+ agent = Agent.create(name="compute-router-7", daily_limit=50_000)
6
+ agent.policy.attach(max_per_hour=10_000, allowlist=["02beef..."])
7
+ receipt = agent.pay(to="compute-node-7@lnd.conduit.energy", sats=150, memo="dataset")
8
+ print(receipt.hash, receipt.settled_in_ms)
9
+ """
10
+
11
+ from .agent import Agent, Balance, LedgerAdjustment
12
+ from .client import Conduit, default_client, set_default_client
13
+ from .conduit_client import ConduitClient
14
+ from .errors import (
15
+ AgentNotFound,
16
+ AuthenticationError,
17
+ ConduitError,
18
+ InsufficientBalance,
19
+ PaymentFailed,
20
+ PermissionDenied,
21
+ PolicyViolation,
22
+ RateLimited,
23
+ WebhookVerificationError,
24
+ )
25
+ from .invoice import Invoice
26
+ from .payment import Receipt
27
+ from .policy import Policy
28
+ from .transaction import Transaction
29
+ from .webhook import parse_webhook, verify_webhook
30
+
31
+ # Module-level config — populated from CONDUIT_API_KEY / CONDUIT_API_URL env vars
32
+ # lazily on first use. See client.py.
33
+ api_key: str | None = None
34
+ base_url: str | None = None
35
+
36
+ __version__ = "0.8.4"
37
+
38
+ __all__ = [
39
+ "Agent",
40
+ "ConduitClient",
41
+ "Conduit",
42
+ "Balance",
43
+ "LedgerAdjustment",
44
+ "default_client",
45
+ "set_default_client",
46
+ "Policy",
47
+ "Receipt",
48
+ "Invoice",
49
+ "Transaction",
50
+ "ConduitError",
51
+ "AuthenticationError",
52
+ "PermissionDenied",
53
+ "PolicyViolation",
54
+ "InsufficientBalance",
55
+ "PaymentFailed",
56
+ "AgentNotFound",
57
+ "RateLimited",
58
+ "WebhookVerificationError",
59
+ "verify_webhook",
60
+ "parse_webhook",
61
+ "api_key",
62
+ "base_url",
63
+ "__version__",
64
+ ]
@@ -0,0 +1,263 @@
1
+ from __future__ import annotations
2
+
3
+ import uuid
4
+ from dataclasses import dataclass
5
+ from datetime import datetime
6
+ from typing import Any
7
+
8
+ from .client import Conduit, default_client
9
+ from .invoice import Invoice
10
+ from .payment import Receipt, _parse_dt
11
+ from .policy import Policy
12
+ from .transaction import Transaction
13
+
14
+
15
+ def _new_idempotency_key() -> str:
16
+ return str(uuid.uuid4())
17
+
18
+
19
+ @dataclass
20
+ class Balance:
21
+ available: int
22
+ pending: int
23
+ total: int
24
+
25
+
26
+ @dataclass
27
+ class LedgerAdjustment:
28
+ """Result of an operator credit/debit on an agent's virtual balance."""
29
+
30
+ agent_id: str
31
+ transaction_id: str
32
+ delta_sats: int # positive = credit, negative = debit
33
+ balance_sats: int
34
+
35
+ @classmethod
36
+ def from_api(cls, data: dict[str, Any]) -> "LedgerAdjustment":
37
+ return cls(
38
+ agent_id=data["agent_id"],
39
+ transaction_id=data["transaction_id"],
40
+ delta_sats=int(data["delta_sats"]),
41
+ balance_sats=int(data["balance_sats"]),
42
+ )
43
+
44
+
45
+ class Agent:
46
+ """An autonomous wallet with optional spending policy.
47
+
48
+ Mirrors the website code panel:
49
+
50
+ agent = Agent.create(name="compute-router-7", daily_limit=50_000)
51
+ agent.policy.attach(max_per_hour=10_000, allowlist=["02beef..."])
52
+ receipt = agent.pay(to="compute-node-7@lnd.conduit.energy",
53
+ sats=150, memo="dataset query")
54
+ """
55
+
56
+ def __init__(
57
+ self,
58
+ *,
59
+ id: str,
60
+ name: str,
61
+ pubkey: str | None,
62
+ active: bool,
63
+ created_at: datetime,
64
+ client: Conduit | None = None,
65
+ ) -> None:
66
+ self.id = id
67
+ self.name = name
68
+ self.pubkey = pubkey
69
+ self.active = active
70
+ self.created_at = created_at
71
+ self._client = client or default_client()
72
+ self.policy = Policy(self, client=self._client)
73
+
74
+ # --- factory methods ---
75
+
76
+ @classmethod
77
+ def create(
78
+ cls,
79
+ name: str,
80
+ daily_limit: int | None = None,
81
+ metadata: dict[str, Any] | None = None,
82
+ *,
83
+ client: Conduit | None = None,
84
+ ) -> "Agent":
85
+ c = client or default_client()
86
+ payload: dict[str, Any] = {"name": name}
87
+ if daily_limit is not None:
88
+ payload["daily_limit"] = daily_limit
89
+ if metadata is not None:
90
+ payload["metadata"] = metadata
91
+ data = c.post("/v1/agents", json=payload)
92
+ return cls._from_api(data, client=c)
93
+
94
+ @classmethod
95
+ def get(cls, agent_id: str, *, client: Conduit | None = None) -> "Agent":
96
+ c = client or default_client()
97
+ data = c.get(f"/v1/agents/{agent_id}")
98
+ return cls._from_api(data, client=c)
99
+
100
+ @classmethod
101
+ def list(cls, *, client: Conduit | None = None) -> list["Agent"]:
102
+ c = client or default_client()
103
+ # The API paginates /v1/agents (default 50, max 500). Page through with
104
+ # has_more so the whole fleet is returned, never silently truncated (M7).
105
+ items: list[dict[str, Any]] = []
106
+ offset = 0
107
+ for _ in range(200): # safety cap (100k agents)
108
+ data = c.get("/v1/agents", params={"limit": 500, "offset": offset})
109
+ page = data.get("data", [])
110
+ items.extend(page)
111
+ if not data.get("has_more") or not page:
112
+ break
113
+ offset += 500
114
+ return [cls._from_api(item, client=c) for item in items]
115
+
116
+ @classmethod
117
+ def _from_api(cls, data: dict[str, Any], client: Conduit) -> "Agent":
118
+ return cls(
119
+ id=data["id"],
120
+ name=data["name"],
121
+ pubkey=data.get("pubkey"),
122
+ active=bool(data.get("active", True)),
123
+ created_at=_parse_dt(data["created_at"]),
124
+ client=client,
125
+ )
126
+
127
+ # --- actions ---
128
+
129
+ def pay(
130
+ self,
131
+ *,
132
+ to: str,
133
+ sats: int,
134
+ memo: str | None = None,
135
+ metadata: dict[str, Any] | None = None,
136
+ idempotency_key: str | None = None,
137
+ ) -> Receipt:
138
+ """Pay a Lightning address (`name@host`) or a BOLT11 invoice.
139
+
140
+ An `Idempotency-Key` is sent automatically (a fresh UUID4 if you don't
141
+ provide one) so an automatic retry can never double-pay. Pass an
142
+ explicit `idempotency_key` to make a manual retry idempotent too.
143
+ """
144
+ data = self._client.post(
145
+ "/v1/payments/pay",
146
+ json={
147
+ "agent_id": self.id,
148
+ "to": to,
149
+ "sats": sats,
150
+ "memo": memo,
151
+ "metadata": metadata,
152
+ },
153
+ idempotency_key=idempotency_key or _new_idempotency_key(),
154
+ )
155
+ return Receipt.from_api(data)
156
+
157
+ def send_invoice(
158
+ self,
159
+ payment_request: str,
160
+ *,
161
+ sats: int | None = None,
162
+ memo: str | None = None,
163
+ idempotency_key: str | None = None,
164
+ ) -> Receipt:
165
+ """Pay a BOLT11 invoice (or zero-amount invoice with explicit sats)."""
166
+ data = self._client.post(
167
+ "/v1/payments/send",
168
+ json={
169
+ "agent_id": self.id,
170
+ "payment_request": payment_request,
171
+ "sats": sats,
172
+ "memo": memo,
173
+ },
174
+ idempotency_key=idempotency_key or _new_idempotency_key(),
175
+ )
176
+ return Receipt.from_api(data)
177
+
178
+ def keysend(
179
+ self,
180
+ dest_pubkey: str,
181
+ sats: int,
182
+ *,
183
+ memo: str | None = None,
184
+ idempotency_key: str | None = None,
185
+ ) -> Receipt:
186
+ data = self._client.post(
187
+ "/v1/payments/send",
188
+ json={
189
+ "agent_id": self.id,
190
+ "dest_pubkey": dest_pubkey,
191
+ "sats": sats,
192
+ "memo": memo,
193
+ },
194
+ idempotency_key=idempotency_key or _new_idempotency_key(),
195
+ )
196
+ return Receipt.from_api(data)
197
+
198
+ def receive(
199
+ self, amount: int, *, memo: str | None = None, expiry: int = 3600
200
+ ) -> Invoice:
201
+ """Create a Lightning invoice that other agents/services can pay."""
202
+ data = self._client.post(
203
+ "/v1/invoices",
204
+ json={"agent_id": self.id, "amount": amount, "memo": memo, "expiry": expiry},
205
+ )
206
+ return Invoice.from_api(data)
207
+
208
+ def credit(
209
+ self,
210
+ sats: int,
211
+ *,
212
+ reason: str | None = None,
213
+ metadata: dict[str, Any] | None = None,
214
+ ) -> "LedgerAdjustment":
215
+ """Operator top-up: credit this agent's virtual balance from the
216
+ operator's own node liquidity. Requires an admin-scope key."""
217
+ payload: dict[str, Any] = {"sats": sats}
218
+ if reason is not None:
219
+ payload["reason"] = reason
220
+ if metadata is not None:
221
+ payload["metadata"] = metadata
222
+ data = self._client.post(f"/v1/agents/{self.id}/credit", json=payload)
223
+ return LedgerAdjustment.from_api(data)
224
+
225
+ def debit(
226
+ self,
227
+ sats: int,
228
+ *,
229
+ reason: str | None = None,
230
+ metadata: dict[str, Any] | None = None,
231
+ ) -> "LedgerAdjustment":
232
+ """Operator sweep: debit this agent's virtual balance back to the
233
+ operator's treasury. Requires an admin-scope key."""
234
+ payload: dict[str, Any] = {"sats": sats}
235
+ if reason is not None:
236
+ payload["reason"] = reason
237
+ if metadata is not None:
238
+ payload["metadata"] = metadata
239
+ data = self._client.post(f"/v1/agents/{self.id}/debit", json=payload)
240
+ return LedgerAdjustment.from_api(data)
241
+
242
+ @property
243
+ def balance(self) -> Balance:
244
+ data = self._client.get(f"/v1/agents/{self.id}/balance")
245
+ return Balance(
246
+ available=int(data["available_sats"]),
247
+ pending=int(data["pending_sats"]),
248
+ total=int(data["total_sats"]),
249
+ )
250
+
251
+ def transactions(self, *, limit: int = 50, direction: str | None = None) -> list[Transaction]:
252
+ params: dict[str, Any] = {"limit": limit}
253
+ if direction:
254
+ params["direction"] = direction
255
+ data = self._client.get(f"/v1/agents/{self.id}/transactions", params=params)
256
+ return [Transaction.from_api(item) for item in data.get("data", [])]
257
+
258
+ def deactivate(self) -> None:
259
+ self._client.delete(f"/v1/agents/{self.id}")
260
+ self.active = False
261
+
262
+ def __repr__(self) -> str:
263
+ return f"<Agent id={self.id!r} name={self.name!r} active={self.active}>"