Skip to main content

LangChain tools for x402 payments - let agents pay for APIs autonomously

Project description

langchain-nory

LangChain tools for x402 payments - Let your agents pay for APIs autonomously.

PyPI version License: MIT

Overview

langchain-nory provides LangChain tools that enable AI agents to:

  • Pay for x402-protected APIs automatically when they encounter HTTP 402 responses
  • Access pre-built paid APIs for crypto prices, weather, translation, and more
  • Make direct payments to any Solana or EVM wallet

All payments use USDC stablecoin on Solana (~400ms settlement) or EVM chains.

Installation

pip install langchain-nory

Quick Start

from langchain_nory import get_nory_tools
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor

# Get all Nory tools (uses NORY_WALLET_KEY env var)
tools = get_nory_tools()

# Or configure with explicit wallet key
tools = get_nory_tools(wallet_key="your-solana-private-key")

# Create agent with tools
llm = ChatOpenAI(model="gpt-4")
agent = create_react_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

# Agent can now pay for APIs!
result = executor.invoke({"input": "What's the current price of Bitcoin?"})

Available Tools

Core Tools

Tool Description Cost
NoryFetchTool Fetch any URL with automatic x402 payment handling Varies
NoryPaymentTool Make direct USDC payments to any wallet 0.1% fee

Pre-built Paid API Tools

Tool Description Cost per request
NoryCryptoPricesTool Real-time crypto prices (BTC, ETH, SOL, etc.) $0.001
NoryWeatherTool Weather + 7-day forecast for any city $0.002
NoryTranslateTool Translate between 20+ languages $0.005
NoryQRCodeTool Generate QR codes $0.001
NoryWebSummaryTool Extract text from any webpage $0.01

Individual Tool Usage

Fetch Any Paid API

from langchain_nory import NoryFetchTool

tool = NoryFetchTool(wallet_key="your-key")

# Automatically pays if the API requires it
result = tool.run("https://api.example.com/premium-data")

Get Crypto Prices

from langchain_nory import NoryCryptoPricesTool

tool = NoryCryptoPricesTool(wallet_key="your-key")
result = tool.run("BTC,ETH,SOL")
# {"BTC": {"price": 45000.50, ...}, "ETH": {...}, "SOL": {...}}

Get Weather

from langchain_nory import NoryWeatherTool

tool = NoryWeatherTool(wallet_key="your-key")
result = tool.run("London")
# {"current": {"temp": 15, "condition": "Cloudy"}, "forecast": [...]}

Translate Text

from langchain_nory import NoryTranslateTool

tool = NoryTranslateTool(wallet_key="your-key")
result = tool.run(text="Hello world", to_lang="es")
# {"translation": "Hola mundo", "from": "en", "to": "es"}

Environment Variables

export NORY_WALLET_KEY="your-solana-private-key"

With CrewAI

from crewai import Agent, Task, Crew
from langchain_nory import get_nory_tools

tools = get_nory_tools()

researcher = Agent(
    role="Market Researcher",
    goal="Get real-time crypto market data",
    tools=tools,
    verbose=True
)

task = Task(
    description="Get the current prices of BTC, ETH, and SOL",
    agent=researcher
)

crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()

How x402 Payment Works

  1. Agent requests a paid API endpoint
  2. Server returns 402 Payment Required with payment requirements
  3. NoryFetchTool creates and signs a USDC transfer transaction
  4. Transaction is sent to Nory for settlement (~400ms)
  5. Agent retries request with X-PAYMENT header containing proof
  6. Server verifies payment and returns data

All of this happens automatically - your agent just calls tool.run(url).

Links

License

MIT

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_nory-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

langchain_nory-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_nory-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for langchain_nory-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb63453f8c9dbdaeed74810423ec7c60bbd5f30f9a223b381620f578ea2faaa3
MD5 4c013a3d8137c27c1d5e38360aa9eade
BLAKE2b-256 24f56573d7829d4b880d7b1bfe8a4fe5f103ad3d41c86b8bb908f6a7937d6c91

See more details on using hashes here.

File details

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

File metadata

  • Download URL: langchain_nory-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for langchain_nory-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63d1267d35d33bcde312dfbf495eacf801f7f16f3353bb687d140d13f0e5baa8
MD5 f43b47e5ae0aac8a93c6cad73c71078b
BLAKE2b-256 a05e74ac44b5fdfc1bf37eb6f5b03ec8f9285777e11edf3b269dd5bc928694a2

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