Python SDK for VDM Nexus — autonomous AI agents that authenticate and pay for compute with a Solana keypair. No API keys.
Project description
vdm-nexus
Python SDK for VDM Nexus — autonomous AI agents that authenticate and pay for compute with a Solana keypair. No API keys.
Mirror of @vdm-nexus/sdk
(TypeScript). Same identity, same wire format, same receipt shape.
Install
pip install vdm-nexus
Four runtime deps: pynacl, base58, httpx, solders.
Use
import asyncio
from vdm_nexus import Agent
async def main() -> None:
# Generate a fresh agent — or load from a secret key string.
agent = Agent.generate()
# agent = Agent.from_base58(os.environ["AGENT_SECRET_KEY"])
print("agent pubkey:", agent.pubkey)
reply = await agent.inference(
"https://nexus.vdmnexus.com/api/v1",
prompt="Explain Ed25519 signatures in one sentence.",
task_type="fast", # "fast" | "reasoning" | "general"
)
print(reply.get("result"))
if "receipt" in reply:
print("cost:", reply["receipt"]["cost_usdc"], "USDC")
print("balance:", reply["receipt"]["balance_remaining"], "USDC")
asyncio.run(main())
x402 — pay per call
v0.2 adds X402Agent, which speaks the x402 v2 protocol
against /v1/chat/completions. Same Ed25519 identity, settles in USDC
on Solana per request. Returns the standard OpenAI chat-completion body
plus a parsed Signed Inference Receipt.
import asyncio
import os
from vdm_nexus import X402Agent
async def main() -> None:
agent = X402Agent.from_base58(os.environ["AGENT_SECRET_KEY"])
result = await agent.pay_and_infer(
"https://nexus.vdmnexus.com/api/v1",
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Why Ed25519?"}],
network="solana:mainnet", # or "solana:devnet"
)
print(result.openai["choices"][0]["message"]["content"])
print("tx:", result.receipt["payment"]["tx_signature"])
print("paid:", result.receipt["payment"]["amount_usdc"], "USDC")
asyncio.run(main())
A real mainnet receipt from this exact flow:
vdmnexus.com/r/c9710ea7-9e1f-46ee-aaa9-903a536ae12e.
Under the hood, pay_and_infer runs the x402 two-roundtrip handshake:
- POST the request body — server replies
402with anX-Payment-Requiredchallenge. - Build a partially-signed SPL USDC
TransferCheckedtransaction (viasolders) for the declaredpayTo, encode as base64. - POST again with
X-Payment: <base64>— server settles via its facilitator, runs inference, returns the OpenAI body plusX-Nexus-ReceiptandX-Payment-Responseheaders.
The agent's wallet is theirs; Nexus never holds private keys.
How it works
Every request is signed with the agent's Ed25519 secret key. The Nexus server verifies the signature against the agent's public key over the raw body bytes, checks the nonce hasn't been reused, checks the timestamp is fresh, debits the agent's USDC balance, and returns the completion plus a tamper-proof receipt.
There are no API keys to rotate, leak, or scope. The public key is the identity.
API
Agent.generate() -> Agent
Generate a fresh Ed25519 keypair.
Agent.from_base58(secret_key_base58: str) -> Agent
Load an agent from a base58-encoded 64-byte secret key.
agent.pubkey: str
The agent's base58-encoded public key. This is the identity.
agent.secret_key_base58: str
The agent's full base58-encoded secret key. Treat as a password. Never log this or commit it to source control.
await agent.inference(endpoint, *, prompt, task_type=..., max_cost_usdc=..., auto_grant=True) -> dict
Make a signed inference request to a Nexus endpoint. Returns a dict
mirroring the JSON response — {"ok", "result"?, "receipt"?, "error"?, "detail"?} — with the receipt fields matching SIR v2.
await agent.grant(endpoint) -> dict
Request a sponsored USDC grant for this agent's pubkey. One grant per
pubkey ever. Auto-called by inference() when the balance is zero;
pass auto_grant=False to opt out.
agent.sign_body(body: bytes) -> str
Lower-level: sign arbitrary body bytes and return the base58 signature. Useful when building your own request flow. Sign the EXACT bytes you will send — the server re-derives the signature against the bytes it receives.
Scope
- v0.1: the
Agentclass. Signed inference against/v1/inference. Auto-grant on first call. - v0.2 (this release): adds
X402Agent— pay-per-call inference against/v1/chat/completionswith on-chain USDC settlement on Solana mainnet or devnet. - v0.3:
verify_receipt— port of the five-check verifier from@vdm-nexus/x402. Also Base (EVM) support inpay_and_infer. - Separate package (
vdm-nexus-wallet): on-chain wallet operations (deposits, transfers). Pulls in heavier Solana dependencies; kept out of the core SDK so the dependency surface stays small.
Framework integrations
langchain-vdm-nexus— drop-inChatNexusmodel for LangChain (and by extension LangGraph, CrewAI, and any framework built onBaseChatModel).
Repo
Source lives in the monorepo
under packages/sdk-python.
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 vdm_nexus-0.2.2.tar.gz.
File metadata
- Download URL: vdm_nexus-0.2.2.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.14.2 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fbd0376a5bc35a838da93a541e9eef5cd7ea5bbde0b5bf494d8b88b3af86564
|
|
| MD5 |
7805ede9025f7154a7fc560873919304
|
|
| BLAKE2b-256 |
23b6c9d2c943782fd268d14ee13fd24a31baa086cb387b68171a836941eeab74
|
File details
Details for the file vdm_nexus-0.2.2-py3-none-any.whl.
File metadata
- Download URL: vdm_nexus-0.2.2-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.14.2 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f6e299f6b06c8c1e7c7c5105f1e4cc515c889e8f2905a43560c90454270212c
|
|
| MD5 |
28a8e87fe02834049621379cea00eab5
|
|
| BLAKE2b-256 |
cb6d817c3be5fb25128e2fa3e213a32fb482fc827731963244c49a117ebfe7c4
|