Metadata-Version: 2.4
Name: prismnetwork
Version: 0.3.2
Summary: Headless GPU leasing on Prism Network for autonomous agents. Wallet-signature auth, on-chain USDG payment, SSH.
Project-URL: Homepage, https://prismnetwork.tech
Project-URL: Source, https://github.com/prismnetwork-tech/prism
License-Expression: Apache-2.0
Keywords: agent,gpu,llm,prism,usdg,web3
Requires-Python: >=3.10
Requires-Dist: eth-account>=0.11
Requires-Dist: requests>=2.31
Requires-Dist: web3>=6.0
Description-Content-Type: text/markdown

# prismnetwork

Headless GPU leasing on [Prism Network](https://prismnetwork.tech) for autonomous
agents, the Python counterpart to `@prismnetwork/agent-sdk`. Give it a wallet; it
authenticates with a signature, pays on-chain in USDG, provisions a GPU, and runs
over SSH. No browser, no dashboard.

```sh
pip install prismnetwork
```

```python
from prismnetwork import PrismAgent, DEFAULT_IMAGE

agent = PrismAgent(private_key=AGENT_KEY, escrow="0xfD4228eEEfC49e4b76A0CD40af9fdd546220B2FD")
agent.authenticate()

lease = agent.lease(image=DEFAULT_IMAGE, duration_seconds=600, min_vram_mib=16000)
out = agent.run(lease, "nvidia-smi")
print(out["stdout"])
agent.end_lease(lease)
```

## What it does

`authenticate()` signs a challenge with the wallet and exchanges it for a bearer
session. `lease()` gets a quote, funds an on-chain USDG escrow bound to the quote
(`createLease`), waits for the GPU to provision, and returns SSH access. `run()`
executes a command over SSH, retrying through the host's sshd warmup. Metering is
per-second; each lease settles on-chain with a verifiable receipt.

Read-only helpers: `offers()`, `balances()`, `leases()`, `quote(...)`, `access(id)`.

## Which machine answered

Every session `run()` opens checks the SSH host key on the far end, and
`host_key_policy(lease.access)` says what that check was worth:

```python
from prismnetwork import host_key_policy

host_key_policy(lease.access)
# {"mode": "attested" | "reported" | "unverified", "fingerprint": ..., "source": ...}
```

`attested` means the fingerprint comes out of a hardware report whose signed data
commits to the key the guest generated at boot. Prism walks that report and puts
the fingerprint on the access grant, and the SDK refuses a session whose host key
does not match it, so the operator cannot put a different machine on the other
end. The report is checked in our control plane rather than here, so `attested`
says we checked it and this client holds the session to what we published.

`reported` means the node named the key on the signed report that opened
access, which rules out the relay and the network path but not the operator,
whose bond is what a dispute reaches instead.

`unverified` means nobody published a key: capacity brokered from a public
cloud has its host key generated by the cloud and never shown to the network, so
the key is recorded on first sight and held for the rest of the lease.

Your own `~/.ssh/known_hosts` is never touched. The record sits beside the
lease's private key and is removed with it by `end_lease()`.

`PrismAgent(..., require_host_key=True)` refuses to open a session on a lease
that publishes no key, rather than trusting whichever machine answers first.

## Batch

Pass `command=` to `lease()` and the node runs that one command and reports its
output instead of granting SSH access:

```python
batch = agent.lease(image=DEFAULT_IMAGE, duration_seconds=600, command="nvidia-smi")
print(batch.result["stdout"])
```

Batch leases match only suppliers at trust class `isolated` or above, because the
broker path has no signed result channel. Commands are capped at 8 KiB and output
at 64 KiB per stream. `result(lease_id)` and `wait_for_result(lease_id)` read the
output of an already-funded batch lease.

## Paying an x402 endpoint

Prism's pay-per-call endpoints take a transfer plus a signature over what the
transfer buys, so a payment can only be redeemed against the request it was made
for. `payment_header` builds the `X-PAYMENT` value:

```python
from prismnetwork import payment_header

body = json.dumps({"model": "llama3.2:3b", "prompt": "what is a prism"}).encode()
header = payment_header(agent.account, tx_hash, body)
```

Pass the bytes the request actually carries. `bound_message` and `hash_request`
are exported for a client that builds the envelope itself; they produce the same
message the Node SDK signs.

The wallet needs USDG (`0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168`, 6 decimals) and
native Robinhood-Chain gas.

Requires `ssh`, `ssh-keygen` and `ssh-keyscan` on `PATH`. Chain id 4663, RPC
`https://rpc.mainnet.chain.robinhood.com`.

Prism is pre-production and unaudited. A permissionless supplier is not a trusted
computing environment; do not lease with a wallet or workload you cannot lose.
