LangChain
Use 1ly directly inside LangChain agents to buy and sell APIs with USDC on Base or Solana.
This integration is production ready and published on PyPI as langchain-onely.
Install
pip install langchain-onelyRequirements: Python 3.10+
Wallet Setup
You need a wallet only for paid calls.
- Base wallet: EVM private key (hex string)
- Solana wallet: Base58 private key string
Endpoint format: always username/slug (example: 1ly/paid-api-vwo6oh).
Quick Start (Buyer)
LangChain tools return JSON strings. Parse them with json.loads.
import json
import os
from langchain_onely import OneLyToolkit
toolkit = OneLyToolkit(
base_private_key=os.getenv("BASE_PRIVATE_KEY"), # or solana_private_key
)
tools = toolkit.get_tools()
search = next(t for t in tools if t.name == "onely_search")
details = next(t for t in tools if t.name == "onely_get_details")
call = next(t for t in tools if t.name == "onely_call")
results = json.loads(search.invoke({"query": "emoji api"}))
info = json.loads(details.invoke({"endpoint": "1ly/paid-api-vwo6oh"}))
# Pay and call (x402 handled automatically)
response = json.loads(call.invoke({
"endpoint": "1ly/paid-api-vwo6oh",
"method": "GET",
"preferredNetwork": "base",
"preferredAsset": "USDC",
"allowFallback": False
}))Quick Start (Seller)
import json
import os
from langchain_onely import OneLyToolkit
# First: create your store and get an API key
toolkit = OneLyToolkit(base_private_key=os.getenv("BASE_PRIVATE_KEY"))
tools = toolkit.get_tools()
create_store = next(t for t in tools if t.name == "onely_create_store")
store = json.loads(create_store.invoke({
"username": "my-store",
"displayName": "My API Store"
}))
# Then: re-initialize with the API key for seller tools
toolkit = OneLyToolkit(
base_private_key=os.getenv("BASE_PRIVATE_KEY"),
api_key=store["data"]["apiKey"]
)
tools = toolkit.get_tools()
create_link = next(t for t in tools if t.name == "onely_create_link")
link = json.loads(create_link.invoke({
"title": "My Paid API",
"description": "Fast JSON data",
"url": "https://api.example.com/endpoint",
"price": 0.01
}))Payment Selection
onely_call supports multiple payment options in the 402 response. You can control selection:
preferredNetwork:"base"or"solana"preferredAsset:"USDC"or"1LY"(1LY is Solana only)allowFallback: IfTrue, tries other compatible options if the preferred choice fails
Solana + 1LY Example
import json
import os
from langchain_onely import OneLyToolkit
toolkit = OneLyToolkit(
solana_private_key=os.getenv("SOLANA_PRIVATE_KEY"),
)
tools = toolkit.get_tools()
call = next(t for t in tools if t.name == "onely_call")
response = json.loads(call.invoke({
"endpoint": "1ly/paid-api-vwo6oh",
"method": "GET",
"preferredNetwork": "solana",
"preferredAsset": "1LY",
"allowFallback": False
}))Optional Configuration
You can pass RPC URLs directly:
toolkit = OneLyToolkit(
base_private_key=os.getenv("BASE_PRIVATE_KEY"),
solana_private_key=os.getenv("SOLANA_PRIVATE_KEY"),
base_rpc_url="https://base.publicnode.com",
solana_rpc_url="https://api.mainnet-beta.solana.com",
)Tools
Buyer Tools
| Tool | Required Inputs | Wallet Required | Notes |
|---|---|---|---|
onely_search | query | No | Search marketplace |
onely_get_details | endpoint | No | Get listing details |
onely_call | endpoint | Yes (paid APIs) | Supports preferredNetwork, preferredAsset, allowFallback |
onely_review | purchaseId, reviewToken | Yes | Must use the same wallet that paid |
Seller Tools
| Tool | Required Inputs | API Key Required | Notes |
|---|---|---|---|
onely_create_store | username, displayName | No | Returns apiKey for seller tools |
onely_create_link | title, description, url, price | Yes | List paid API |
onely_list_links | none | Yes | List your links |
onely_get_stats | none | Yes | Sales stats |
onely_withdraw | amount | Yes | Solana only |
Troubleshooting
- Wallet not configured: Pass
base_private_keyorsolana_private_keytoOneLyToolkit - Payment failed: Ensure the wallet has enough USDC on the selected network
- Review failed: Use the
purchaseIdandreviewTokenreturned byonely_call