🦜 LangChain
Adding Pay-Per-Call AI Services to Your LangChain Agent in 5 Minutes
June 2026 · 4 min read · run.pay engineering
LangChain agents are great at reasoning and chaining LLM calls — but they often need specialized capabilities: hallucination detection, PII scanning, bias checking, GDPR compliance. Building these from scratch takes weeks. Integrating third-party APIs means account sprawl. Here's how to do it in 5 minutes with run.pay.
Prerequisites
You need a run.pay agent wallet (free, 3 trial calls) and Python with LangChain installed.
pip install langchain runpay
Step 1: Create your agent wallet
Sign up at getrunpay.com/signup — takes 30 seconds. You'll get an agent ID like agt_xxxxxxxxxxxxx. This is your payment identity for all 205 services.
Step 2: Add run.pay tools to your agent
from langchain.tools import tool
from runpay import RunPay
client = RunPay(agent_id="agt_your_agent_id")
@tool
def check_hallucinations(text: str) -> dict:
"""
Check if an LLM response contains hallucinations or factual errors.
Returns hallucination_score (0-100), risk_level, and flagged_claims.
Use before sending any LLM response to users.
"""
return client.call("hallucination-detector", {"response": text})
# $0.01 per call, billed to your Stripe wallet
@tool
def scan_pii(text: str) -> dict:
"""
Scan text for personally identifiable information (PII).
Returns pii_found, entities (with type and value), and risk level.
Use before storing or logging any user input.
"""
return client.call("pii-scanner", {"text": text})
@tool
def check_gdpr_compliance(text: str) -> dict:
"""
Check if text or data processing complies with GDPR regulations.
Returns gdpr_compliant, violations, and recommendations.
"""
return client.call("gdpr-checker", {"text": text})
Step 3: Add tools to your agent
from langchain.agents import create_openai_functions_agent, AgentExecutor
from langchain_openai import ChatOpenAI
tools = [check_hallucinations, scan_pii, check_gdpr_compliance]
llm = ChatOpenAI(model="gpt-4o")
agent = create_openai_functions_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
# Your agent now has safety superpowers
result = executor.invoke({
"input": "Summarize this document and check it for PII before returning"
})
Using x402 directly (no SDK)
If you prefer not to use the SDK, every run.pay service is x402-compatible. Your LangChain agent can call services directly via HTTP:
import httpx
def call_runpay(service_id: str, payload: dict) -> dict:
r = httpx.post(
f"https://runpay-backend-visibility-production.up.railway.app/x402/{service_id}",
headers={"X-Payment": "agt_your_agent_id"},
json=payload
)
if r.status_code == 402:
raise ValueError("Insufficient wallet balance — fund at getrunpay.com/agent-wallet")
return r.json()
The x402 header X-Payment: agt_xxx is your universal payment credential. It works across all 205 services on run.pay with no per-service setup.
What you just built
Your LangChain agent can now autonomously check every LLM output for hallucinations before sending it to users, scan every piece of user input for PII before storing it, verify GDPR compliance on any text processing, and pay for all of this per-call with no monthly commitment. Total setup time: under 5 minutes. Total cost: $0.01–$0.03 per response checked.
Start building safer LangChain agents
3 free calls · No credit card · x402 compatible
Create agent wallet →