Metadata-Version: 2.5
Name: langchain-agent-margin-router
Version: 0.1.0
Summary: LangChain integration for the Agent Margin Router: exposes all 39 paid API endpoints (market data, on-chain best-price, news, web, developer tools) as ready-to-use LangChain tools for your agents. Pay per call with USDC on Base via x402, or use an API key.
Project-URL: Homepage, https://agentmarginrouter.com
Project-URL: Documentation, https://agentmarginrouter.com/docs
Project-URL: Repository, https://github.com/AgentMarginRouter/langchain-agent-margin-router
Author: NovaNest
License: MIT License
        
        Copyright (c) 2026 NovaNest
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agent-margin-router,ai-agents,crypto,defi,langchain,langchain-tools,llm,onchain,tools,x402
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: agent-margin-router>=0.1.0
Requires-Dist: langchain-core<0.4,>=0.3
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: twine>=4.0; extra == 'dev'
Description-Content-Type: text/markdown

# langchain-agent-margin-router

**LangChain integration for the [Agent Margin Router](https://agentmarginrouter.com).**

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.

```bash
pip install langchain-agent-margin-router
```

This package is a thin wrapper around the official
[`agent-margin-router`](https://pypi.org/project/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

```python
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:

```python
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:

```python
llm_with_tools = llm.bind_tools(tools)
```

## Selecting a subset

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

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

Or exclude a few:

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

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

```python
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

```python
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
