Developers
LangChain

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-onely

Requirements: 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: If True, 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

ToolRequired InputsWallet RequiredNotes
onely_searchqueryNoSearch marketplace
onely_get_detailsendpointNoGet listing details
onely_callendpointYes (paid APIs)Supports preferredNetwork, preferredAsset, allowFallback
onely_reviewpurchaseId, reviewTokenYesMust use the same wallet that paid

Seller Tools

ToolRequired InputsAPI Key RequiredNotes
onely_create_storeusername, displayNameNoReturns apiKey for seller tools
onely_create_linktitle, description, url, priceYesList paid API
onely_list_linksnoneYesList your links
onely_get_statsnoneYesSales stats
onely_withdrawamountYesSolana only

Troubleshooting

  • Wallet not configured: Pass base_private_key or solana_private_key to OneLyToolkit
  • Payment failed: Ensure the wallet has enough USDC on the selected network
  • Review failed: Use the purchaseId and reviewToken returned by onely_call