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

Metadata

Release files for langchain-agent-margin-router 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-agent-margin-router 0.1.0
File Size Uploaded Provenance Actions
langchain_agent_margin_router-0.1.0.tar.gz 5.7 kB Without provenance Details for langchain_agent_margin_router-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-agent-margin-router 0.1.0
File Interpreter ABI Platform Actions
langchain_agent_margin_router-0.1.0-py3-none-any.whl Python 3 none any Details for langchain_agent_margin_router-0.1.0-py3-none-any.whl

Total release size: 12.8 kB

Release files / langchain_agent_margin_router-0.1.0.tar.gz

Download URL langchain_agent_margin_router-0.1.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4157274943e4a848119b961f6f619a9aa0aa330d10b573a249a04260fa4b0a9e
BLAKE2b-256 checksum
How to use checksums
1ae5af5e40eb1c4b0550416cef3daa144973c70ad183df85eb36c76ff5f6ea3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Release files / langchain_agent_margin_router-0.1.0-py3-none-any.whl

Download URL langchain_agent_margin_router-0.1.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c939bbb5b9312363e4d107202b9c598a444f50e83ee2fa02f705fb8f6d7e4f1f
BLAKE2b-256 checksum
How to use checksums
8d5f15024450a72da8b527b3710618b0454ff7dc362974bfde8665a7067d2044
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Security for langchain-agent-margin-router 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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