Skip to main content

LangChain integration for VDM Nexus — signed-inference ChatModel that pays per call via x402 on Solana.

Project description

langchain-vdm-nexus

LangChain integration for VDM Nexus — signed-inference ChatModel that pays per call via x402 on Solana. No API keys, just an Ed25519 keypair.

ChatNexus is a drop-in subclass of langchain_core.language_models.chat_models.BaseChatModel. It runs the x402 v2 handshake transparently (probe → 402 → sign SPL USDC transfer → paid retry) and exposes the resulting Signed Inference Receipt and on-chain payment metadata on every response.

Install

pip install langchain-vdm-nexus

Two runtime deps: vdm-nexus (≥ 0.2.0) and langchain-core (≥ 0.3).

Use

import os
from langchain_vdm_nexus import ChatNexus
from langchain_core.messages import HumanMessage

llm = ChatNexus(
    secret_key=os.environ["AGENT_SECRET_KEY"],   # base58 64-byte Ed25519
    endpoint="https://nexus.vdmnexus.com/api/v1",
    model="openai/gpt-4o-mini",
    network="solana:mainnet",                    # or "solana:devnet"
)

reply = llm.invoke([HumanMessage(content="Why Ed25519?")])
print(reply.content)

A real mainnet receipt produced by this exact call shape: vdmnexus.com/r/c9710ea7-9e1f-46ee-aaa9-903a536ae12e.

Receipt access

The Signed Inference Receipt (SIR v2) and the x402 payment response are attached to every AIMessage:

reply = llm.invoke([HumanMessage(content="hello")])

receipt = reply.response_metadata["nexus_receipt"]
print("tx:        ", receipt["payment"]["tx_signature"])
print("paid:      ", receipt["payment"]["amount_usdc"], "USDC")
print("model:     ", receipt["model"])
print("hash:      ", receipt["response_hash"])

payment = reply.response_metadata["nexus_payment"]
print("settled at:", payment["txSignature"], "on", payment["network"])

Each receipt is cryptographically signed by the Nexus operator key and can be verified independently — see verify.vdmnexus.com or the @vdm-nexus/x402 TS verifier.

Async

ChatNexus implements both _generate and _agenerate. Use ainvoke, abatch, astream (single-chunk; see Streaming below) as normal:

reply = await llm.ainvoke([HumanMessage(content="hi")])

Compatibility

LangChain's BaseChatModel is the substrate that LangGraph nodes and CrewAI agents call into. ChatNexus works as-is in:

  • LangChain chains (llm | prompt | parser).
  • LangGraph — pass the model into any node that accepts a chat model. Receipts surface on the node's output state via last_message.response_metadata["nexus_receipt"].
  • CrewAI — use as the agent's llm. Every tool-call and reasoning step routes through Nexus and emits a receipt.

Native LangGraph and CrewAI sub-packages may follow if there's adoption demand, but neither needs one — ChatNexus is sufficient.

Streaming

Not implemented in v0.1.0. The upstream /chat/completions endpoint does not emit SSE chunks today. Calls into stream / astream will fall through to the default BaseChatModel behaviour: a single chunk containing the full response. Native streaming will arrive once the Nexus rail supports it.

How payment works

Each invoke runs the x402 v2 two-roundtrip handshake:

  1. POST /chat/completions — server replies 402 with an X-Payment-Required challenge declaring the price (USDC) and recipient.
  2. Build a partially-signed SPL TransferChecked transaction (via solders) for that price, signed by your Ed25519 keypair.
  3. POST again with X-Payment: <base64> — the server's facilitator co-signs as fee payer, broadcasts to Solana, runs inference, and returns the OpenAI body plus X-Nexus-Receipt and X-Payment-Response headers.

The agent's wallet is yours; Nexus never holds private keys.

License

MIT. See LICENSE.

Repo

Source lives in the VDM Nexus monorepo under packages/sdk-python-langchain.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_vdm_nexus-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_vdm_nexus-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file langchain_vdm_nexus-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_vdm_nexus-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.14.2 HTTPX/0.28.1

File hashes

Hashes for langchain_vdm_nexus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b52767643e08624fa9775dcffce4397969a64b5ff3c50f15691e52afbc72dcf2
MD5 a9d09e7933635227aa1fa6a355c713f0
BLAKE2b-256 1591348788984c0c5d8a89ae058d074cec1d3f858aff025f1f8b3fbb48d1b905

See more details on using hashes here.

File details

Details for the file langchain_vdm_nexus-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_vdm_nexus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03a3f1773c7e93d25c02b9b66e9b18423c189e769615c18dd02f022fe205fa48
MD5 aaf57a7eca1f942fa6ec1a5b01f0d567
BLAKE2b-256 fce88dd82a4581764941b0786ee2fefd765fd3dd1bf1647e273256e4ff11ba58

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page