Nory LangChain Tools
Give your LangChain agents the ability to pay.
Nory LangChain Tools provides a set of LangChain-compatible tools that enable AI agents to make instant payments using the x402 protocol. Payments settle on Solana in under 1 second.
Installation
pip install nory-langchain
Quick Start
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from nory_langchain import get_nory_tools
# Initialize LLM
llm = ChatOpenAI(model="gpt-4")
# Get all Nory payment tools
tools = get_nory_tools()
# Create agent with payment capabilities
agent = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
verbose=True
)
# Your agent can now make payments!
agent.run("Check my Nory wallet balance")
agent.run("Pay 5 USDC to GkXn...abc for the API access")
agent.run("Use x402 to fetch data from https://api.example.com/premium-data")
Configuration
Set your environment variables:
export NORY_WALLET_KEY="your-solana-wallet-private-key"
export NORY_API_URL="https://api.noryx402.com" # Optional, this is the default
Available Tools
nory_check_balance
Check your wallet balance before making payments.
from nory_langchain import NoryCheckBalanceTool
tool = NoryCheckBalanceTool()
result = tool.run({"currency": "USDC"})
nory_pay
Make direct payments to any Solana wallet address.
from nory_langchain import NoryPayTool
tool = NoryPayTool()
result = tool.run({
"recipient": "GkXn9FqJ4pT1qVz8hQJ9X5...",
"amount": 5.0,
"memo": "Payment for API access"
})
nory_x402_request
Access x402-enabled APIs with automatic payment handling. When the server returns HTTP 402 (Payment Required), Nory automatically pays and retries.
from nory_langchain import NoryX402RequestTool
tool = NoryX402RequestTool()
result = tool.run({
"url": "https://api.noryx402.com/data/crypto",
"method": "GET"
})
nory_discover_services
Find available x402-enabled services and APIs.
from nory_langchain import NoryDiscoverServicesTool
tool = NoryDiscoverServicesTool()
result = tool.run({
"category": "ai",
"max_price": 0.01
})
nory_payment_history
View your recent payment transactions.
from nory_langchain import NoryPaymentHistoryTool
tool = NoryPaymentHistoryTool()
result = tool.run({"limit": 10})
Using with Different Agent Types
ReAct Agent
from langchain.agents import create_react_agent
from langchain import hub
from nory_langchain import get_nory_tools
prompt = hub.pull("hwchase17/react")
tools = get_nory_tools()
agent = create_react_agent(llm, tools, prompt)
OpenAI Functions Agent
from langchain.agents import create_openai_functions_agent
from langchain import hub
from nory_langchain import get_nory_tools
prompt = hub.pull("hwchase17/openai-functions-agent")
tools = get_nory_tools()
agent = create_openai_functions_agent(llm, tools, prompt)
Tool Calling Agent (Recommended)
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from nory_langchain import get_nory_tools
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant with payment capabilities."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
tools = get_nory_tools()
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
executor.invoke({"input": "Check my balance and pay 1 USDC to Alice"})
How x402 Works
- Request - Agent makes HTTP request to x402-enabled endpoint
- 402 Response - Server returns HTTP 402 with payment requirements
- Payment - Nory creates and signs a Solana transaction
- Settlement - Transaction confirms in ~400ms
- Access - Agent retries with payment proof, receives the resource
All of this happens automatically when using nory_x402_request.
Use Cases
- API Access: Pay-per-call access to premium APIs
- AI Services: Pay for model inference, image generation
- Data Feeds: Access premium market data, research reports
- Compute: Purchase serverless compute, GPU time
- Agent-to-Agent: Agents paying other agents for services
Security
- Non-custodial: Your private key stays on your machine
- Per-transaction limits: Configure maximum payment amounts
- Audit logging: All transactions are logged
Links
License
MIT
Metadata
Release files for nory-langchain 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nory_langchain-0.1.0.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nory_langchain-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.4 kB
Release files / nory_langchain-0.1.0.tar.gz
| Download URL | nory_langchain-0.1.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ae17395eeef1e7055f22ab37e0246c5e659e12bea2b4a8f00c7e5d66a78248e
|
|
BLAKE2b-256 checksum How to use checksums |
41764443ef98042906aedd55d9796f3ee8bd127f5c5753a38af126e98535e287
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.3
|
Release files / nory_langchain-0.1.0-py3-none-any.whl
| Download URL | nory_langchain-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bdbcfea4ae6136e98cf6419d963afa9a5c55f986cc6f38cf81bdb72e2ca867f
|
|
BLAKE2b-256 checksum How to use checksums |
9149df1bccadccd7a95b308d86ee1f1dd0705042ccec8928fd6664abc41362b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.3
|