File size: 2,183 Bytes
bde2f3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# x402 AI Framework Integrations

Pay-per-call AI tools for every major framework.
No crypto knowledge required. One `pip install`, zero config.

## Installation

```bash
pip install x402-frameworks
```

## Usage

### LangChain

```python
from x402_frameworks import x402LangChain

x402 = x402LangChain(api_key="your-key", auto_pay=True)

@x402.wrap_tool("token_scan")
@tool
def scan_token(address: str) -> dict:
    """Scan a token for rug pull indicators."""
    return client.scan(address)

from langchain.agents import create_react_agent
agent = create_react_agent(llm, [scan_token], prompt)
# Payment handled automatically on every tool call
```

### CrewAI

```python
from x402_frameworks import x402CrewAI

x402 = x402CrewAI(api_key="your-key", max_budget_usd=50)

researcher = Agent(
    role="Token Researcher",
    tools=[x402.wrap("token_scan", scan_func)],
)
# Shared credit pool across all agents in the crew
```

### AutoGen

```python
from x402_frameworks import x402AutoGen

x402 = x402AutoGen(api_key="your-key")

analyst = AssistantAgent(
    name="TokenAnalyst",
    functions=[x402.as_function("token_scan")],
)
# AutoGen-compatible function specs with transparent payment
```

## How It Works

1. Developer wraps a tool function with `@x402.wrap_tool("tool_name")`
2. When the AI agent calls the tool, x402 checks:
   - Free trial available? → use it
   - Prepaid credits? → deduct
   - Auto-pay enabled? → pay from wallet
   - None? → raise `PaymentRequiredError` with invoice details
3. Tool executes, result returned to agent

## Supported Frameworks

| Framework | Adapter | Status |
|-----------|---------|--------|
| LangChain | `x402LangChain` | ✅ |
| CrewAI | `x402CrewAI` | ✅ |
| AutoGen | `x402AutoGen` | ✅ |
| Haystack | Coming soon | ⏳ |
| Semantic Kernel | Coming soon | ⏳ |

## Configuration

| Env Var | Default | Description |
|---------|---------|-------------|
| `X402_API_KEY` | `""` | API key for authenticated access |
| `X402_BASE_URL` | `https://mcp.rugmunch.io/mcp/x402` | x402 MCP endpoint |
| `X402_AUTO_PAY` | `false` | Auto-pay invoices from wallet |
| `X402_MAX_BUDGET` | `0` | Monthly budget cap (0 = unlimited) |