Skip to main content

langchain-agent-margin-router

LangChain integration for the Agent Margin Router.

Give your LangChain agents instant access to 39 paid API endpoints — real-time market data, on-chain reads, best-price gas routing, news, web search, and developer tools — through one pay-per-call backend. Billing is handled with USDC on Base via x402 or an API key, with 3 free calls per wallet so you can try every tool with no signup.

pip install langchain-agent-margin-router

This package is a thin wrapper around the official agent-margin-router SDK: it turns every SDK endpoint into a ready-to-use LangChain StructuredTool, with the argument schema and description inferred automatically from the SDK's typed methods — so the tools always stay in sync with the API.

Quickstart

from langchain_agent_margin_router import get_tools

# 3 free calls per wallet, no signup
tools = get_tools(wallet="0xYourWallet000000000000000000000000000000")

print(len(tools))            # 39
print([t.name for t in tools][:5])
# ['extract_clean', 'market_spread', 'gas_fees', 'best_price', 'token_price']

Pass tools straight into any LangChain agent:

from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent

llm = init_chat_model("openai:gpt-4o-mini")
agent = create_react_agent(llm, tools)

result = agent.invoke({
    "messages": [("user", "What's the median ETH price and the cheapest gas on Base right now?")]
})
print(result["messages"][-1].content)

Or bind them to a model directly:

llm_with_tools = llm.bind_tools(tools)

Selecting a subset

Most agents only need a handful of endpoints. Keep the tool list tight:

tools = get_tools(
    wallet="0x...",
    only=["token_price", "best_price", "news_search", "web_search"],
)

Or exclude a few:

tools = get_tools(wallet="0x...", exclude=["pdf_text", "youtube_transcript"])

Add a prefix to avoid name collisions with your other tools:

tools = get_tools(wallet="0x...", name_prefix="amr_")
# tool names become amr_token_price, amr_best_price, ...

Authentication

Pick one:

Mode How Billing
Wallet (free tier) get_tools(wallet="0x...") 3 free calls per wallet, then HTTP 402
API key get_tools(api_key="amr_live_...") usage + billing tied to the key's wallet
Anonymous get_tools() stricter per-IP limit

Payment behaviour. When the free tier is exhausted and no payment is attached, the API returns HTTP 402. The tool does not perform an automatic on-chain payment; instead it returns a structured error payload including the accepts block (asset, network, price, payTo, facilitator) so your application can settle the x402 payment out of band or top up an API key.

Toolkit class

from langchain_agent_margin_router import AgentMarginRouterToolkit

toolkit = AgentMarginRouterToolkit(wallet="0x...")
tools = toolkit.get_tools()

Available endpoints

All 39 endpoints of the SDK are exposed, including:

  • Market & crypto: token_price, market_spread, crypto_ohlcv, dex_price, fear_greed
  • On-chain: best_price, gas_fees, wallet_balance, erc20_balance, tx_status, ens_resolve, contract_info, agent_wallet_snapshot
  • DeFi: defi_yields, defi_tvl
  • News & search: news_search, web_search, hn_search, reddit_search, rss_feed, wikipedia_summary, arxiv_search
  • Web & content: extract_clean, html_to_markdown, web_crawl, url_status, pdf_text, youtube_transcript, seo_check
  • Developer & data: github_repo_summary, npm_package, pypi_package, dns_lookup, dns_whois, domain_rdap, email_validate, geo_ip, geocode, currency_convert

See the full reference at https://agentmarginrouter.com/docs.

License

MIT © NovaNest

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_agent_margin_router-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

langchain_agent_margin_router-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for langchain_agent_margin_router-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4157274943e4a848119b961f6f619a9aa0aa330d10b573a249a04260fa4b0a9e
MD5 c54d69bd0b32b9f5060d3d5cdb42a64d
BLAKE2b-256 1ae5af5e40eb1c4b0550416cef3daa144973c70ad183df85eb36c76ff5f6ea3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_agent_margin_router-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c939bbb5b9312363e4d107202b9c598a444f50e83ee2fa02f705fb8f6d7e4f1f
MD5 00184de1d1b4a243d33ce83f6d43e50f
BLAKE2b-256 8d5f15024450a72da8b527b3710618b0454ff7dc362974bfde8665a7067d2044

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page