langchain-onely
LangChain integration for the 1ly marketplace. This package provides production-ready tools that allow AI agents to discover, purchase, and monetize APIs using the x402 micropayment protocol on Base and Solana.
Installation
pip install langchain-onely
Requirements:
- Python 3.10+
- A LangChain LLM provider (e.g.,
langchain-openai,langchain-anthropic)
Install with examples:
# Includes langchain-openai, langchain-anthropic, python-dotenv
pip install "langchain-onely[examples]"
Install for development:
# Includes pytest, black, ruff, python-dotenv
pip install "langchain-onely[dev]"
Quick Start
Buyer (discover and call APIs)
import os
from langchain import hub
from langchain_onely import OneLyToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
# Initialize toolkit with a wallet for payments
# Provide Base OR Solana (or both)
toolkit = OneLyToolkit(
base_private_key=os.getenv("BASE_PRIVATE_KEY"),
solana_private_key=os.getenv("SOLANA_PRIVATE_KEY")
)
tools = toolkit.get_tools()
llm = ChatOpenAI(model="gpt-4")
prompt = hub.pull("hwchase17/react")
agent = create_react_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
result = executor.invoke({
"input": "Find a weather API under $0.10 and get weather for San Francisco"
})
Note: The example above uses langchain-openai. Install the provider package you prefer for your LLM.
Examples
See examples/ for complete, runnable scripts:
examples/buyer_agent.py- Discover and call APIsexamples/seller_agent.py- Create a store and list APIs
Seller (create a store and list APIs)
import os
from langchain_onely import OneLyToolkit
# Step 1: Create a store (one-time)
create_store_toolkit = OneLyToolkit(
base_private_key=os.getenv("BASE_PRIVATE_KEY")
)
create_store_tool = [t for t in create_store_toolkit.get_tools() if t.name == "onely_create_store"][0]
store_result = create_store_tool.invoke({
"username": "mystore",
"displayName": "My API Store"
})
# Save the returned API key as ONELY_API_KEY
# Step 2: List an API
seller_toolkit = OneLyToolkit(
base_private_key=os.getenv("BASE_PRIVATE_KEY"),
solana_private_key=os.getenv("SOLANA_PRIVATE_KEY"),
api_key=os.getenv("ONELY_API_KEY")
)
create_link_tool = [t for t in seller_toolkit.get_tools() if t.name == "onely_create_link"][0]
link_result = create_link_tool.invoke({
"title": "Weather API",
"url": "https://api.example.com/weather",
"price": "0.05",
"description": "Real-time weather data for any city"
})
Configuration
Create a .env file (or set environment variables directly):
# Base wallet (EVM) for payments and store creation
BASE_PRIVATE_KEY=0x1234...
# Solana wallet for withdrawals
SOLANA_PRIVATE_KEY=5J3mN...
# Optional: custom RPC endpoints (recommended for production)
BASE_RPC_URL=https://mainnet.base.org
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
# Seller API key (after onely_create_store)
ONELY_API_KEY=1ly_live_...
Tools
All tools return a JSON string with a message field and, when applicable, a details or data payload. Errors include error: true and a structured details object with a code.
Buyer tools
onely_search
- Purpose: Search marketplace listings.
- Inputs:
query(string),type("api" or "standard"),minPrice(float),maxPrice(float),limit(1-50). - Output:
results,total.
onely_get_details
- Purpose: Fetch full listing details and x402 payment requirements.
- Inputs:
endpoint(string, e.g.,joe/weather). - Output:
details,fullUrl.
onely_call
- Purpose: Pay for and call a listing using x402.
- Inputs:
endpoint,method,body,headers,preferredNetwork,preferredAsset,allowFallback. - Requires: Base or Solana wallet.
- Output:
dataplus purchase metadata (purchaseId,reviewToken) for reviews. - Notes:
preferredNetwork=baseorsolana.preferredAsset=USDCor1LY(Solana only).
onely_review
- Purpose: Leave a review for a paid call.
- Inputs:
purchaseId,reviewToken,positive,comment. - Requires: Base or Solana wallet. The wallet used must match the wallet that paid for the purchase.
Seller tools
onely_create_store
- Purpose: Create a marketplace store and get an API key.
- Inputs:
username,displayName,avatarUrl. - Requires: Base wallet.
- Output:
apiKeyand store details.
onely_create_link
- Purpose: List a paid or free API.
- Inputs:
title,url,description,slug,price,currency,isPublic,isStealth,webhookUrl. - Requires:
ONELY_API_KEY.
onely_list_links
- Purpose: List all your API listings.
- Inputs: none.
- Requires:
ONELY_API_KEY.
onely_get_stats
- Purpose: Revenue and sales stats.
- Inputs:
period("7d" | "30d" | "90d" | "all"),linkId. - Requires:
ONELY_API_KEY.
onely_withdraw
- Purpose: Withdraw earnings to Solana.
- Inputs:
amount,walletAddress. - Requires:
ONELY_API_KEY.
Security Notes
- Never commit private keys or API keys.
- Keep wallet balances minimal for testing.
- Use custom RPC endpoints for reliability and rate-limit protection.
- This toolkit is non-custodial; keys are used only for signing.
Payment Preferences
You can explicitly choose the payment network and asset per call:
call_tool.invoke({
"endpoint": "agent/emoji-hub",
"method": "GET",
"preferredNetwork": "base", # or "solana"
"preferredAsset": "USDC", # or "1LY" (Solana only)
"allowFallback": True # try another compatible method on failure
})
Development
pip install -e ".[dev]"
ruff check langchain_onely/
black --check langchain_onely/
Testing
pytest tests/
License
MIT License. See LICENSE.
Metadata
Release files for langchain-onely 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_onely-0.1.1.tar.gz | 27.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_onely-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.2 kB
Release files / langchain_onely-0.1.1.tar.gz
| Download URL | langchain_onely-0.1.1.tar.gz |
|---|---|
| Size | 27.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41ed90f24ad9ab7bda856482d4a7c40b9eab74ec4226d4fe2dfe222fd50b712e
|
|
BLAKE2b-256 checksum How to use checksums |
eee34b6ff112e13b5e6458bc7856eedd1a052c9ebd04c08f088752ee12d554dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Release files / langchain_onely-0.1.1-py3-none-any.whl
| Download URL | langchain_onely-0.1.1-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
faee7f750e31a7bea7969a3c62027ae4ead95b5b6567d99430cdc5d58c64a6f4
|
|
BLAKE2b-256 checksum How to use checksums |
8306b632c4a22096f1dad05641cbe65da1229ec3b773f3c010716f713bddf592
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|