> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xenarch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> LangChain payment tools — let LangChain agents pay for x402-gated content with USDC micropayments. MCP-compatible. Drop-in tool integration.

## Installation

```bash theme={null}
pip install xenarch[agent,langchain]
```

Requires `langchain>=0.3.0`.

## Tools

The SDK provides three LangChain tools:

```python theme={null}
from xenarch.tools.langchain import CheckGateTool, PayTool, GetHistoryTool

tools = [CheckGateTool(), PayTool(), GetHistoryTool()]
```

| Tool             | Description                                  |
| ---------------- | -------------------------------------------- |
| `CheckGateTool`  | Check if a URL has an x402 payment gate      |
| `PayTool`        | Execute USDC payment and return access token |
| `GetHistoryTool` | View past payments for this wallet           |

## Usage with LangGraph

```python theme={null}
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from xenarch.tools.langchain import CheckGateTool, PayTool, GetHistoryTool

load_dotenv()

llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
tools = [CheckGateTool(), PayTool(), GetHistoryTool()]

agent = create_react_agent(
    llm,
    tools,
    prompt=(
        "You are a helpful assistant with Xenarch payment tools. "
        "You can check URLs for payment gates, pay for gated content, "
        "and review payment history."
    ),
)

result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": "Check if example.com has a paywall and pay if needed."
    }]
})
```

## Using with other LLMs

```python theme={null}
# Anthropic
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(model="claude-sonnet-4-20250514")

# Local model via Ollama
from langchain_community.llms import Ollama
llm = Ollama(model="llama3")
```

## Wallet configuration

The tools use the same wallet configuration as the core SDK:

1. `XENARCH_PRIVATE_KEY` environment variable
2. `~/.xenarch/config.json`
3. `~/.xenarch/wallet.json`
4. Auto-generate on first use

See [Agent Quickstart](/quickstart-agent) for wallet setup.

## Full example

See the [LangChain agent example](/examples/langchain-agent) for a complete working script.
