AI Framework Integration
Give AI agents the power to make payments, swap tokens, and manage wallets using LangChain or the Vercel AI SDK.
🦜
@paydirect/langchain
LangChain tools for agents built with LangChain, LangGraph, or CrewAI.
npm install @paydirect/langchain▲
@paydirect/ai-sdk
Vercel AI SDK tools for Next.js apps and serverless agents.
npm install @paydirect/ai-sdkAvailable Tools
Both packages expose the same set of tools:
| Tool | Description |
|---|---|
getBalance | Get wallet balances (ETH, USDC, ADAO) |
sendPayout | Transfer tokens to any address |
createPayment | Create a payment invoice |
getPayment | Check payment status |
listPayments | List recent payments |
getSwapQuote | Get a DEX swap price quote |
executeSwap | Swap tokens on Uniswap V3 |
withdraw | Withdraw to settlement wallet |
LangChain
Works with any LangChain-compatible agent, including LangGraph and CrewAI.
Installation
npm install @paydirect/langchain @langchain/core @langchain/openai
Quick Start
import { createPayDirectTools } from "@paydirect/langchain";
import { ChatOpenAI } from "@langchain/openai";
import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
// Create PayDirect tools
const tools = createPayDirectTools({
apiKey: process.env.PAYDIRECT_API_KEY!,
baseUrl: "https://www.paydirect.com/api/v1",
});
// Create agent
const llm = new ChatOpenAI({ model: "gpt-4o" });
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a financial agent managing crypto payments."],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);
const agent = createToolCallingAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });
// Run
const result = await executor.invoke({
input: "Check my balance, then swap 10 USDC for ETH",
});
console.log(result.output);Select Specific Tools
const tools = createPayDirectTools({
apiKey: "pd_live_...",
include: ["balance", "swap_quote", "swap"],
});Vercel AI SDK
Native integration with the Vercel AI SDK for Next.js apps, serverless functions, and edge runtimes.
Installation
npm install @paydirect/ai-sdk ai @ai-sdk/openai zod
Quick Start — generateText
import { createPayDirectTools } from "@paydirect/ai-sdk";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
const paydirectTools = createPayDirectTools({
apiKey: process.env.PAYDIRECT_API_KEY!,
baseUrl: "https://www.paydirect.com/api/v1",
});
const { text } = await generateText({
model: openai("gpt-4o"),
tools: paydirectTools,
maxSteps: 5,
prompt: "What's my wallet balance?",
});
console.log(text);Quick Start — streamText (Chat UI)
// app/api/chat/route.ts
import { createPayDirectTools } from "@paydirect/ai-sdk";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
const paydirectTools = createPayDirectTools({
apiKey: process.env.PAYDIRECT_API_KEY!,
});
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: openai("gpt-4o"),
tools: paydirectTools,
maxSteps: 10,
system: "You are a financial assistant. Use PayDirect tools to help the user.",
messages,
});
return result.toDataStreamResponse();
}Select Specific Tools
const tools = createPayDirectTools({
apiKey: "pd_live_...",
include: ["getBalance", "getSwapQuote", "executeSwap"],
});Use Cases
Autonomous Treasury Agent
An AI agent that monitors balances and automatically rebalances between USDC and ETH to maintain target allocations.
const { text } = await generateText({
model: openai("gpt-4o"),
tools: paydirectTools,
maxSteps: 10,
prompt: `
Check the wallet balance. If USDC balance > 500,
swap 50% of USDC for ETH. Report what you did.
`,
});Payment Processing Agent
An AI agent that handles incoming orders and makes payments.
const { text } = await generateText({
model: openai("gpt-4o"),
tools: paydirectTools,
maxSteps: 10,
prompt: `
The user purchased a subscription for $5/month.
Send 5 USDC to 0x1234...5678 as the payment.
Then verify the transaction completed.
`,
});CoWork-style Agent Payments
An AI orchestrator that pays AI agents for completed work.
const { text } = await generateText({
model: openai("gpt-4o"),
tools: paydirectTools,
maxSteps: 10,
prompt: `
Agent-007 completed a content writing task.
Payment: 200 ADAO to 0xAgentWallet...
Split: 190 ADAO to agent, 10 ADAO to platform fee wallet.
Execute both payouts.
`,
});Security Considerations
- API keys in environment variables — Never hardcode keys in agent prompts or client-side code.
- Server-side only — Both packages are designed for server-side execution. Never expose in the browser.
- Rate limiting — PayDirect enforces rate limits per API key. Agents making rapid-fire calls should implement backoff.
- Human-in-the-loop — For high-value operations, consider requiring human approval before the agent executes (LangGraph supports this natively).
- Tool subsetting — Use the
includeoption to limit which tools an agent has access to. A read-only agent only needsbalanceandlist_payments.
